1 23 package org.infoglue.deliver.portal; 24 25 import java.io.InputStream ; 26 import java.io.InputStreamReader ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 import org.apache.pluto.om.entity.PortletApplicationEntity; 34 import org.apache.pluto.om.entity.PortletApplicationEntityList; 35 import org.infoglue.deliver.portal.om.PortletApplicationEntityImpl; 36 import org.infoglue.deliver.portal.om.PortletApplicationEntityListImpl; 37 import org.infoglue.deliver.portal.om.PortletEntityImpl; 38 import org.infoglue.deliver.portal.om.PreferenceImpl; 39 40 import com.thoughtworks.xstream.XStream; 41 import com.thoughtworks.xstream.io.xml.DomDriver; 42 43 51 public class OmBuilderXStreamImpl implements OmBuilder 52 { 53 private static final Log log = LogFactory.getLog(OmBuilderXStreamImpl.class); 54 55 private XStream xstream; 56 57 public OmBuilderXStreamImpl() 58 { 59 xstream = new XStream(new DomDriver()); 60 xstream.alias("applications", ArrayList .class); 61 xstream.alias("application", PortletApplicationEntityImpl.class); 62 xstream.alias("entities", ArrayList .class); 63 xstream.alias("entity", PortletEntityImpl.class); 64 xstream.alias("preferences", ArrayList .class); 65 xstream.alias("preference", PreferenceImpl.class); 66 xstream.alias("value", java.lang.String .class); 68 xstream.addImplicitCollection(PreferenceImpl.class, "values", String .class); 76 } 77 78 83 public PortletApplicationEntityListImpl getPortletApplicationEntityList(InputStream is) 84 { 85 ArrayList apps = new ArrayList (); 86 try 87 { 88 apps = (ArrayList ) xstream.fromXML(new InputStreamReader (is)); 89 } 90 catch(Exception e) 91 { 92 e.printStackTrace(); 93 } 94 95 PortletApplicationEntityListImpl applications = new PortletApplicationEntityListImpl(apps); 96 97 for (Iterator iter = applications.iterator(); iter.hasNext();) { 99 PortletApplicationEntity app = (PortletApplicationEntity) iter.next(); 100 101 for (Iterator ports = app.getPortletEntityList().iterator(); ports.hasNext();) { 102 PortletEntityImpl port = (PortletEntityImpl) ports.next(); 103 if (port.getId().toString().indexOf(".") < 0) { 104 port.setId(app.getId() + "." + port.getId()); 105 } 106 port.setPortletApplicationEntity(app); 107 108 } 109 } 110 return applications; 111 } 112 113 118 public String toXML(PortletApplicationEntityList pael) { 119 List apps = new ArrayList (); 120 for (Iterator it = pael.iterator(); it.hasNext();) { 121 apps.add(it.next()); 122 } 123 return xstream.toXML(apps); 124 } 125 } | Popular Tags |