KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > services > PortletEntityRegistryServiceFileImplIG


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.deliver.portal.services;
24
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27
28 import javax.servlet.ServletContext JavaDoc;
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 /**
43  * @author joran
44  *
45  * @version $Revision: 1.4 $
46  */

47 public class PortletEntityRegistryServiceFileImplIG extends PortletEntityRegistryService {
48     private static final Log LOG = LogFactory.getLog(PortletEntityRegistryServiceFileImplIG.class);
49
50     private ServletContext JavaDoc aContext;
51     private String JavaDoc filename = "WEB-INF/data/portletentityregistryIG.xml";
52     private OmBuilder builder = new OmBuilderXStreamImpl();
53     private PortletApplicationEntityListImpl applications;
54
55     /* (non-Javadoc)
56      * @see org.apache.pluto.portalImpl.services.Service#init(javax.servlet.ServletContext, org.apache.pluto.portalImpl.util.Properties)
57      */

58     protected void init(ServletContext JavaDoc aContext, Properties aProperties) throws Exception JavaDoc {
59         // TODO Auto-generated method stub
60
super.init(aContext, aProperties);
61         this.aContext = aContext;
62         load();
63     }
64
65     /* (non-Javadoc)
66      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#getPortletApplicationEntityList()
67      */

68     public PortletApplicationEntityList getPortletApplicationEntityList() {
69         return applications;
70     }
71
72     /* (non-Javadoc)
73      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#getPortletEntity(org.apache.pluto.om.common.ObjectID)
74      */

75     public PortletEntity getPortletEntity(ObjectID id) {
76         String JavaDoc 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     /* (non-Javadoc)
100      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#store()
101      */

102     public void store() throws IOException JavaDoc {
103         String JavaDoc xml = builder.toXML(applications);
104         LOG.info(xml);
105     }
106
107     /* (non-Javadoc)
108      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#load()
109      */

110     public void load() throws IOException JavaDoc {
111         LOG.info("Start building PortletApplicationList.....");
112         InputStream JavaDoc is = aContext.getResourceAsStream(filename);
113         if (is == null) {
114             throw new IOException JavaDoc("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     /* (non-Javadoc)
124      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#refresh(org.apache.pluto.om.entity.PortletEntity)
125      */

126     public void refresh(PortletEntity portletEntity) {
127         // TODO Auto-generated method stub
128
throw new UnsupportedOperationException JavaDoc();
129
130     }
131
132     public static void main(String JavaDoc[] args) {
133         try {
134             PortletEntityRegistryServiceFileImplIG reg =
135                 new PortletEntityRegistryServiceFileImplIG();
136             reg.load();
137
138             reg.store();
139         } catch (IOException JavaDoc e) {
140             // TODO Auto-generated catch block
141
e.printStackTrace();
142         }
143     }
144
145 }
146
Popular Tags