Source Code Cross Referenced for DeploymentDescriptorReader.java in  » Portal » Open-Portal » com » sun » portal » portletcontainercommon » descriptor » 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 » Open Portal » com.sun.portal.portletcontainercommon.descriptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002 Sun Microsystems, Inc. All 
003:         * rights reserved. Use of this product is subject 
004:         * to license terms. Federal Acquisitions: 
005:         * Commercial Software -- Government Users 
006:         * Subject to Standard License Terms and 
007:         * Conditions. 
008:         * 
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
010:         * are trademarks or registered trademarks of Sun Microsystems, 
011:         * Inc. in the United States and other countries. 
012:         */
013:        package com.sun.portal.portletcontainercommon.descriptor;
014:
015:        import java.io.InputStream;
016:        import java.io.IOException;
017:        import java.util.logging.Logger;
018:        import java.util.logging.Level;
019:
020:        import org.jdom.input.SAXBuilder;
021:        import org.jdom.Document;
022:        import org.jdom.Element;
023:        import org.jdom.Namespace;
024:        import org.jdom.JDOMException;
025:        import com.sun.portal.log.common.PortalLogger;
026:
027:        /**
028:         * The deployment descriptor reader reads the portlet deployment descriptor
029:         * file and parses the elements of the XML file. 
030:         */
031:        public class DeploymentDescriptorReader {
032:            // Schema location and namespace
033:            public static String PORTLET_SCHEMA_LOCATION = "DDSchemaLocation";
034:            public static String PORTLET_SCHEMA_FILE = "/portlet.xsd";
035:            public static String SUN_PORTLET_SCHEMA_FILE = "/sun-portlet.xsd";
036:
037:            public static String PORTLET_NAMESPACE = "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd";
038:
039:            public static String SUN_PORTAL_NAMESPACE = "http://www.sun.com/software/xml/ns/portal_server";
040:
041:            // SAXBuilder related constants 
042:            public static String BUILDER_SAX_PARSER = "org.apache.xerces.parsers.SAXParser";
043:
044:            public static String BUILDER_SAX_PARSER_SUN_INTERNAL = "com.sun.org.apache.xerces.internal.parsers.SAXParser";
045:
046:            public static String BUILDER_VALIDATION_SCHEMA_FEATURE = "http://apache.org/xml/features/validation/schema";
047:
048:            public static String BUILDER_SCHEMA_LOC_PROPERTY = "http://apache.org/xml/properties/schema/external-schemaLocation";
049:
050:            public static final String VALIDATE_SCHEMA = "validate_schema";
051:
052:            // Create a logger for this class
053:            private static Logger debugLogger = PortalLogger
054:                    .getLogger(DeploymentDescriptorReader.class);
055:
056:            //global variables
057:            private String _portletSchemaLocation;
058:
059:            public DeploymentDescriptorReader(Logger logger,
060:                    String schemaLocation) {
061:                _portletSchemaLocation = schemaLocation;
062:                debugLogger.log(Level.INFO, "PSPL_PCCCSPPCCD0001",
063:                        schemaLocation);
064:            }
065:
066:            /**
067:             * Reads the deployment descriptor's xml file, and returns the root
068:             * element.
069:             * <P>
070:             * In the case of unable to read the deployment descriptor, an error
071:             * is logged.
072:             * <P>
073:             * @param portletStream The input stream of the deployment 
074:             * descriptor's xml file
075:             * @return The root Element of the document, null if the resource does not
076:             * exists.
077:             */
078:            private Element readDeploymentDescriptor(InputStream portletStream,
079:                    String schemaLocation) throws DeploymentDescriptorException {
080:                SAXBuilder builder = null;
081:                String validateString = System.getProperty(VALIDATE_SCHEMA);
082:
083:                // validating the schema
084:                if (validateString != null
085:                        && validateString.equalsIgnoreCase("true")) {
086:                    String parser = BUILDER_SAX_PARSER_SUN_INTERNAL;
087:                    if (!isParserAvailable(parser)) {
088:                        parser = BUILDER_SAX_PARSER;
089:                    }
090:                    builder = new SAXBuilder(parser, true);
091:                    builder.setFeature(BUILDER_VALIDATION_SCHEMA_FEATURE, true);
092:                    builder.setProperty(BUILDER_SCHEMA_LOC_PROPERTY,
093:                            schemaLocation);
094:                    debugLogger.log(Level.INFO, "PSPL_PCCCSPPCCD0002",
095:                            validateString);
096:                } else {
097:                    builder = new SAXBuilder();
098:                }
099:
100:                Element element = null;
101:
102:                try {
103:                    Document doc = builder.build(portletStream);
104:                    element = doc.getRootElement();
105:                } catch (IOException e) {
106:                    throw new DeploymentDescriptorException(
107:                            "error reading stream", e);
108:                } catch (JDOMException je) {
109:                    debugLogger.log(Level.SEVERE, "PSPL_PCCCSPPCCD0003", je);
110:                    throw new DeploymentDescriptorException(
111:                            "Can not read deployment descriptor", je);
112:                }
113:
114:                debugLogger.log(Level.INFO, "PSPL_PCCCSPPCCD0004", element);
115:                return element;
116:            }
117:
118:            private boolean isParserAvailable(String parser) {
119:                boolean result = true;
120:                try {
121:                    Class.forName(parser);
122:                } catch (ClassNotFoundException e) {
123:                    result = false;
124:                }
125:
126:                return result;
127:            }
128:
129:            /**
130:             * Loads the deployment descriptor into PortletAppDescriptor structure.
131:             * <P>
132:             * @param The root Element of the deployment descriptor document
133:             * @return The PortletAppDescriptor object, null if portlet app descriptor
134:             * can not be read or can not be instantiated.
135:             */
136:            public PortletAppDescriptor loadPortletAppDescriptor(
137:                    InputStream portletStream, InputStream extStream)
138:                    throws DeploymentDescriptorException {
139:
140:                PortletAppDescriptor appDescriptor = null;
141:
142:                if (portletStream != null) {
143:                    Element root = readDeploymentDescriptor(portletStream,
144:                            PORTLET_NAMESPACE + " " + _portletSchemaLocation
145:                                    + PORTLET_SCHEMA_FILE);
146:                    if (root != null) {
147:                        Namespace namespace = Namespace
148:                                .getNamespace(PORTLET_NAMESPACE);
149:                        appDescriptor = new PortletAppDescriptor(debugLogger,
150:                                extStream);
151:                        appDescriptor.load(root, namespace, this );
152:                    }
153:                }
154:
155:                return appDescriptor;
156:            }
157:
158:            public DeploymentExtensionDescriptor loadDeploymentExtensionDescriptor(
159:                    InputStream extStream) throws DeploymentDescriptorException {
160:
161:                DeploymentExtensionDescriptor exDescriptor = null;
162:
163:                if (extStream != null) {
164:                    Element root = readDeploymentDescriptor(extStream,
165:                            SUN_PORTAL_NAMESPACE + " " + _portletSchemaLocation
166:                                    + SUN_PORTLET_SCHEMA_FILE);
167:                    if (root != null) {
168:                        Namespace namespace = Namespace
169:                                .getNamespace(SUN_PORTAL_NAMESPACE);
170:                        exDescriptor = new DeploymentExtensionDescriptor(
171:                                debugLogger);
172:                        exDescriptor.load(root, namespace);
173:                    }
174:                }
175:
176:                return exDescriptor;
177:            }
178:
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.