Source Code Cross Referenced for DOMEntityResolverWrapper.java in  » XML » xerces-2_9_1 » org » apache » xerces » util » 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 » XML » xerces 2_9_1 » org.apache.xerces.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.xerces.util;
019:
020:        import org.apache.xerces.xni.XNIException;
021:        import org.apache.xerces.xni.XMLResourceIdentifier;
022:        import org.apache.xerces.xni.grammars.XMLGrammarDescription;
023:        import org.apache.xerces.xni.parser.XMLEntityResolver;
024:        import org.apache.xerces.xni.parser.XMLInputSource;
025:
026:        import org.w3c.dom.ls.LSResourceResolver;
027:        import org.w3c.dom.ls.LSInput;
028:
029:        import java.io.InputStream;
030:        import java.io.IOException;
031:        import java.io.Reader;
032:        import java.io.StringReader;
033:
034:        /**
035:         * This class wraps DOM entity resolver to XNI entity resolver.
036:         *
037:         * @see LSResourceResolver
038:         *
039:         * @author Gopal Sharma, SUN MicroSystems Inc.
040:         * @author Elena Litani, IBM 
041:         * @author Ramesh Mandava, Sun Microsystems
042:         * @version $Id: DOMEntityResolverWrapper.java 447241 2006-09-18 05:12:57Z mrglavas $
043:         */
044:        public class DOMEntityResolverWrapper implements  XMLEntityResolver {
045:
046:            //
047:            // Data
048:            //
049:
050:            /** XML 1.0 type constant according to DOM L3 LS CR spec "http://www.w3.org/TR/2003/CR-DOM-Level-3-LS-20031107" */
051:            private static final String XML_TYPE = "http://www.w3.org/TR/REC-xml";
052:
053:            /** XML Schema constant according to DOM L3 LS CR spec "http://www.w3.org/TR/2003/CR-DOM-Level-3-LS-20031107" */
054:            private static final String XSD_TYPE = "http://www.w3.org/2001/XMLSchema";
055:
056:            /** The DOM entity resolver. */
057:            protected LSResourceResolver fEntityResolver;
058:
059:            //
060:            // Constructors
061:            //
062:
063:            /** Default constructor. */
064:            public DOMEntityResolverWrapper() {
065:            }
066:
067:            /** Wraps the specified DOM entity resolver. */
068:            public DOMEntityResolverWrapper(LSResourceResolver entityResolver) {
069:                setEntityResolver(entityResolver);
070:            } // LSResourceResolver
071:
072:            //
073:            // Public methods
074:            //
075:
076:            /** Sets the DOM entity resolver. */
077:            public void setEntityResolver(LSResourceResolver entityResolver) {
078:                fEntityResolver = entityResolver;
079:            } // setEntityResolver(LSResourceResolver)
080:
081:            /** Returns the DOM entity resolver. */
082:            public LSResourceResolver getEntityResolver() {
083:                return fEntityResolver;
084:            } // getEntityResolver():LSResourceResolver
085:
086:            //
087:            // XMLEntityResolver methods
088:            //
089:
090:            /**
091:             * Resolves an external parsed entity. If the entity cannot be
092:             * resolved, this method should return null.
093:             *
094:             * @param resourceIdentifier	description of the resource to be revsoved
095:             * @throws XNIException Thrown on general error.
096:             * @throws IOException  Thrown if resolved entity stream cannot be
097:             *                      opened or some other i/o error occurs.
098:             */
099:            public XMLInputSource resolveEntity(
100:                    XMLResourceIdentifier resourceIdentifier)
101:                    throws XNIException, IOException {
102:                // resolve entity using DOM entity resolver
103:                if (fEntityResolver != null) {
104:                    // For entity resolution the type of the resource would be  XML TYPE
105:                    // DOM L3 LS spec mention only the XML 1.0 recommendation right now
106:                    LSInput inputSource = resourceIdentifier == null ? fEntityResolver
107:                            .resolveResource(null, null, null, null, null)
108:                            : fEntityResolver.resolveResource(
109:                                    getType(resourceIdentifier),
110:                                    resourceIdentifier.getNamespace(),
111:                                    resourceIdentifier.getPublicId(),
112:                                    resourceIdentifier.getLiteralSystemId(),
113:                                    resourceIdentifier.getBaseSystemId());
114:                    if (inputSource != null) {
115:                        String publicId = inputSource.getPublicId();
116:                        String systemId = inputSource.getSystemId();
117:                        String baseSystemId = inputSource.getBaseURI();
118:                        InputStream byteStream = inputSource.getByteStream();
119:                        Reader charStream = inputSource.getCharacterStream();
120:                        String encoding = inputSource.getEncoding();
121:                        String data = inputSource.getStringData();
122:
123:                        /**
124:                         * An LSParser looks at inputs specified in LSInput in
125:                         * the following order: characterStream, byteStream,
126:                         * stringData, systemId, publicId.
127:                         */
128:                        XMLInputSource xmlInputSource = new XMLInputSource(
129:                                publicId, systemId, baseSystemId);
130:
131:                        if (charStream != null) {
132:                            xmlInputSource.setCharacterStream(charStream);
133:                        } else if (byteStream != null) {
134:                            xmlInputSource
135:                                    .setByteStream((InputStream) byteStream);
136:                        } else if (data != null && data.length() != 0) {
137:                            xmlInputSource.setCharacterStream(new StringReader(
138:                                    data));
139:                        }
140:                        xmlInputSource.setEncoding(encoding);
141:                        return xmlInputSource;
142:                    }
143:                }
144:
145:                // unable to resolve entity
146:                return null;
147:
148:            } // resolveEntity(String,String,String):XMLInputSource
149:
150:            /** Determines the type of resource being resolved **/
151:            private String getType(XMLResourceIdentifier resourceIdentifier) {
152:                if (resourceIdentifier instanceof  XMLGrammarDescription) {
153:                    XMLGrammarDescription desc = (XMLGrammarDescription) resourceIdentifier;
154:                    if (XMLGrammarDescription.XML_SCHEMA.equals(desc
155:                            .getGrammarType())) {
156:                        return XSD_TYPE;
157:                    }
158:                }
159:                return XML_TYPE;
160:            } // getType(XMLResourceIdentifier):String
161:
162:        } // DOMEntityResolverWrapper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.