KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > OmBuilderXStreamImpl


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;
24
25 import java.io.InputStream JavaDoc;
26 import java.io.InputStreamReader JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
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 /**
44  * OM builder to serialize/deserialize a PortletApplicationEntityList
45  * (registry).
46  *
47  * @author jand
48  * @author joran
49  *
50  */

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 JavaDoc.class);
61         xstream.alias("application", PortletApplicationEntityImpl.class);
62         xstream.alias("entities", ArrayList JavaDoc.class);
63         xstream.alias("entity", PortletEntityImpl.class);
64         xstream.alias("preferences", ArrayList JavaDoc.class);
65         xstream.alias("preference", PreferenceImpl.class);
66         //xstream.alias("name", java.lang.String.class);
67
xstream.alias("value", java.lang.String JavaDoc.class);
68         //xstream.alias("value", ArrayList.class);
69
//xstream.addImplicitCollection(PreferenceSet.class, "preference",
70
// PreferenceImpl.class);
71
// xstream.addImplicitCollection(
72
// ArrayList.class,
73
// "applications",
74
// PortletApplicationEntityImpl.class);
75
xstream.addImplicitCollection(PreferenceImpl.class, "values", String JavaDoc.class);
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#getPortletApplicationEntityList()
82      */

83     public PortletApplicationEntityListImpl getPortletApplicationEntityList(InputStream JavaDoc is)
84     {
85         ArrayList JavaDoc apps = new ArrayList JavaDoc();
86         try
87         {
88             apps = (ArrayList JavaDoc) xstream.fromXML(new InputStreamReader JavaDoc(is));
89         }
90         catch(Exception JavaDoc e)
91         {
92             e.printStackTrace();
93         }
94
95         PortletApplicationEntityListImpl applications = new PortletApplicationEntityListImpl(apps);
96
97         // This is here to set back-references
98
for (Iterator JavaDoc iter = applications.iterator(); iter.hasNext();) {
99             PortletApplicationEntity app = (PortletApplicationEntity) iter.next();
100
101             for (Iterator JavaDoc 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     /*
114      * (non-Javadoc)
115      *
116      * @see org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistryService#toXML()
117      */

118     public String JavaDoc toXML(PortletApplicationEntityList pael) {
119         List JavaDoc apps = new ArrayList JavaDoc();
120         for (Iterator JavaDoc it = pael.iterator(); it.hasNext();) {
121             apps.add(it.next());
122         }
123         return xstream.toXML(apps);
124     }
125 }
Popular Tags