Source Code Cross Referenced for StreamValidatorHelper.java in  » XML » xerces-2_9_1 » org » apache » xerces » jaxp » validation » 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.jaxp.validation 
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.jaxp.validation;
019:
020:        import java.lang.ref.SoftReference;
021:        import java.util.Locale;
022:        import java.io.IOException;
023:
024:        import javax.xml.transform.Result;
025:        import javax.xml.transform.Source;
026:        import javax.xml.transform.stream.StreamSource;
027:
028:        import org.apache.xerces.impl.Constants;
029:        import org.apache.xerces.impl.XMLErrorReporter;
030:        import org.apache.xerces.impl.msg.XMLMessageFormatter;
031:        import org.apache.xerces.impl.xs.XMLSchemaValidator;
032:        import org.apache.xerces.parsers.XML11Configuration;
033:        import org.apache.xerces.xni.XNIException;
034:        import org.apache.xerces.xni.parser.XMLInputSource;
035:        import org.apache.xerces.xni.parser.XMLParseException;
036:        import org.apache.xerces.xni.parser.XMLParserConfiguration;
037:        import org.xml.sax.SAXException;
038:
039:        /**
040:         * <p>A validator helper for <code>StreamSource</code>s.</p>
041:         * 
042:         * @author Michael Glavassevich, IBM
043:         * @version $Id: StreamValidatorHelper.java 542521 2007-05-29 13:58:42Z mrglavas $
044:         */
045:        final class StreamValidatorHelper implements  ValidatorHelper {
046:
047:            // feature identifiers
048:
049:            /** Feature identifier: parser settings. */
050:            private static final String PARSER_SETTINGS = Constants.XERCES_FEATURE_PREFIX
051:                    + Constants.PARSER_SETTINGS;
052:
053:            // property identifiers
054:
055:            /** Property identifier: entity resolver. */
056:            private static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX
057:                    + Constants.ENTITY_RESOLVER_PROPERTY;
058:
059:            /** Property identifier: error handler. */
060:            private static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX
061:                    + Constants.ERROR_HANDLER_PROPERTY;
062:
063:            /** Property identifier: error reporter. */
064:            private static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX
065:                    + Constants.ERROR_REPORTER_PROPERTY;
066:
067:            /** Property identifier: XML Schema validator. */
068:            private static final String SCHEMA_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX
069:                    + Constants.SCHEMA_VALIDATOR_PROPERTY;
070:
071:            /** Property identifier: symbol table. */
072:            private static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX
073:                    + Constants.SYMBOL_TABLE_PROPERTY;
074:
075:            /** Property identifier: validation manager. */
076:            private static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX
077:                    + Constants.VALIDATION_MANAGER_PROPERTY;
078:
079:            //
080:            // Data
081:            //
082:
083:            /** SoftReference to parser configuration. **/
084:            private SoftReference fConfiguration = new SoftReference(null);
085:
086:            /** Schema validator. **/
087:            private final XMLSchemaValidator fSchemaValidator;
088:
089:            /** Component manager. **/
090:            private final XMLSchemaValidatorComponentManager fComponentManager;
091:
092:            public StreamValidatorHelper(
093:                    XMLSchemaValidatorComponentManager componentManager) {
094:                fComponentManager = componentManager;
095:                fSchemaValidator = (XMLSchemaValidator) fComponentManager
096:                        .getProperty(SCHEMA_VALIDATOR);
097:            }
098:
099:            public void validate(Source source, Result result)
100:                    throws SAXException, IOException {
101:                if (result == null) {
102:                    final StreamSource streamSource = (StreamSource) source;
103:                    XMLInputSource input = new XMLInputSource(streamSource
104:                            .getPublicId(), streamSource.getSystemId(), null);
105:                    input.setByteStream(streamSource.getInputStream());
106:                    input.setCharacterStream(streamSource.getReader());
107:
108:                    // Gets the parser configuration. We'll create and initialize a new one, if we 
109:                    // haven't created one before or if the previous one was garbage collected.
110:                    XMLParserConfiguration config = (XMLParserConfiguration) fConfiguration
111:                            .get();
112:                    if (config == null) {
113:                        config = initialize();
114:                    }
115:                    // If settings have changed on the component manager, refresh the error handler and entity resolver.
116:                    else if (fComponentManager.getFeature(PARSER_SETTINGS)) {
117:                        config.setProperty(ENTITY_RESOLVER, fComponentManager
118:                                .getProperty(ENTITY_RESOLVER));
119:                        config.setProperty(ERROR_HANDLER, fComponentManager
120:                                .getProperty(ERROR_HANDLER));
121:                    }
122:
123:                    // prepare for parse
124:                    fComponentManager.reset();
125:                    fSchemaValidator.setDocumentHandler(null);
126:
127:                    try {
128:                        config.parse(input);
129:                    } catch (XMLParseException e) {
130:                        throw Util.toSAXParseException(e);
131:                    } catch (XNIException e) {
132:                        throw Util.toSAXException(e);
133:                    }
134:                    return;
135:                }
136:                throw new IllegalArgumentException(
137:                        JAXPValidationMessageFormatter.formatMessage(Locale
138:                                .getDefault(), "SourceResultMismatch",
139:                                new Object[] { source.getClass().getName(),
140:                                        result.getClass().getName() }));
141:            }
142:
143:            private XMLParserConfiguration initialize() {
144:                XML11Configuration config = new XML11Configuration();
145:                config.setProperty(ENTITY_RESOLVER, fComponentManager
146:                        .getProperty(ENTITY_RESOLVER));
147:                config.setProperty(ERROR_HANDLER, fComponentManager
148:                        .getProperty(ERROR_HANDLER));
149:                XMLErrorReporter errorReporter = (XMLErrorReporter) fComponentManager
150:                        .getProperty(ERROR_REPORTER);
151:                config.setProperty(ERROR_REPORTER, errorReporter);
152:                // add message formatters
153:                if (errorReporter
154:                        .getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
155:                    XMLMessageFormatter xmft = new XMLMessageFormatter();
156:                    errorReporter.putMessageFormatter(
157:                            XMLMessageFormatter.XML_DOMAIN, xmft);
158:                    errorReporter.putMessageFormatter(
159:                            XMLMessageFormatter.XMLNS_DOMAIN, xmft);
160:                }
161:                config.setProperty(SYMBOL_TABLE, fComponentManager
162:                        .getProperty(SYMBOL_TABLE));
163:                config.setProperty(VALIDATION_MANAGER, fComponentManager
164:                        .getProperty(VALIDATION_MANAGER));
165:                config.setDocumentHandler(fSchemaValidator);
166:                config.setDTDHandler(null);
167:                config.setDTDContentModelHandler(null);
168:                fConfiguration = new SoftReference(config);
169:                return config;
170:            }
171:
172:        } // StreamValidatorHelper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.