1 23 package org.infoglue.deliver.portal.services; 24 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 28 import javax.servlet.ServletContext ; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.apache.pluto.om.common.ObjectID; 33 import org.apache.pluto.om.entity.PortletApplicationEntity; 34 import org.apache.pluto.om.entity.PortletApplicationEntityList; 35 import org.apache.pluto.om.entity.PortletEntity; 36 import org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService; 37 import org.apache.pluto.portalImpl.util.Properties; 38 import org.infoglue.deliver.portal.OmBuilder; 39 import org.infoglue.deliver.portal.OmBuilderXStreamImpl; 40 import org.infoglue.deliver.portal.om.PortletApplicationEntityListImpl; 41 42 47 public class PortletEntityRegistryServiceFileImplIG extends PortletEntityRegistryService { 48 private static final Log LOG = LogFactory.getLog(PortletEntityRegistryServiceFileImplIG.class); 49 50 private ServletContext aContext; 51 private String filename = "WEB-INF/data/portletentityregistryIG.xml"; 52 private OmBuilder builder = new OmBuilderXStreamImpl(); 53 private PortletApplicationEntityListImpl applications; 54 55 58 protected void init(ServletContext aContext, Properties aProperties) throws Exception { 59 super.init(aContext, aProperties); 61 this.aContext = aContext; 62 load(); 63 } 64 65 68 public PortletApplicationEntityList getPortletApplicationEntityList() { 69 return applications; 70 } 71 72 75 public PortletEntity getPortletEntity(ObjectID id) { 76 String oid = id.toString(); 77 int dot = oid.lastIndexOf("."); 78 if (dot < 0) { 79 LOG.warn("ID does not contain '.' to separate application- and portlet-id: " + id); 80 return null; 81 } 82 83 ObjectID appID = 84 org.apache.pluto.portalImpl.util.ObjectID.createFromString(oid.substring(0, dot)); 85 86 PortletApplicationEntity appEntity = applications.get(appID); 87 if (appEntity == null) { 88 LOG.warn("Application not found: " + appID); 89 return null; 90 } 91 PortletEntity portletEntity = appEntity.getPortletEntityList().get(id); 92 if (portletEntity == null) { 93 LOG.warn("Portlet not found: " + id); 94 } 95 96 return portletEntity; 97 } 98 99 102 public void store() throws IOException { 103 String xml = builder.toXML(applications); 104 LOG.info(xml); 105 } 106 107 110 public void load() throws IOException { 111 LOG.info("Start building PortletApplicationList....."); 112 InputStream is = aContext.getResourceAsStream(filename); 113 if (is == null) { 114 throw new IOException ("Unable to find " + filename); 115 } 116 117 applications = builder.getPortletApplicationEntityList(is); 118 is.close(); 119 LOG.info("Applications: " + applications); 120 LOG.info("DONE!"); 121 } 122 123 126 public void refresh(PortletEntity portletEntity) { 127 throw new UnsupportedOperationException (); 129 130 } 131 132 public static void main(String [] args) { 133 try { 134 PortletEntityRegistryServiceFileImplIG reg = 135 new PortletEntityRegistryServiceFileImplIG(); 136 reg.load(); 137 138 reg.store(); 139 } catch (IOException e) { 140 e.printStackTrace(); 142 } 143 } 144 145 } 146 | Popular Tags |