Source Code Cross Referenced for PortletApplicationUnmarshaller.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » container » binding » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.container.binding 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.container.binding;
007:
008:        import java.io.IOException;
009:        import java.io.InputStream;
010:        import java.util.ArrayList;
011:        import java.util.List;
012:        import java.util.Locale;
013:
014:        import javax.portlet.PortletMode;
015:
016:        import org.apache.pluto.om.common.DescriptionSet;
017:        import org.apache.pluto.om.common.DisplayNameSet;
018:        import org.apache.pluto.om.common.LanguageSet;
019:        import org.apache.pluto.om.common.ParameterSet;
020:        import org.apache.pluto.om.common.PreferenceSet;
021:        import org.apache.pluto.om.portlet.ContentTypeSet;
022:        import org.apache.pluto.om.portlet.PortletApplicationDefinition;
023:        import org.apache.pluto.om.portlet.PortletDefinitionList;
024:        import org.apache.pluto.om.servlet.WebApplicationDefinition;
025:        import org.jasig.portal.container.om.common.DescriptionSetImpl;
026:        import org.jasig.portal.container.om.common.DisplayNameSetImpl;
027:        import org.jasig.portal.container.om.common.LanguageSetImpl;
028:        import org.jasig.portal.container.om.common.ParameterSetImpl;
029:        import org.jasig.portal.container.om.common.PreferenceSetImpl;
030:        import org.jasig.portal.container.om.common.SecurityRoleRefImpl;
031:        import org.jasig.portal.container.om.common.SecurityRoleRefSetImpl;
032:        import org.jasig.portal.container.om.portlet.ContentTypeImpl;
033:        import org.jasig.portal.container.om.portlet.ContentTypeSetImpl;
034:        import org.jasig.portal.container.om.portlet.PortletApplicationDefinitionImpl;
035:        import org.jasig.portal.container.om.portlet.PortletDefinitionImpl;
036:        import org.jasig.portal.container.om.portlet.PortletDefinitionListImpl;
037:        import org.jasig.portal.container.om.portlet.UserAttributeImpl;
038:        import org.jasig.portal.container.om.portlet.UserAttributeListImpl;
039:        import org.jasig.portal.i18n.LocaleManager;
040:        import org.jasig.portal.utils.DocumentFactory;
041:        import org.jasig.portal.utils.XML;
042:        import org.w3c.dom.Document;
043:        import org.w3c.dom.Element;
044:        import org.w3c.dom.NodeList;
045:        import org.xml.sax.SAXException;
046:
047:        /**
048:         * Parses a <code>portlet.xml</code> file and produces data structures.
049:         * @author Ken Weiner, kweiner@unicon.net
050:         * @version $Revision: 35013 $
051:         */
052:        public class PortletApplicationUnmarshaller {
053:
054:            private InputStream inputStream = null;
055:            private String contextName = null;
056:            private Document doc = null; // Might want to consider SAX instead of DOM parsing
057:            private PortletApplicationDefinitionImpl portletApplicationDefinition = null;
058:
059:            public PortletApplicationUnmarshaller() {
060:                portletApplicationDefinition = new PortletApplicationDefinitionImpl();
061:            }
062:
063:            /**
064:             * Initializer that takes an input stream to the <code>portlet.xml</code> file.
065:             * @param inputStream an input stream to the contents of the <code>portlet.xml</code> file
066:             * @throws IOException
067:             * @throws SAXException
068:             */
069:            public void init(InputStream inputStream, String contextName)
070:                    throws IOException, SAXException {
071:                this .inputStream = inputStream;
072:                this .contextName = contextName;
073:                this .doc = DocumentFactory.getDocumentFromStream(inputStream);
074:            }
075:
076:            /**
077:             * Returns a PortletApplicationDefinition object that was populated with data 
078:             * from the <code>portlet.xml</code> file.
079:             * @return the portlet application definition
080:             */
081:            public PortletApplicationDefinition getPortletApplicationDefinition(
082:                    WebApplicationDefinition webApplicationDefinition) {
083:                Element portletAppE = doc.getDocumentElement();
084:                portletApplicationDefinition.setId(contextName);
085:                portletApplicationDefinition.setVersion(portletAppE
086:                        .getAttribute("version"));
087:                portletApplicationDefinition
088:                        .setPortletDefinitionList(getPortletDefinitions(
089:                                portletAppE, webApplicationDefinition));
090:                portletApplicationDefinition
091:                        .setUserAttributes(getUserAttributes(portletAppE));
092:                portletApplicationDefinition
093:                        .setWebApplicationDefinition(webApplicationDefinition);
094:                return portletApplicationDefinition;
095:            }
096:
097:            private PortletDefinitionList getPortletDefinitions(
098:                    Element portletAppE,
099:                    WebApplicationDefinition webApplicationDefinition) {
100:                PortletDefinitionListImpl portletDefinitions = new PortletDefinitionListImpl();
101:
102:                NodeList portletNL = portletAppE
103:                        .getElementsByTagName("portlet");
104:                for (int i = 0; i < portletNL.getLength(); i += 1) {
105:                    Element portletE = (Element) portletNL.item(i);
106:                    String portletName = XML.getChildElementText(portletE,
107:                            "portlet-name");
108:                    String portletDefinitionId = contextName + "."
109:                            + portletName;
110:                    PortletDefinitionImpl portletDefinition = new PortletDefinitionImpl();
111:                    portletDefinition.setId(portletDefinitionId);
112:                    portletDefinition.setClassName(XML.getChildElementText(
113:                            portletE, "portlet-class"));
114:                    portletDefinition.setName(portletName);
115:                    portletDefinition
116:                            .setDisplayNames(getDisplayNames(portletE));
117:                    portletDefinition
118:                            .setDescriptions(getDescriptions(portletE));
119:                    portletDefinition.setLanguages(getLanguages(portletE));
120:                    portletDefinition
121:                            .setInitParameters(getInitParameters(portletE));
122:                    portletDefinition.setPreferences(getPreferences(portletE));
123:                    portletDefinition
124:                            .setContentTypes(getContentTypes(portletE));
125:                    portletDefinition
126:                            .setServletDefinition(webApplicationDefinition
127:                                    .getServletDefinitionList()
128:                                    .get(portletName));
129:                    portletDefinition
130:                            .setPortletApplicationDefinition(portletApplicationDefinition);
131:                    portletDefinition.setExpirationCache(XML
132:                            .getChildElementText(portletE, "expiration-cache"));
133:                    portletDefinition
134:                            .setInitSecurityRoleRefSet(getSecurityRoleRefs(portletE));
135:
136:                    portletDefinitions.add(portletDefinitionId,
137:                            portletDefinition);
138:                }
139:                return portletDefinitions;
140:            }
141:
142:            private DisplayNameSet getDisplayNames(Element portletE) {
143:                DisplayNameSetImpl displayNames = new DisplayNameSetImpl();
144:                NodeList displayNameNL = portletE
145:                        .getElementsByTagName("display-name");
146:                for (int i = 0; i < displayNameNL.getLength(); i += 1) {
147:                    Element displayNameE = (Element) displayNameNL.item(i);
148:                    String displayName = XML.getElementText(displayNameE);
149:                    displayNames.add(displayName, Locale.getDefault());
150:                }
151:                return displayNames;
152:            }
153:
154:            private DescriptionSet getDescriptions(Element portletE) {
155:                DescriptionSetImpl descriptions = new DescriptionSetImpl();
156:                NodeList descriptionNL = portletE
157:                        .getElementsByTagName("description");
158:                for (int i = 0; i < descriptionNL.getLength(); i += 1) {
159:                    Element descriptionE = (Element) descriptionNL.item(i);
160:                    String description = XML.getElementText(descriptionE);
161:                    descriptions.add(description, Locale.getDefault());
162:                }
163:                return descriptions;
164:            }
165:
166:            private LanguageSet getLanguages(Element portletE) {
167:                // Check for a resource bundle element
168:                String resources = null;
169:                NodeList resourceBundleNL = portletE
170:                        .getElementsByTagName("resource-bundle");
171:                if (resourceBundleNL.getLength() > 0) {
172:                    Element resourceBundleE = (Element) resourceBundleNL
173:                            .item(0); // there should only be one
174:                    String resourceBundle = XML.getElementText(resourceBundleE);
175:                    if (resourceBundle.trim().length() > 0) {
176:                        resources = resourceBundle;
177:                    }
178:                }
179:
180:                // The portlet-info element is optional if the resource-bundle element is specified
181:                String title = null;
182:                String shortTitle = null;
183:                String keywords = null;
184:                NodeList portletInfoNL = portletE
185:                        .getElementsByTagName("portlet-info");
186:                if (portletInfoNL.getLength() > 0) {
187:                    Element portletInfoE = (Element) portletInfoNL.item(0); // there should only be one
188:                    title = XML.getChildElementText(portletInfoE, "title");
189:                    shortTitle = XML.getChildElementText(portletInfoE,
190:                            "short-title");
191:                    keywords = XML
192:                            .getChildElementText(portletInfoE, "keywords");
193:                }
194:
195:                LanguageSetImpl languages = new LanguageSetImpl(title,
196:                        shortTitle, keywords, resources);
197:                languages.setClassLoader(Thread.currentThread()
198:                        .getContextClassLoader());
199:                NodeList supportedLocaleNL = portletE
200:                        .getElementsByTagName("supported-locale");
201:                for (int i = 0; i < supportedLocaleNL.getLength(); i += 1) {
202:                    Element supportedLocaleE = (Element) supportedLocaleNL
203:                            .item(i);
204:                    languages.addLocale(LocaleManager.parseLocale(XML
205:                            .getElementText(supportedLocaleE)));
206:                }
207:                return languages;
208:            }
209:
210:            private ParameterSet getInitParameters(Element portletE) {
211:                ParameterSetImpl parameters = new ParameterSetImpl();
212:                NodeList initParamNL = portletE
213:                        .getElementsByTagName("init-param");
214:                for (int i = 0; i < initParamNL.getLength(); i += 1) {
215:                    Element initParamE = (Element) initParamNL.item(i);
216:                    parameters.add(XML.getChildElementText(initParamE, "name"),
217:                            XML.getChildElementText(initParamE, "value"));
218:                }
219:                return parameters;
220:            }
221:
222:            private PreferenceSet getPreferences(Element portletE) {
223:                PreferenceSetImpl preferences = new PreferenceSetImpl();
224:                NodeList portletPreferencesNL = portletE
225:                        .getElementsByTagName("portlet-preferences");
226:                if (portletPreferencesNL.getLength() > 0) {
227:                    Element portletPreferencesE = (Element) portletPreferencesNL
228:                            .item(0); // there should only be one
229:                    NodeList preferenceNL = portletPreferencesE
230:                            .getElementsByTagName("preference");
231:                    for (int i = 0; i < preferenceNL.getLength(); i += 1) {
232:                        Element preferenceE = (Element) preferenceNL.item(i);
233:                        String name = XML.getChildElementText(preferenceE,
234:                                "name");
235:                        List values = new ArrayList(1); // There is usually just one value
236:                        NodeList valueNL = preferenceE
237:                                .getElementsByTagName("value");
238:                        for (int j = 0; j < valueNL.getLength(); j += 1) {
239:                            Element valueE = (Element) valueNL.item(j);
240:                            values.add(XML.getElementText(valueE));
241:                        }
242:                        boolean readOnly = Boolean.valueOf(
243:                                XML.getChildElementText(preferenceE,
244:                                        "read-only")).booleanValue();
245:                        preferences.add(name, values, readOnly);
246:                    }
247:                    preferences.setPreferencesValidator(XML
248:                            .getChildElementText(portletPreferencesE,
249:                                    "preferences-validator"));
250:                }
251:                return preferences;
252:            }
253:
254:            private SecurityRoleRefSetImpl getSecurityRoleRefs(Element portletE) {
255:                SecurityRoleRefSetImpl securityRoleRefs = new SecurityRoleRefSetImpl();
256:                NodeList securityRoleRefsNL = portletE
257:                        .getElementsByTagName("security-role-ref");
258:                for (int i = 0; i < securityRoleRefsNL.getLength(); i += 1) {
259:                    Element securityRoleRefE = (Element) securityRoleRefsNL
260:                            .item(i);
261:                    SecurityRoleRefImpl securityRoleRef = new SecurityRoleRefImpl();
262:                    securityRoleRef.setDescription(XML.getChildElementText(
263:                            securityRoleRefE, "description"));
264:                    securityRoleRef.setRoleName(XML.getChildElementText(
265:                            securityRoleRefE, "role-name"));
266:                    securityRoleRef.setRoleLink(XML.getChildElementText(
267:                            securityRoleRefE, "role-link"));
268:                    securityRoleRefs.add(securityRoleRef);
269:                }
270:                return securityRoleRefs;
271:            }
272:
273:            private ContentTypeSet getContentTypes(Element portletE) {
274:                ContentTypeSetImpl contentTypes = new ContentTypeSetImpl();
275:                NodeList supportsNL = portletE.getElementsByTagName("supports");
276:                for (int i = 0; i < supportsNL.getLength(); i += 1) {
277:                    Element supportsE = (Element) supportsNL.item(i);
278:                    ContentTypeImpl contentType = new ContentTypeImpl();
279:                    contentType.setContentType(XML.getChildElementText(
280:                            supportsE, "mime-type"));
281:                    NodeList portletModeNL = supportsE
282:                            .getElementsByTagName("portlet-mode");
283:                    for (int j = 0; j < portletModeNL.getLength(); j += 1) {
284:                        Element portletModeE = (Element) portletModeNL.item(j);
285:                        contentType.addPortletMode(new PortletMode(XML
286:                                .getElementText(portletModeE)));
287:                    }
288:                    contentTypes.add(contentType);
289:                }
290:                return contentTypes;
291:            }
292:
293:            private UserAttributeListImpl getUserAttributes(Element portletAppE) {
294:                UserAttributeListImpl userAttributes = new UserAttributeListImpl();
295:                NodeList userAttributesNL = portletAppE
296:                        .getElementsByTagName("user-attribute");
297:                for (int i = 0; i < userAttributesNL.getLength(); i += 1) {
298:                    Element userAttributeE = (Element) userAttributesNL.item(i);
299:                    UserAttributeImpl userAttribute = new UserAttributeImpl();
300:                    userAttribute.setDescription(XML.getChildElementText(
301:                            userAttributeE, "description"));
302:                    userAttribute.setName(XML.getChildElementText(
303:                            userAttributeE, "name"));
304:                    userAttributes.add(userAttribute);
305:                }
306:                return userAttributes;
307:            }
308:
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.