Source Code Cross Referenced for NonValidatingConfiguration.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 java.io.IOException;
021:        import java.util.Locale;
022:
023:        import org.apache.xerces.impl.Constants;
024:        import org.apache.xerces.impl.XMLDTDScannerImpl;
025:        import org.apache.xerces.impl.XMLDocumentScannerImpl;
026:        import org.apache.xerces.impl.XMLEntityManager;
027:        import org.apache.xerces.impl.XMLErrorReporter;
028:        import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
029:        import org.apache.xerces.impl.dv.DTDDVFactory;
030:        import org.apache.xerces.impl.msg.XMLMessageFormatter;
031:        import org.apache.xerces.impl.validation.ValidationManager;
032:        import org.apache.xerces.util.SymbolTable;
033:        import org.apache.xerces.xni.XMLLocator;
034:        import org.apache.xerces.xni.XNIException;
035:        import org.apache.xerces.xni.grammars.XMLGrammarPool;
036:        import org.apache.xerces.xni.parser.XMLComponent;
037:        import org.apache.xerces.xni.parser.XMLComponentManager;
038:        import org.apache.xerces.xni.parser.XMLConfigurationException;
039:        import org.apache.xerces.xni.parser.XMLDTDScanner;
040:        import org.apache.xerces.xni.parser.XMLDocumentScanner;
041:        import org.apache.xerces.xni.parser.XMLInputSource;
042:        import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
043:
044:        /**
045:         * This is the non validating parser configuration. It extends the basic
046:         * configuration with the set of following parser components:
047:         * Document scanner, DTD scanner, namespace binder, document handler.
048:         * <p>
049:         * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a> 
050:         * non-validating XML processor, since conformant non-validating processor is required  
051:         * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values, 
052:         * include the replacement text of internal entities, and supply default attribute values".
053:         * 
054:         * @author Elena Litani, IBM
055:         * @version $Id: NonValidatingConfiguration.java 447239 2006-09-18 05:08:26Z mrglavas $
056:         */
057:        public class NonValidatingConfiguration extends
058:                BasicParserConfiguration implements  XMLPullParserConfiguration {
059:
060:            //
061:            // Constants
062:            //
063:
064:            // feature identifiers
065:
066:            /** Feature identifier: warn on duplicate attribute definition. */
067:            protected static final String WARN_ON_DUPLICATE_ATTDEF = Constants.XERCES_FEATURE_PREFIX
068:                    + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
069:
070:            /** Feature identifier: warn on duplicate entity definition. */
071:            protected static final String WARN_ON_DUPLICATE_ENTITYDEF = Constants.XERCES_FEATURE_PREFIX
072:                    + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
073:
074:            /** Feature identifier: warn on undeclared element definition. */
075:            protected static final String WARN_ON_UNDECLARED_ELEMDEF = Constants.XERCES_FEATURE_PREFIX
076:                    + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
077:
078:            /** Feature identifier: allow Java encodings. */
079:            protected static final String ALLOW_JAVA_ENCODINGS = Constants.XERCES_FEATURE_PREFIX
080:                    + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
081:
082:            /** Feature identifier: continue after fatal error. */
083:            protected static final String CONTINUE_AFTER_FATAL_ERROR = Constants.XERCES_FEATURE_PREFIX
084:                    + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
085:
086:            /** Feature identifier: load external DTD. */
087:            protected static final String LOAD_EXTERNAL_DTD = Constants.XERCES_FEATURE_PREFIX
088:                    + Constants.LOAD_EXTERNAL_DTD_FEATURE;
089:
090:            /** Feature identifier: notify built-in refereces. */
091:            protected static final String NOTIFY_BUILTIN_REFS = Constants.XERCES_FEATURE_PREFIX
092:                    + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
093:
094:            /** Feature identifier: notify character refereces. */
095:            protected static final String NOTIFY_CHAR_REFS = Constants.XERCES_FEATURE_PREFIX
096:                    + Constants.NOTIFY_CHAR_REFS_FEATURE;
097:
098:            /** Feature identifier: expose schema normalized value */
099:            protected static final String NORMALIZE_DATA = Constants.XERCES_FEATURE_PREFIX
100:                    + Constants.SCHEMA_NORMALIZED_VALUE;
101:
102:            /** Feature identifier: send element default value via characters() */
103:            protected static final String SCHEMA_ELEMENT_DEFAULT = Constants.XERCES_FEATURE_PREFIX
104:                    + Constants.SCHEMA_ELEMENT_DEFAULT;
105:
106:            // property identifiers
107:
108:            /** Property identifier: error reporter. */
109:            protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX
110:                    + Constants.ERROR_REPORTER_PROPERTY;
111:
112:            /** Property identifier: entity manager. */
113:            protected static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX
114:                    + Constants.ENTITY_MANAGER_PROPERTY;
115:
116:            /** Property identifier document scanner: */
117:            protected static final String DOCUMENT_SCANNER = Constants.XERCES_PROPERTY_PREFIX
118:                    + Constants.DOCUMENT_SCANNER_PROPERTY;
119:
120:            /** Property identifier: DTD scanner. */
121:            protected static final String DTD_SCANNER = Constants.XERCES_PROPERTY_PREFIX
122:                    + Constants.DTD_SCANNER_PROPERTY;
123:
124:            /** Property identifier: grammar pool. */
125:            protected static final String XMLGRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX
126:                    + Constants.XMLGRAMMAR_POOL_PROPERTY;
127:
128:            /** Property identifier: DTD validator. */
129:            protected static final String DTD_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX
130:                    + Constants.DTD_VALIDATOR_PROPERTY;
131:
132:            /** Property identifier: namespace binder. */
133:            protected static final String NAMESPACE_BINDER = Constants.XERCES_PROPERTY_PREFIX
134:                    + Constants.NAMESPACE_BINDER_PROPERTY;
135:
136:            /** Property identifier: datatype validator factory. */
137:            protected static final String DATATYPE_VALIDATOR_FACTORY = Constants.XERCES_PROPERTY_PREFIX
138:                    + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
139:
140:            protected static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX
141:                    + Constants.VALIDATION_MANAGER_PROPERTY;
142:
143:            /** Property identifier: XML Schema validator. */
144:            protected static final String SCHEMA_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX
145:                    + Constants.SCHEMA_VALIDATOR_PROPERTY;
146:
147:            // debugging
148:
149:            /** Set to true and recompile to print exception stack trace. */
150:            private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
151:
152:            //
153:            // Data
154:            //
155:
156:            // components (non-configurable)
157:
158:            /** Grammar pool. */
159:            protected XMLGrammarPool fGrammarPool;
160:
161:            /** Datatype validator factory. */
162:            protected DTDDVFactory fDatatypeValidatorFactory;
163:
164:            // components (configurable)
165:
166:            /** Error reporter. */
167:            protected XMLErrorReporter fErrorReporter;
168:
169:            /** Entity manager. */
170:            protected XMLEntityManager fEntityManager;
171:
172:            /** Document scanner. */
173:            protected XMLDocumentScanner fScanner;
174:
175:            /** Input Source */
176:            protected XMLInputSource fInputSource;
177:
178:            /** DTD scanner. */
179:            protected XMLDTDScanner fDTDScanner;
180:
181:            protected ValidationManager fValidationManager;
182:
183:            // private data
184:
185:            /** Document scanner that does namespace binding. */
186:            private XMLNSDocumentScannerImpl fNamespaceScanner;
187:
188:            /** Default Xerces implementation of scanner*/
189:            private XMLDocumentScannerImpl fNonNSScanner;
190:
191:            /** fConfigUpdated is set to true if there has been any change to the configuration settings, 
192:             * i.e a feature or a property was changed.
193:             */
194:            protected boolean fConfigUpdated = false;
195:
196:            // state
197:
198:            /** Locator */
199:            protected XMLLocator fLocator;
200:
201:            /** 
202:             * True if a parse is in progress. This state is needed because
203:             * some features/properties cannot be set while parsing (e.g.
204:             * validation and namespaces).
205:             */
206:            protected boolean fParseInProgress = false;
207:
208:            //
209:            // Constructors
210:            //
211:
212:            /** Default constructor. */
213:            public NonValidatingConfiguration() {
214:                this (null, null, null);
215:            } // <init>()
216:
217:            /** 
218:             * Constructs a parser configuration using the specified symbol table. 
219:             *
220:             * @param symbolTable The symbol table to use.
221:             */
222:            public NonValidatingConfiguration(SymbolTable symbolTable) {
223:                this (symbolTable, null, null);
224:            } // <init>(SymbolTable)
225:
226:            /**
227:             * Constructs a parser configuration using the specified symbol table and
228:             * grammar pool.
229:             * <p>
230:             * <strong>REVISIT:</strong> 
231:             * Grammar pool will be updated when the new validation engine is
232:             * implemented.
233:             *
234:             * @param symbolTable The symbol table to use.
235:             * @param grammarPool The grammar pool to use.
236:             */
237:            public NonValidatingConfiguration(SymbolTable symbolTable,
238:                    XMLGrammarPool grammarPool) {
239:                this (symbolTable, grammarPool, null);
240:            } // <init>(SymbolTable,XMLGrammarPool)
241:
242:            /**
243:             * Constructs a parser configuration using the specified symbol table,
244:             * grammar pool, and parent settings.
245:             * <p>
246:             * <strong>REVISIT:</strong> 
247:             * Grammar pool will be updated when the new validation engine is
248:             * implemented.
249:             *
250:             * @param symbolTable    The symbol table to use.
251:             * @param grammarPool    The grammar pool to use.
252:             * @param parentSettings The parent settings.
253:             */
254:            public NonValidatingConfiguration(SymbolTable symbolTable,
255:                    XMLGrammarPool grammarPool,
256:                    XMLComponentManager parentSettings) {
257:                super (symbolTable, parentSettings);
258:
259:                // add default recognized features
260:                final String[] recognizedFeatures = { PARSER_SETTINGS,
261:                        NAMESPACES,
262:                        //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl
263:                        //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl
264:                        //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager
265:                        CONTINUE_AFTER_FATAL_ERROR,
266:                //LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl
267:                //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
268:                //NOTIFY_CHAR_REFS,		// from XMLDocumentFragmentScannerImpl
269:                //WARN_ON_DUPLICATE_ENTITYDEF   // from XMLEntityManager
270:                };
271:                addRecognizedFeatures(recognizedFeatures);
272:
273:                // set state for default features
274:                //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl
275:                //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);    // from XMLDTDScannerImpl
276:                //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager
277:                fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
278:                fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
279:                fFeatures.put(NAMESPACES, Boolean.TRUE);
280:                //setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl
281:                //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
282:                //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
283:                //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager
284:
285:                // add default recognized properties
286:                final String[] recognizedProperties = { ERROR_REPORTER,
287:                        ENTITY_MANAGER, DOCUMENT_SCANNER, DTD_SCANNER,
288:                        DTD_VALIDATOR, NAMESPACE_BINDER, XMLGRAMMAR_POOL,
289:                        DATATYPE_VALIDATOR_FACTORY, VALIDATION_MANAGER };
290:                addRecognizedProperties(recognizedProperties);
291:
292:                fGrammarPool = grammarPool;
293:                if (fGrammarPool != null) {
294:                    fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
295:                }
296:
297:                fEntityManager = createEntityManager();
298:                fProperties.put(ENTITY_MANAGER, fEntityManager);
299:                addComponent(fEntityManager);
300:
301:                fErrorReporter = createErrorReporter();
302:                fErrorReporter.setDocumentLocator(fEntityManager
303:                        .getEntityScanner());
304:                fProperties.put(ERROR_REPORTER, fErrorReporter);
305:                addComponent(fErrorReporter);
306:
307:                // this configuration delays creation of the scanner
308:                // till it is known if namespace processing should be performed
309:
310:                fDTDScanner = createDTDScanner();
311:                if (fDTDScanner != null) {
312:                    fProperties.put(DTD_SCANNER, fDTDScanner);
313:                    if (fDTDScanner instanceof  XMLComponent) {
314:                        addComponent((XMLComponent) fDTDScanner);
315:                    }
316:                }
317:
318:                fDatatypeValidatorFactory = createDatatypeValidatorFactory();
319:                if (fDatatypeValidatorFactory != null) {
320:                    fProperties.put(DATATYPE_VALIDATOR_FACTORY,
321:                            fDatatypeValidatorFactory);
322:                }
323:                fValidationManager = createValidationManager();
324:
325:                if (fValidationManager != null) {
326:                    fProperties.put(VALIDATION_MANAGER, fValidationManager);
327:                }
328:                // add message formatters
329:                if (fErrorReporter
330:                        .getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
331:                    XMLMessageFormatter xmft = new XMLMessageFormatter();
332:                    fErrorReporter.putMessageFormatter(
333:                            XMLMessageFormatter.XML_DOMAIN, xmft);
334:                    fErrorReporter.putMessageFormatter(
335:                            XMLMessageFormatter.XMLNS_DOMAIN, xmft);
336:                }
337:
338:                fConfigUpdated = false;
339:
340:                // set locale
341:                try {
342:                    setLocale(Locale.getDefault());
343:                } catch (XNIException e) {
344:                    // do nothing
345:                    // REVISIT: What is the right thing to do? -Ac
346:                }
347:
348:            } // <init>(SymbolTable,XMLGrammarPool)
349:
350:            //
351:            // Public methods
352:            //
353:            public void setFeature(String featureId, boolean state)
354:                    throws XMLConfigurationException {
355:                fConfigUpdated = true;
356:                super .setFeature(featureId, state);
357:            }
358:
359:            public void setProperty(String propertyId, Object value)
360:                    throws XMLConfigurationException {
361:                fConfigUpdated = true;
362:                super .setProperty(propertyId, value);
363:            }
364:
365:            /**
366:             * Set the locale to use for messages.
367:             *
368:             * @param locale The locale object to use for localization of messages.
369:             *
370:             * @exception XNIException Thrown if the parser does not support the
371:             *                         specified locale.
372:             */
373:            public void setLocale(Locale locale) throws XNIException {
374:                super .setLocale(locale);
375:                fErrorReporter.setLocale(locale);
376:            } // setLocale(Locale)
377:
378:            public boolean getFeature(String featureId)
379:                    throws XMLConfigurationException {
380:                // make this feature special
381:                if (featureId.equals(PARSER_SETTINGS)) {
382:                    return fConfigUpdated;
383:                }
384:                return super .getFeature(featureId);
385:
386:            } // getFeature(String):boolean
387:
388:            //
389:            // XMLPullParserConfiguration methods
390:            //
391:
392:            // parsing
393:
394:            /**
395:             * Sets the input source for the document to parse.
396:             *
397:             * @param inputSource The document's input source.
398:             *
399:             * @exception XMLConfigurationException Thrown if there is a 
400:             *                        configuration error when initializing the
401:             *                        parser.
402:             * @exception IOException Thrown on I/O error.
403:             *
404:             * @see #parse(boolean)
405:             */
406:            public void setInputSource(XMLInputSource inputSource)
407:                    throws XMLConfigurationException, IOException {
408:
409:                // REVISIT: this method used to reset all the components and
410:                //          construct the pipeline. Now reset() is called
411:                //          in parse (boolean) just before we parse the document
412:                //          Should this method still throw exceptions..?
413:
414:                fInputSource = inputSource;
415:
416:            } // setInputSource(XMLInputSource)
417:
418:            /**
419:             * Parses the document in a pull parsing fashion.
420:             *
421:             * @param complete True if the pull parser should parse the
422:             *                 remaining document completely.
423:             *
424:             * @return True if there is more document to parse.
425:             *
426:             * @exception XNIException Any XNI exception, possibly wrapping 
427:             *                         another exception.
428:             * @exception IOException  An IO exception from the parser, possibly
429:             *                         from a byte stream or character stream
430:             *                         supplied by the parser.
431:             *
432:             * @see #setInputSource
433:             */
434:            public boolean parse(boolean complete) throws XNIException,
435:                    IOException {
436:                //
437:                // reset and configure pipeline and set InputSource.
438:                if (fInputSource != null) {
439:                    try {
440:                        // resets and sets the pipeline.
441:                        reset();
442:                        fScanner.setInputSource(fInputSource);
443:                        fInputSource = null;
444:                    } catch (XNIException ex) {
445:                        if (PRINT_EXCEPTION_STACK_TRACE)
446:                            ex.printStackTrace();
447:                        throw ex;
448:                    } catch (IOException ex) {
449:                        if (PRINT_EXCEPTION_STACK_TRACE)
450:                            ex.printStackTrace();
451:                        throw ex;
452:                    } catch (RuntimeException ex) {
453:                        if (PRINT_EXCEPTION_STACK_TRACE)
454:                            ex.printStackTrace();
455:                        throw ex;
456:                    } catch (Exception ex) {
457:                        if (PRINT_EXCEPTION_STACK_TRACE)
458:                            ex.printStackTrace();
459:                        throw new XNIException(ex);
460:                    }
461:                }
462:
463:                try {
464:                    return fScanner.scanDocument(complete);
465:                } catch (XNIException ex) {
466:                    if (PRINT_EXCEPTION_STACK_TRACE)
467:                        ex.printStackTrace();
468:                    throw ex;
469:                } catch (IOException ex) {
470:                    if (PRINT_EXCEPTION_STACK_TRACE)
471:                        ex.printStackTrace();
472:                    throw ex;
473:                } catch (RuntimeException ex) {
474:                    if (PRINT_EXCEPTION_STACK_TRACE)
475:                        ex.printStackTrace();
476:                    throw ex;
477:                } catch (Exception ex) {
478:                    if (PRINT_EXCEPTION_STACK_TRACE)
479:                        ex.printStackTrace();
480:                    throw new XNIException(ex);
481:                }
482:
483:            } // parse(boolean):boolean
484:
485:            /**
486:             * If the application decides to terminate parsing before the xml document
487:             * is fully parsed, the application should call this method to free any
488:             * resource allocated during parsing. For example, close all opened streams.
489:             */
490:            public void cleanup() {
491:                fEntityManager.closeReaders();
492:            }
493:
494:            //
495:            // XMLParserConfiguration methods
496:            //
497:
498:            /**
499:             * Parses the specified input source.
500:             *
501:             * @param source The input source.
502:             *
503:             * @exception XNIException Throws exception on XNI error.
504:             * @exception java.io.IOException Throws exception on i/o error.
505:             */
506:            public void parse(XMLInputSource source) throws XNIException,
507:                    IOException {
508:
509:                if (fParseInProgress) {
510:                    // REVISIT - need to add new error message
511:                    throw new XNIException(
512:                            "FWK005 parse may not be called while parsing.");
513:                }
514:                fParseInProgress = true;
515:
516:                try {
517:                    setInputSource(source);
518:                    parse(true);
519:                } catch (XNIException ex) {
520:                    if (PRINT_EXCEPTION_STACK_TRACE)
521:                        ex.printStackTrace();
522:                    throw ex;
523:                } catch (IOException ex) {
524:                    if (PRINT_EXCEPTION_STACK_TRACE)
525:                        ex.printStackTrace();
526:                    throw ex;
527:                } catch (RuntimeException ex) {
528:                    if (PRINT_EXCEPTION_STACK_TRACE)
529:                        ex.printStackTrace();
530:                    throw ex;
531:                } catch (Exception ex) {
532:                    if (PRINT_EXCEPTION_STACK_TRACE)
533:                        ex.printStackTrace();
534:                    throw new XNIException(ex);
535:                } finally {
536:                    fParseInProgress = false;
537:                    // close all streams opened by xerces
538:                    this .cleanup();
539:                }
540:
541:            } // parse(InputSource)
542:
543:            //
544:            // Protected methods
545:            //
546:
547:            /** 
548:             * Reset all components before parsing. 
549:             *
550:             * @throws XNIException Thrown if an error occurs during initialization.
551:             */
552:            protected void reset() throws XNIException {
553:
554:                if (fValidationManager != null)
555:                    fValidationManager.reset();
556:                // configure the pipeline and initialize the components
557:                configurePipeline();
558:                super .reset();
559:
560:            } // reset()
561:
562:            /** Configures the pipeline. */
563:            protected void configurePipeline() {
564:                // create appropriate scanner
565:                // and register it as one of the components.
566:                if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
567:                    if (fNamespaceScanner == null) {
568:                        fNamespaceScanner = new XMLNSDocumentScannerImpl();
569:                        addComponent((XMLComponent) fNamespaceScanner);
570:                    }
571:                    fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
572:                    fNamespaceScanner.setDTDValidator(null);
573:                    fScanner = fNamespaceScanner;
574:                } else {
575:                    if (fNonNSScanner == null) {
576:                        fNonNSScanner = new XMLDocumentScannerImpl();
577:                        addComponent((XMLComponent) fNonNSScanner);
578:                    }
579:                    fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
580:                    fScanner = fNonNSScanner;
581:                }
582:
583:                fScanner.setDocumentHandler(fDocumentHandler);
584:                fLastComponent = fScanner;
585:                // setup dtd pipeline
586:                if (fDTDScanner != null) {
587:                    fDTDScanner.setDTDHandler(fDTDHandler);
588:                    fDTDScanner
589:                            .setDTDContentModelHandler(fDTDContentModelHandler);
590:                }
591:
592:            } // configurePipeline()
593:
594:            // features and properties
595:
596:            /**
597:             * Check a feature. If feature is know and supported, this method simply
598:             * returns. Otherwise, the appropriate exception is thrown.
599:             *
600:             * @param featureId The unique identifier (URI) of the feature.
601:             *
602:             * @throws XMLConfigurationException Thrown for configuration error.
603:             *                                   In general, components should
604:             *                                   only throw this exception if
605:             *                                   it is <strong>really</strong>
606:             *                                   a critical error.
607:             */
608:            protected void checkFeature(String featureId)
609:                    throws XMLConfigurationException {
610:
611:                //
612:                // Xerces Features
613:                //
614:
615:                if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
616:                    final int suffixLength = featureId.length()
617:                            - Constants.XERCES_FEATURE_PREFIX.length();
618:
619:                    //
620:                    // http://apache.org/xml/features/validation/dynamic
621:                    //   Allows the parser to validate a document only when it
622:                    //   contains a grammar. Validation is turned on/off based
623:                    //   on each document instance, automatically.
624:                    //
625:                    if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE
626:                            .length()
627:                            && featureId
628:                                    .endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
629:                        return;
630:                    }
631:                    //
632:                    // http://apache.org/xml/features/validation/default-attribute-values
633:                    //
634:                    if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE
635:                            .length()
636:                            && featureId
637:                                    .endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
638:                        // REVISIT
639:                        short type = XMLConfigurationException.NOT_SUPPORTED;
640:                        throw new XMLConfigurationException(type, featureId);
641:                    }
642:                    //
643:                    // http://apache.org/xml/features/validation/default-attribute-values
644:                    //
645:                    if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE
646:                            .length()
647:                            && featureId
648:                                    .endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
649:                        // REVISIT
650:                        short type = XMLConfigurationException.NOT_SUPPORTED;
651:                        throw new XMLConfigurationException(type, featureId);
652:                    }
653:                    //
654:                    // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
655:                    //
656:                    if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE
657:                            .length()
658:                            && featureId
659:                                    .endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
660:                        return;
661:                    }
662:                    //
663:                    // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
664:                    //
665:                    if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE
666:                            .length()
667:                            && featureId
668:                                    .endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
669:                        return;
670:                    }
671:
672:                    //
673:                    // http://apache.org/xml/features/validation/default-attribute-values
674:                    //
675:                    if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE
676:                            .length()
677:                            && featureId
678:                                    .endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
679:                        short type = XMLConfigurationException.NOT_SUPPORTED;
680:                        throw new XMLConfigurationException(type, featureId);
681:                    }
682:                }
683:
684:                //
685:                // Not recognized
686:                //
687:
688:                super .checkFeature(featureId);
689:
690:            } // checkFeature(String)
691:
692:            /**
693:             * Check a property. If the property is know and supported, this method
694:             * simply returns. Otherwise, the appropriate exception is thrown.
695:             *
696:             * @param propertyId The unique identifier (URI) of the property
697:             *                   being set.
698:             *
699:             * @throws XMLConfigurationException Thrown for configuration error.
700:             *                                   In general, components should
701:             *                                   only throw this exception if
702:             *                                   it is <strong>really</strong>
703:             *                                   a critical error.
704:             */
705:            protected void checkProperty(String propertyId)
706:                    throws XMLConfigurationException {
707:
708:                //
709:                // Xerces Properties
710:                //
711:
712:                if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
713:                    final int suffixLength = propertyId.length()
714:                            - Constants.XERCES_PROPERTY_PREFIX.length();
715:
716:                    if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length()
717:                            && propertyId
718:                                    .endsWith(Constants.DTD_SCANNER_PROPERTY)) {
719:                        return;
720:                    }
721:                }
722:
723:                if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
724:                    final int suffixLength = propertyId.length()
725:                            - Constants.JAXP_PROPERTY_PREFIX.length();
726:
727:                    if (suffixLength == Constants.SCHEMA_SOURCE.length()
728:                            && propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
729:                        return;
730:                    }
731:                }
732:
733:                //
734:                // Not recognized
735:                //
736:
737:                super .checkProperty(propertyId);
738:
739:            } // checkProperty(String)
740:
741:            // factory methods
742:
743:            /** Creates an entity manager. */
744:            protected XMLEntityManager createEntityManager() {
745:                return new XMLEntityManager();
746:            } // createEntityManager():XMLEntityManager
747:
748:            /** Creates an error reporter. */
749:            protected XMLErrorReporter createErrorReporter() {
750:                return new XMLErrorReporter();
751:            } // createErrorReporter():XMLErrorReporter
752:
753:            /** Create a document scanner. */
754:            protected XMLDocumentScanner createDocumentScanner() {
755:                return null;
756:            } // createDocumentScanner():XMLDocumentScanner
757:
758:            /** Create a DTD scanner. */
759:            protected XMLDTDScanner createDTDScanner() {
760:                return new XMLDTDScannerImpl();
761:            } // createDTDScanner():XMLDTDScanner
762:
763:            /** Create a datatype validator factory. */
764:            protected DTDDVFactory createDatatypeValidatorFactory() {
765:                return DTDDVFactory.getInstance();
766:            } // createDatatypeValidatorFactory():DatatypeValidatorFactory
767:
768:            protected ValidationManager createValidationManager() {
769:                return new ValidationManager();
770:            }
771:
772:        } // class NonValidatingConfiguration
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.