Source Code Cross Referenced for StandardParserConfiguration.java in  » XML » xerces-2_9_1 » org » apache » xerces » parsers » 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.parsers 
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.parsers;
019:
020:        import org.apache.xerces.impl.Constants;
021:        import org.apache.xerces.impl.xs.XMLSchemaValidator;
022:        import org.apache.xerces.impl.xs.XSMessageFormatter;
023:        import org.apache.xerces.util.SymbolTable;
024:        import org.apache.xerces.xni.grammars.XMLGrammarPool;
025:        import org.apache.xerces.xni.parser.XMLComponentManager;
026:        import org.apache.xerces.xni.parser.XMLConfigurationException;
027:
028:        /**
029:         * This is the "standard" parser configuration. It extends the DTD
030:         * configuration with the standard set of parser components. 
031:         * The standard set of parser components include those needed
032:         * to parse and validate with DTD's, and those needed for XML
033:         * Schema.</p>
034:         * <p>
035:         * In addition to the features and properties recognized by the base
036:         * parser configuration, this class recognizes these additional 
037:         * features and properties:
038:         * <ul>
039:         * <li>Features
040:         *  <ul>
041:         *  <li>http://apache.org/xml/features/validation/schema</li>
042:         *  <li>http://apache.org/xml/features/validation/schema-full-checking</li>
043:         *  <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
044:         *  <li>http://apache.org/xml/features/validation/schema/element-default</li>
045:         *  </ul>
046:         * <li>Properties
047:         *  <ul>
048:         *   <li>http://apache.org/xml/properties/internal/error-reporter</li>
049:         *   <li>http://apache.org/xml/properties/internal/entity-manager</li>
050:         *   <li>http://apache.org/xml/properties/internal/document-scanner</li>
051:         *   <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
052:         *   <li>http://apache.org/xml/properties/internal/grammar-pool</li>
053:         *   <li>http://apache.org/xml/properties/internal/validator/dtd</li>
054:         *   <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
055:         *  </ul>
056:         * </ul>
057:         *
058:         * @author Arnaud  Le Hors, IBM
059:         * @author Andy Clark, IBM
060:         *
061:         * @version $Id: StandardParserConfiguration.java 447239 2006-09-18 05:08:26Z mrglavas $
062:         */
063:        public class StandardParserConfiguration extends DTDConfiguration {
064:
065:            //
066:            // Constants
067:            //
068:
069:            // feature identifiers
070:
071:            /** Feature identifier: expose schema normalized value */
072:            protected static final String NORMALIZE_DATA = Constants.XERCES_FEATURE_PREFIX
073:                    + Constants.SCHEMA_NORMALIZED_VALUE;
074:
075:            /** Feature identifier: send element default value via characters() */
076:            protected static final String SCHEMA_ELEMENT_DEFAULT = Constants.XERCES_FEATURE_PREFIX
077:                    + Constants.SCHEMA_ELEMENT_DEFAULT;
078:
079:            /** Feature identifier: augment PSVI */
080:            protected static final String SCHEMA_AUGMENT_PSVI = Constants.XERCES_FEATURE_PREFIX
081:                    + Constants.SCHEMA_AUGMENT_PSVI;
082:
083:            /** feature identifier: XML Schema validation */
084:            protected static final String XMLSCHEMA_VALIDATION = Constants.XERCES_FEATURE_PREFIX
085:                    + Constants.SCHEMA_VALIDATION_FEATURE;
086:
087:            /** feature identifier: XML Schema validation -- full checking */
088:            protected static final String XMLSCHEMA_FULL_CHECKING = Constants.XERCES_FEATURE_PREFIX
089:                    + Constants.SCHEMA_FULL_CHECKING;
090:
091:            /** Feature: generate synthetic annotations */
092:            protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = Constants.XERCES_FEATURE_PREFIX
093:                    + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;
094:
095:            /** Feature identifier: validate annotations */
096:            protected static final String VALIDATE_ANNOTATIONS = Constants.XERCES_FEATURE_PREFIX
097:                    + Constants.VALIDATE_ANNOTATIONS_FEATURE;
098:
099:            /** Feature identifier: honour all schemaLocations */
100:            protected static final String HONOUR_ALL_SCHEMALOCATIONS = Constants.XERCES_FEATURE_PREFIX
101:                    + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE;
102:
103:            /** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */
104:            protected static final String IGNORE_XSI_TYPE = Constants.XERCES_FEATURE_PREFIX
105:                    + Constants.IGNORE_XSI_TYPE_FEATURE;
106:
107:            /** Feature identifier: whether to ignore ID/IDREF errors */
108:            protected static final String ID_IDREF_CHECKING = Constants.XERCES_FEATURE_PREFIX
109:                    + Constants.ID_IDREF_CHECKING_FEATURE;
110:
111:            /** Feature identifier: whether to ignore unparsed entity errors */
112:            protected static final String UNPARSED_ENTITY_CHECKING = Constants.XERCES_FEATURE_PREFIX
113:                    + Constants.UNPARSED_ENTITY_CHECKING_FEATURE;
114:
115:            /** Feature identifier: whether to ignore identity constraint errors */
116:            protected static final String IDENTITY_CONSTRAINT_CHECKING = Constants.XERCES_FEATURE_PREFIX
117:                    + Constants.IDC_CHECKING_FEATURE;
118:
119:            // property identifiers
120:
121:            /** Property identifier: XML Schema validator. */
122:            protected static final String SCHEMA_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX
123:                    + Constants.SCHEMA_VALIDATOR_PROPERTY;
124:
125:            /** Property identifier: schema location. */
126:            protected static final String SCHEMA_LOCATION = Constants.XERCES_PROPERTY_PREFIX
127:                    + Constants.SCHEMA_LOCATION;
128:
129:            /** Property identifier: no namespace schema location. */
130:            protected static final String SCHEMA_NONS_LOCATION = Constants.XERCES_PROPERTY_PREFIX
131:                    + Constants.SCHEMA_NONS_LOCATION;
132:
133:            /** Property identifier: root type definition. */
134:            protected static final String ROOT_TYPE_DEF = Constants.XERCES_PROPERTY_PREFIX
135:                    + Constants.ROOT_TYPE_DEFINITION_PROPERTY;
136:
137:            //
138:            // Data
139:            //
140:
141:            // components (non-configurable)
142:
143:            /** XML Schema Validator. */
144:            protected XMLSchemaValidator fSchemaValidator;
145:
146:            //
147:            // Constructors
148:            //
149:
150:            /** Default constructor. */
151:            public StandardParserConfiguration() {
152:                this (null, null, null);
153:            } // <init>()
154:
155:            /** 
156:             * Constructs a parser configuration using the specified symbol table. 
157:             *
158:             * @param symbolTable The symbol table to use.
159:             */
160:            public StandardParserConfiguration(SymbolTable symbolTable) {
161:                this (symbolTable, null, null);
162:            } // <init>(SymbolTable)
163:
164:            /**
165:             * Constructs a parser configuration using the specified symbol table and
166:             * grammar pool.
167:             * <p>
168:             * <strong>REVISIT:</strong> 
169:             * Grammar pool will be updated when the new validation engine is
170:             * implemented.
171:             *
172:             * @param symbolTable The symbol table to use.
173:             * @param grammarPool The grammar pool to use.
174:             */
175:            public StandardParserConfiguration(SymbolTable symbolTable,
176:                    XMLGrammarPool grammarPool) {
177:                this (symbolTable, grammarPool, null);
178:            } // <init>(SymbolTable,XMLGrammarPool)
179:
180:            /**
181:             * Constructs a parser configuration using the specified symbol table,
182:             * grammar pool, and parent settings.
183:             * <p>
184:             * <strong>REVISIT:</strong> 
185:             * Grammar pool will be updated when the new validation engine is
186:             * implemented.
187:             *
188:             * @param symbolTable    The symbol table to use.
189:             * @param grammarPool    The grammar pool to use.
190:             * @param parentSettings The parent settings.
191:             */
192:            public StandardParserConfiguration(SymbolTable symbolTable,
193:                    XMLGrammarPool grammarPool,
194:                    XMLComponentManager parentSettings) {
195:                super (symbolTable, grammarPool, parentSettings);
196:
197:                // add default recognized features
198:                final String[] recognizedFeatures = {
199:                        NORMALIZE_DATA,
200:                        SCHEMA_ELEMENT_DEFAULT,
201:                        SCHEMA_AUGMENT_PSVI,
202:                        GENERATE_SYNTHETIC_ANNOTATIONS,
203:                        VALIDATE_ANNOTATIONS,
204:                        HONOUR_ALL_SCHEMALOCATIONS,
205:                        // NOTE: These shouldn't really be here but since the XML Schema
206:                        //       validator is constructed dynamically, its recognized
207:                        //       features might not have been set and it would cause a
208:                        //       not-recognized exception to be thrown. -Ac
209:                        XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING,
210:                        IGNORE_XSI_TYPE, ID_IDREF_CHECKING,
211:                        IDENTITY_CONSTRAINT_CHECKING, UNPARSED_ENTITY_CHECKING, };
212:                addRecognizedFeatures(recognizedFeatures);
213:
214:                // set state for default features
215:                setFeature(SCHEMA_ELEMENT_DEFAULT, true);
216:                setFeature(NORMALIZE_DATA, true);
217:                setFeature(SCHEMA_AUGMENT_PSVI, true);
218:                setFeature(GENERATE_SYNTHETIC_ANNOTATIONS, false);
219:                setFeature(VALIDATE_ANNOTATIONS, false);
220:                setFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
221:
222:                setFeature(IGNORE_XSI_TYPE, false);
223:                setFeature(ID_IDREF_CHECKING, true);
224:                setFeature(IDENTITY_CONSTRAINT_CHECKING, true);
225:                setFeature(UNPARSED_ENTITY_CHECKING, true);
226:
227:                // add default recognized properties
228:
229:                final String[] recognizedProperties = {
230:                // NOTE: These shouldn't really be here but since the XML Schema
231:                        //       validator is constructed dynamically, its recognized
232:                        //       properties might not have been set and it would cause a
233:                        //       not-recognized exception to be thrown. -Ac
234:                        SCHEMA_LOCATION, SCHEMA_NONS_LOCATION, ROOT_TYPE_DEF, };
235:
236:                addRecognizedProperties(recognizedProperties);
237:            } // <init>(SymbolTable,XMLGrammarPool)
238:
239:            //
240:            // Public methods
241:            //
242:
243:            /** Configures the pipeline. */
244:            protected void configurePipeline() {
245:                super .configurePipeline();
246:                if (getFeature(XMLSCHEMA_VALIDATION)) {
247:                    // If schema validator was not in the pipeline insert it.
248:                    if (fSchemaValidator == null) {
249:                        fSchemaValidator = new XMLSchemaValidator();
250:
251:                        // add schema component
252:                        fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
253:                        addComponent(fSchemaValidator);
254:                        // add schema message formatter
255:                        if (fErrorReporter
256:                                .getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
257:                            XSMessageFormatter xmft = new XSMessageFormatter();
258:                            fErrorReporter.putMessageFormatter(
259:                                    XSMessageFormatter.SCHEMA_DOMAIN, xmft);
260:                        }
261:
262:                    }
263:                    fLastComponent = fSchemaValidator;
264:                    fNamespaceBinder.setDocumentHandler(fSchemaValidator);
265:
266:                    fSchemaValidator.setDocumentHandler(fDocumentHandler);
267:                    fSchemaValidator.setDocumentSource(fNamespaceBinder);
268:                }
269:
270:            } // configurePipeline()
271:
272:            // features and properties
273:
274:            /**
275:             * Check a feature. If feature is know and supported, this method simply
276:             * returns. Otherwise, the appropriate exception is thrown.
277:             *
278:             * @param featureId The unique identifier (URI) of the feature.
279:             *
280:             * @throws XMLConfigurationException Thrown for configuration error.
281:             *                                   In general, components should
282:             *                                   only throw this exception if
283:             *                                   it is <strong>really</strong>
284:             *                                   a critical error.
285:             */
286:            protected void checkFeature(String featureId)
287:                    throws XMLConfigurationException {
288:
289:                //
290:                // Xerces Features
291:                //
292:
293:                if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
294:                    final int suffixLength = featureId.length()
295:                            - Constants.XERCES_FEATURE_PREFIX.length();
296:
297:                    //
298:                    // http://apache.org/xml/features/validation/schema
299:                    //   Lets the user turn Schema validation support on/off.
300:                    //
301:                    if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE
302:                            .length()
303:                            && featureId
304:                                    .endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) {
305:                        return;
306:                    }
307:                    // activate full schema checking
308:                    if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length()
309:                            && featureId
310:                                    .endsWith(Constants.SCHEMA_FULL_CHECKING)) {
311:                        return;
312:                    }
313:                    // Feature identifier: expose schema normalized value 
314:                    //  http://apache.org/xml/features/validation/schema/normalized-value
315:                    if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE
316:                            .length()
317:                            && featureId
318:                                    .endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) {
319:                        return;
320:                    }
321:                    // Feature identifier: send element default value via characters() 
322:                    // http://apache.org/xml/features/validation/schema/element-default
323:                    if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT
324:                            .length()
325:                            && featureId
326:                                    .endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) {
327:                        return;
328:                    }
329:                }
330:
331:                //
332:                // Not recognized
333:                //
334:
335:                super .checkFeature(featureId);
336:
337:            } // checkFeature(String)
338:
339:            /**
340:             * Check a property. If the property is know and supported, this method
341:             * simply returns. Otherwise, the appropriate exception is thrown.
342:             *
343:             * @param propertyId The unique identifier (URI) of the property
344:             *                   being set.
345:             *
346:             * @throws XMLConfigurationException Thrown for configuration error.
347:             *                                   In general, components should
348:             *                                   only throw this exception if
349:             *                                   it is <strong>really</strong>
350:             *                                   a critical error.
351:             */
352:            protected void checkProperty(String propertyId)
353:                    throws XMLConfigurationException {
354:
355:                //
356:                // Xerces Properties
357:                //
358:
359:                if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
360:                    final int suffixLength = propertyId.length()
361:                            - Constants.XERCES_PROPERTY_PREFIX.length();
362:
363:                    if (suffixLength == Constants.SCHEMA_LOCATION.length()
364:                            && propertyId.endsWith(Constants.SCHEMA_LOCATION)) {
365:                        return;
366:                    }
367:                    if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length()
368:                            && propertyId
369:                                    .endsWith(Constants.SCHEMA_NONS_LOCATION)) {
370:                        return;
371:                    }
372:                }
373:
374:                if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
375:                    final int suffixLength = propertyId.length()
376:                            - Constants.JAXP_PROPERTY_PREFIX.length();
377:
378:                    if (suffixLength == Constants.SCHEMA_SOURCE.length()
379:                            && propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
380:                        return;
381:                    }
382:                }
383:
384:                //
385:                // Not recognized
386:                //
387:
388:                super .checkProperty(propertyId);
389:
390:            } // checkProperty(String)
391:
392:        } // class StandardParserConfiguration
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.