Source Code Cross Referenced for XMLParser.java in  » Web-Server » Rimfaxe-Web-Server » org » apache » xerces » framework » 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 » Web Server » Rimfaxe Web Server » org.apache.xerces.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The Apache Software License, Version 1.1
0003:         *
0004:         *
0005:         * Copyright (c) 1999,2000 The Apache Software Foundation.  All rights
0006:         * reserved.
0007:         *
0008:         * Redistribution and use in source and binary forms, with or without
0009:         * modification, are permitted provided that the following conditions
0010:         * are met:
0011:         *
0012:         * 1. Redistributions of source code must retain the above copyright
0013:         *    notice, this list of conditions and the following disclaimer.
0014:         *
0015:         * 2. Redistributions in binary form must reproduce the above copyright
0016:         *    notice, this list of conditions and the following disclaimer in
0017:         *    the documentation and/or other materials provided with the
0018:         *    distribution.
0019:         *
0020:         * 3. The end-user documentation included with the redistribution,
0021:         *    if any, must include the following acknowledgment:
0022:         *       "This product includes software developed by the
0023:         *        Apache Software Foundation (http://www.apache.org/)."
0024:         *    Alternately, this acknowledgment may appear in the software itself,
0025:         *    if and wherever such third-party acknowledgments normally appear.
0026:         *
0027:         * 4. The names "Xerces" and "Apache Software Foundation" must
0028:         *    not be used to endorse or promote products derived from this
0029:         *    software without prior written permission. For written
0030:         *    permission, please contact apache@apache.org.
0031:         *
0032:         * 5. Products derived from this software may not be called "Apache",
0033:         *    nor may "Apache" appear in their name, without prior written
0034:         *    permission of the Apache Software Foundation.
0035:         *
0036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0047:         * SUCH DAMAGE.
0048:         * ====================================================================
0049:         *
0050:         * This software consists of voluntary contributions made by many
0051:         * individuals on behalf of the Apache Software Foundation and was
0052:         * originally based on software copyright (c) 1999, International
0053:         * Business Machines, Inc., http://www.apache.org.  For more
0054:         * information on the Apache Software Foundation, please see
0055:         * <http://www.apache.org/>.
0056:         */
0057:
0058:        package org.apache.xerces.framework;
0059:
0060:        import java.io.InputStream;
0061:        import java.io.IOException;
0062:        import java.io.Reader;
0063:        import java.util.Locale;
0064:
0065:        import org.apache.xerces.readers.DefaultEntityHandler;
0066:        import org.apache.xerces.readers.XMLDeclRecognizer;
0067:        import org.apache.xerces.readers.XMLEntityHandler;
0068:        import org.apache.xerces.readers.XMLEntityReaderFactory;
0069:        import org.apache.xerces.utils.ChunkyCharArray;
0070:        import org.apache.xerces.utils.StringPool;
0071:        import org.apache.xerces.utils.XMLMessageProvider;
0072:        import org.apache.xerces.utils.XMLMessages;
0073:        import org.apache.xerces.utils.ImplementationMessages;
0074:        import org.apache.xerces.validators.common.GrammarResolver;
0075:        import org.apache.xerces.validators.common.GrammarResolverImpl;
0076:        import org.apache.xerces.validators.common.XMLValidator;
0077:        import org.apache.xerces.validators.datatype.DatatypeMessageProvider;
0078:        import org.apache.xerces.validators.datatype.DatatypeValidatorFactoryImpl;
0079:        import org.apache.xerces.validators.schema.SchemaMessageProvider;
0080:
0081:        import org.xml.sax.EntityResolver;
0082:        import org.xml.sax.ErrorHandler;
0083:        import org.xml.sax.InputSource;
0084:        import org.xml.sax.Locator;
0085:        import org.xml.sax.SAXException;
0086:        import org.xml.sax.SAXNotRecognizedException;
0087:        import org.xml.sax.SAXNotSupportedException;
0088:        import org.xml.sax.SAXParseException;
0089:
0090:        /**
0091:         * This is the base class of all standard parsers.
0092:         *
0093:         * @version $Id: XMLParser.java,v 1.33.2.5 2001/11/13 20:48:14 neilg Exp $
0094:         */
0095:        public abstract class XMLParser implements  XMLErrorReporter,
0096:                XMLDocumentHandler.DTDHandler {
0097:
0098:            //
0099:            // Constants
0100:            //
0101:
0102:            // protected
0103:
0104:            /** SAX2 features prefix (http://xml.org/sax/features/). */
0105:            protected static final String SAX2_FEATURES_PREFIX = "http://xml.org/sax/features/";
0106:
0107:            /** SAX2 properties prefix (http://xml.org/sax/properties/). */
0108:            protected static final String SAX2_PROPERTIES_PREFIX = "http://xml.org/sax/properties/";
0109:
0110:            /** Xerces features prefix (http://apache.org/xml/features/). */
0111:            protected static final String XERCES_FEATURES_PREFIX = "http://apache.org/xml/features/";
0112:
0113:            /** Xerces properties prefix (http://apache.org/xml/properties/). */
0114:            protected static final String XERCES_PROPERTIES_PREFIX = "http://apache.org/xml/properties/";
0115:
0116:            // private
0117:
0118:            /** Features recognized by this parser. */
0119:            private static final String RECOGNIZED_FEATURES[] = {
0120:                    // SAX2 core
0121:                    "http://xml.org/sax/features/validation",
0122:                    "http://xml.org/sax/features/external-general-entities",
0123:                    "http://xml.org/sax/features/external-parameter-entities",
0124:                    "http://xml.org/sax/features/namespaces",
0125:                    // Xerces
0126:                    "http://apache.org/xml/features/validation/schema",
0127:                    // "http://apache.org/xml/features/schema/expose-normalized-values",
0128:                    "http://apache.org/xml/features/validation/schema-full-checking",
0129:                    "http://apache.org/xml/features/validation/dynamic",
0130:                    "http://apache.org/xml/features/validation/default-attribute-values",
0131:
0132:                    "http://apache.org/xml/features/validation/validate-content-models",
0133:                    "http://apache.org/xml/features/validation/validate-datatypes",
0134:                    "http://apache.org/xml/features/validation/warn-on-duplicate-attdef",
0135:                    "http://apache.org/xml/features/validation/warn-on-undeclared-elemdef",
0136:                    "http://apache.org/xml/features/allow-java-encodings",
0137:                    "http://apache.org/xml/features/continue-after-fatal-error",
0138:                    "http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
0139:                    "http://apache.org/xml/features/nonvalidating/load-external-dtd" };
0140:
0141:            /** Properties recognized by this parser. */
0142:            private static final String RECOGNIZED_PROPERTIES[] = {
0143:                    // SAX2 core
0144:                    "http://xml.org/sax/properties/xml-string",
0145:                    // Xerces
0146:                    "http://apache.org/xml/properties/schema/external-schemaLocation",
0147:                    "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation" };
0148:
0149:            // debugging
0150:
0151:            /** Set to true and recompile to print exception stack trace. */
0152:            private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
0153:
0154:            //
0155:            // Data
0156:            //
0157:
0158:            protected GrammarResolver fGrammarResolver = null;
0159:
0160:            // state
0161:
0162:            protected boolean fParseInProgress = false;
0163:            private boolean fNeedReset = false;
0164:
0165:            // features
0166:
0167:            /** Continue after fatal error. */
0168:            private boolean fContinueAfterFatalError = false;
0169:
0170:            // properties
0171:
0172:            /** Error handler. */
0173:            private ErrorHandler fErrorHandler = null;
0174:
0175:            // other
0176:
0177:            private Locale fLocale = null;
0178:
0179:            // error information
0180:
0181:            private static XMLMessageProvider fgXMLMessages = new XMLMessages();
0182:            private static XMLMessageProvider fgImplementationMessages = new ImplementationMessages();
0183:            private static XMLMessageProvider fgSchemaMessages = new SchemaMessageProvider();
0184:            private static XMLMessageProvider fgDatatypeMessages = new DatatypeMessageProvider();
0185:
0186:            //
0187:            //
0188:            //
0189:            protected StringPool fStringPool = null;
0190:            protected XMLErrorReporter fErrorReporter = null;
0191:            protected DefaultEntityHandler fEntityHandler = null;
0192:            protected XMLDocumentScanner fScanner = null;
0193:            protected XMLValidator fValidator = null;
0194:
0195:            //
0196:            // Constructors
0197:            //
0198:
0199:            /**
0200:             * Constructor
0201:             */
0202:            protected XMLParser() {
0203:                this (new StringPool());
0204:            }
0205:
0206:            protected XMLParser(StringPool stringPool) {
0207:                fStringPool = stringPool;
0208:                fErrorReporter = this ;
0209:                fEntityHandler = new DefaultEntityHandler(fStringPool,
0210:                        fErrorReporter);
0211:                fScanner = new XMLDocumentScanner(fStringPool, fErrorReporter,
0212:                        fEntityHandler, new ChunkyCharArray(fStringPool));
0213:                fValidator = new XMLValidator(fStringPool, fErrorReporter,
0214:                        fEntityHandler, fScanner);
0215:                fGrammarResolver = new GrammarResolverImpl();
0216:                fScanner.setGrammarResolver(fGrammarResolver);
0217:                fValidator.setGrammarResolver(fGrammarResolver);
0218:                try {
0219:                    //JR-defect 48 fix - turn on Namespaces
0220:                    setNamespaces(true);
0221:                } catch (Exception e) {
0222:                    // ignore
0223:                }
0224:            }
0225:
0226:            /**
0227:             * Set char data processing preference and handlers.
0228:             */
0229:            protected void initHandlers(boolean sendCharDataAsCharArray,
0230:                    XMLDocumentHandler docHandler,
0231:                    XMLDocumentHandler.DTDHandler dtdHandler) {
0232:                fValidator.initHandlers(sendCharDataAsCharArray, docHandler,
0233:                        dtdHandler);
0234:                fScanner.setDTDHandler(this );
0235:            }
0236:
0237:            //
0238:            // Public methods
0239:            //
0240:
0241:            // features and properties
0242:
0243:            /**
0244:             * Returns a list of features that this parser recognizes.
0245:             * This method will never return null; if no features are
0246:             * recognized, this method will return a zero length array.
0247:             *
0248:             * @see #isFeatureRecognized
0249:             * @see #setFeature
0250:             * @see #getFeature
0251:             */
0252:            public String[] getFeaturesRecognized() {
0253:                return RECOGNIZED_FEATURES;
0254:            }
0255:
0256:            /**
0257:             * Returns true if the specified feature is recognized.
0258:             *
0259:             * @see #getFeaturesRecognized
0260:             * @see #setFeature
0261:             * @see #getFeature
0262:             */
0263:            public boolean isFeatureRecognized(String featureId) {
0264:                String[] recognizedFeatures = getFeaturesRecognized();
0265:                for (int i = 0; i < recognizedFeatures.length; i++) {
0266:                    if (featureId.equals(recognizedFeatures[i]))
0267:                        return true;
0268:                }
0269:                return false;
0270:            }
0271:
0272:            /**
0273:             * Returns a list of properties that this parser recognizes.
0274:             * This method will never return null; if no properties are
0275:             * recognized, this method will return a zero length array.
0276:             *
0277:             * @see #isPropertyRecognized
0278:             * @see #setProperty
0279:             * @see #getProperty
0280:             */
0281:            public String[] getPropertiesRecognized() {
0282:                return RECOGNIZED_PROPERTIES;
0283:            }
0284:
0285:            /**
0286:             * Returns true if the specified property is recognized.
0287:             *
0288:             * @see #getPropertiesRecognized
0289:             * @see #setProperty
0290:             * @see #getProperty
0291:             */
0292:            public boolean isPropertyRecognized(String propertyId) {
0293:                String[] recognizedProperties = getPropertiesRecognized();
0294:                for (int i = 0; i < recognizedProperties.length; i++) {
0295:                    if (propertyId.equals(recognizedProperties[i]))
0296:                        return true;
0297:                }
0298:                return false;
0299:            }
0300:
0301:            // initialization
0302:
0303:            /**
0304:             * Setup for application-driven parsing.
0305:             *
0306:             * @param source the input source to be parsed.
0307:             * @see #parseSome
0308:             */
0309:            public boolean parseSomeSetup(InputSource source) throws Exception {
0310:                if (fNeedReset)
0311:                    resetOrCopy();
0312:                fParseInProgress = true;
0313:                fNeedReset = true;
0314:                return fEntityHandler.startReadingFromDocument(source);
0315:            }
0316:
0317:            /**
0318:             * Application-driven parsing.
0319:             *
0320:             * @see #parseSomeSetup
0321:             */
0322:            public boolean parseSome() throws Exception {
0323:                if (!fScanner.parseSome(false)) {
0324:                    fParseInProgress = false;
0325:                    return false;
0326:                }
0327:                return true;
0328:            }
0329:
0330:            // resetting
0331:
0332:            /** Reset parser instance so that it can be reused. */
0333:            public void reset() throws Exception {
0334:                fGrammarResolver.clearGrammarResolver();
0335:                fStringPool.reset();
0336:                fEntityHandler.reset(fStringPool);
0337:                fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool));
0338:                fValidator.reset(fStringPool);
0339:                fNeedReset = false;
0340:            }
0341:
0342:            // properties (the normal kind)
0343:
0344:            /**
0345:             * return the locator being used by the parser
0346:             *
0347:             * @return the parser's active locator
0348:             */
0349:            public final Locator getLocator() {
0350:                return fEntityHandler;
0351:            }
0352:
0353:            /**
0354:             * return the locale
0355:             *
0356:             * @return the locale
0357:             */
0358:            public final Locale getfLocale() {
0359:                return fLocale;
0360:            }
0361:
0362:            /**
0363:             * return the XML Messages object
0364:             *
0365:             * @return the parser's messages object
0366:             */
0367:            public final XMLMessageProvider getfgXMLMessages() {
0368:                return fgXMLMessages;
0369:            }
0370:
0371:            /**
0372:             * return the Implementation Messages object
0373:             *
0374:             * @return the parser's implementation messages
0375:             */
0376:            public final XMLMessageProvider getfgImplementationMessages() {
0377:                return fgImplementationMessages;
0378:            }
0379:
0380:            /**
0381:             * return the Schema Messages object
0382:             *
0383:             * @return the parser's schema messages
0384:             */
0385:            public final XMLMessageProvider getfgSchemaMessages() {
0386:                return fgSchemaMessages;
0387:            }
0388:
0389:            /**
0390:             * return the Datatypes Messages object
0391:             *
0392:             * @return the parser's datatypes messages
0393:             */
0394:            public final XMLMessageProvider getfgDatatypeMessages() {
0395:                return fgDatatypeMessages;
0396:            }
0397:
0398:            /**
0399:             * Set the reader factory.
0400:             */
0401:            public void setReaderFactory(XMLEntityReaderFactory readerFactory) {
0402:                fEntityHandler.setReaderFactory(readerFactory);
0403:            }
0404:
0405:            /**
0406:             * Adds a recognizer.
0407:             *
0408:             * @param recognizer The XML recognizer to add.
0409:             */
0410:            public void addRecognizer(XMLDeclRecognizer recognizer) {
0411:                fEntityHandler.addRecognizer(recognizer);
0412:            }
0413:
0414:            //
0415:            // Protected methods
0416:            //
0417:
0418:            // SAX2 core features
0419:
0420:            /**
0421:             * Sets whether the parser validates.
0422:             * <p>
0423:             * This method is the equivalent to the feature:
0424:             * <pre>
0425:             * http://xml.org/sax/features/validation
0426:             * </pre>
0427:             *
0428:             * @param validate True to validate; false to not validate.
0429:             *
0430:             * @see #getValidation
0431:             * @see #setFeature
0432:             */
0433:            protected void setValidation(boolean validate)
0434:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0435:                if (fParseInProgress) {
0436:                    throw new SAXNotSupportedException(
0437:                            "PAR004 Cannot setFeature(http://xml.org/sax/features/validation): parse is in progress.\n"
0438:                                    + "http://xml.org/sax/features/validation");
0439:                }
0440:                try {
0441:                    // REVISIT: [Q] Should the scanner tell the validator that
0442:                    //              validation is on? -Ac
0443:                    fScanner.setValidationEnabled(validate);
0444:                    fValidator.setValidationEnabled(validate);
0445:                } catch (Exception ex) {
0446:                    throw new SAXNotSupportedException(ex.getMessage());
0447:                }
0448:            }
0449:
0450:            /**
0451:             * Returns true if validation is turned on.
0452:             *
0453:             * @see #setValidation
0454:             */
0455:            protected boolean getValidation() throws SAXNotRecognizedException,
0456:                    SAXNotSupportedException {
0457:                return fValidator.getValidationEnabled();
0458:            }
0459:
0460:            /**
0461:             * <b>Note: Currently, this parser always expands external general
0462:             * entities.</b> Setting this feature to false will throw a
0463:             * SAXNotSupportedException.
0464:             * <p>
0465:             * Sets whether external general entities are expanded.
0466:             * <p>
0467:             * This method is the equivalent to the feature:
0468:             * <pre>
0469:             * http://xml.org/sax/features/external-general-entities
0470:             * </pre>
0471:             *
0472:             * @param expand True to expand external general entities; false
0473:             *               to not expand.
0474:             *
0475:             * @see #getExternalGeneralEntities
0476:             * @see #setFeature
0477:             */
0478:            protected void setExternalGeneralEntities(boolean expand)
0479:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0480:                if (fParseInProgress) {
0481:                    throw new SAXNotSupportedException(
0482:                            "PAR004 Cannot setFeature(http://xml.org/sax/features/external-general-entities): parse is in progress.\n"
0483:                                    + "http://xml.org/sax/features/external-general-entities");
0484:                }
0485:                if (!expand) {
0486:                    throw new SAXNotSupportedException(
0487:                            "http://xml.org/sax/features/external-general-entities");
0488:                }
0489:            }
0490:
0491:            /**
0492:             * <b>Note: This feature is always true.</b>
0493:             * <p>
0494:             * Returns true if external general entities are expanded.
0495:             *
0496:             * @see #setExternalGeneralEntities
0497:             */
0498:            protected boolean getExternalGeneralEntities()
0499:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0500:                return true;
0501:            }
0502:
0503:            /**
0504:             * <b>Note: Currently, this parser always expands external parameter
0505:             * entities.</b> Setting this feature to false will throw a
0506:             * SAXNotSupportedException.
0507:             * <p>
0508:             * Sets whether external parameter entities are expanded.
0509:             * <p>
0510:             * This method is the equivalent to the feature:
0511:             * <pre>
0512:             * http://xml.org/sax/features/external-parameter-entities
0513:             * </pre>
0514:             *
0515:             * @param expand True to expand external parameter entities; false
0516:             *               to not expand.
0517:             *
0518:             * @see #getExternalParameterEntities
0519:             * @see #setFeature
0520:             */
0521:            protected void setExternalParameterEntities(boolean expand)
0522:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0523:                if (fParseInProgress) {
0524:                    throw new SAXNotSupportedException(
0525:                            "PAR004 Cannot setFeature(http://xml.org/sax/features/external-general-entities): parse is in progress.\n"
0526:                                    + "http://xml.org/sax/features/external-general-entities");
0527:                }
0528:                if (!expand) {
0529:                    throw new SAXNotSupportedException(
0530:                            "http://xml.org/sax/features/external-parameter-entities");
0531:                }
0532:            }
0533:
0534:            /**
0535:             * <b>Note: This feature is always true.</b>
0536:             * <p>
0537:             * Returns true if external parameter entities are expanded.
0538:             *
0539:             * @see #setExternalParameterEntities
0540:             */
0541:            protected boolean getExternalParameterEntities()
0542:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0543:                return true;
0544:            }
0545:
0546:            /**
0547:             * Sets whether the parser preprocesses namespaces.
0548:             * <p>
0549:             * This method is the equivalent to the feature:
0550:             * <pre>
0551:             * http://xml.org/sax/features/namespaces
0552:             * <pre>
0553:             *
0554:             * @param process True to process namespaces; false to not process.
0555:             *
0556:             * @see #getNamespaces
0557:             * @see #setFeature
0558:             */
0559:            protected void setNamespaces(boolean process)
0560:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0561:                if (fParseInProgress) {
0562:                    throw new SAXNotSupportedException(
0563:                            "PAR004 Cannot setFeature(http://xml.org/sax/features/namespaces): parse is in progress.\n"
0564:                                    + "http://xml.org/sax/features/namespaces");
0565:                }
0566:                fScanner.setNamespacesEnabled(process);
0567:                // REVISIT: [Q] Should the scanner tell the validator that namespace
0568:                //              processing is on? -Ac
0569:                fValidator.setNamespacesEnabled(process);
0570:            }
0571:
0572:            /**
0573:             * Returns true if the parser preprocesses namespaces.
0574:             *
0575:             * @see #setNamespaces
0576:             */
0577:            protected boolean getNamespaces() throws SAXNotRecognizedException,
0578:                    SAXNotSupportedException {
0579:                return fValidator.getNamespacesEnabled();
0580:            }
0581:
0582:            // Xerces features
0583:
0584:            /**
0585:             * Allows the user to turn Schema support on/off.
0586:             * <p>
0587:             * This method is equivalent to the feature:
0588:             * <pre>
0589:             * http://apache.org/xml/features/validation/schema
0590:             * </pre>
0591:             *
0592:             * @param schema True to turn on Schema support; false to turn it off.
0593:             *
0594:             * @see #getValidationSchema
0595:             * @see #setFeature
0596:             */
0597:            protected void setValidationSchema(boolean schema)
0598:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0599:                if (fParseInProgress) {
0600:                    // REVISIT: Localize message
0601:                    throw new SAXNotSupportedException(
0602:                            "http://apache.org/xml/features/validation/schema: parse is in progress");
0603:                }
0604:                fValidator.setSchemaValidationEnabled(schema);
0605:            }
0606:
0607:            /**
0608:             * Returns true if Schema support is turned on.
0609:             *
0610:             * @see #setValidationSchema
0611:             */
0612:            protected boolean getValidationSchema()
0613:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0614:                return fValidator.getSchemaValidationEnabled();
0615:            }
0616:
0617:            /**
0618:             * Allows the user to turn full Schema constraint checking on/off.
0619:             * Only takes effect if Schema validation is enabled.
0620:             * If this feature is off, partial constraint checking is done.
0621:             * <p>
0622:             * This method is equivalent to the feature:
0623:             * <pre>
0624:             * http://apache.org/xml/features/validation/schema-full-checking
0625:             * </pre>
0626:             *
0627:             * @param schemaFullChecking True to turn on full schema constraint checking.
0628:             *
0629:             * @see #getValidationSchemaFullChecking
0630:             * @see #setFeature
0631:             */
0632:            protected void setValidationSchemaFullChecking(
0633:                    boolean schemaFullChecking)
0634:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0635:                if (fParseInProgress) {
0636:                    // REVISIT: Localize message
0637:                    throw new SAXNotSupportedException(
0638:                            "http://apache.org/xml/features/validation/schema-full-checking:  parse is in progress");
0639:                }
0640:                fValidator.setSchemaFullCheckingEnabled(schemaFullChecking);
0641:            }
0642:
0643:            /**
0644:             * Normalization of element content is controlled by this feature.
0645:             * If this feature is set to true, DOM and SAX APIs will expose element content
0646:             * that is normalized according to XML Schema REC.
0647:             * Otherwise, element content will be exposed as required by the infoset.
0648:             *
0649:             * @param normalize
0650:             */
0651:            protected void setNormalizeContents(boolean normalize) {
0652:                fValidator.setNormalizeContents(normalize);
0653:            }
0654:
0655:            protected boolean getNormalizeContents() {
0656:                return fValidator.getNormalizeConents();
0657:            }
0658:
0659:            /**
0660:             * Allows the user to set a list of external XML Schemas (ex."http://example.com schema.xsd")
0661:             * to be used by the parser.
0662:             * If two schemas with the same targetNamespace appear in both
0663:             * the list and a document, the one from the list will be picked up.
0664:             * See XML Schema REC: http://www.w3.org/TR/xmlschema-1/#schema-loc
0665:             * <P>
0666:             * This method is equivalent to the property:
0667:             * <PRE>http://apache.org/xml/properties/schema/external-schemaLocation</PRE>
0668:             *
0669:             * @param value  The list of schemas.
0670:             * @exception SAXNotRecognizedException
0671:             * @exception SAXNotSupportedException
0672:             */
0673:            protected void setExternalSchemaLocation(Object value)
0674:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0675:                if (fParseInProgress) {
0676:                    // REVISIT: Localize message
0677:                    throw new SAXNotSupportedException(
0678:                            "http://apache.org/xml/properties/validation/schema/external-schemaLocation:  parse is in progress");
0679:                }
0680:                fValidator.setExternalSchemas(value);
0681:            }
0682:
0683:            /**
0684:             * Allows the user to set external XML Schema with no target Namespace.
0685:             * This value overwrites the value on the _noNamespaceSchemaLocation_.
0686:             * See XML Schema REC: http://www.w3.org/TR/xmlschema-1/#schema-loc
0687:             * <P>
0688:             * This method is equivalent to the property:
0689:             * <PRE>http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation</PRE>
0690:             *
0691:             * @param value  An XML Schema file name
0692:             * @exception SAXNotRecognizedException
0693:             * @exception SAXNotSupportedException
0694:             */
0695:            protected void setExternalNoNamespaceSchemaLocation(Object value)
0696:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0697:                if (fParseInProgress) {
0698:                    // REVISIT: Localize message
0699:                    throw new SAXNotSupportedException(
0700:                            "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation:  parse is in progress");
0701:                }
0702:                fValidator.setExternalNoNamespaceSchema(value);
0703:            }
0704:
0705:            /**
0706:             * Returns true if Schema support is turned on.
0707:             *
0708:             * @see #setValidationSchemaFullChecking
0709:             */
0710:            protected boolean getValidationSchemaFullChecking()
0711:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0712:                return fValidator.getSchemaFullCheckingEnabled();
0713:            }
0714:
0715:            /**
0716:             * Allows the parser to validate a document only when it contains a
0717:             * grammar. Validation is turned on/off based on each document
0718:             * instance, automatically.
0719:             * <p>
0720:             * This method is the equivalent to the feature:
0721:             * <pre>
0722:             * http://apache.org/xml/features/validation/dynamic
0723:             * </pre>
0724:             *
0725:             * @param dynamic True to dynamically validate documents; false to
0726:             *                validate based on the validation feature.
0727:             *
0728:             * @see #getValidationDynamic
0729:             * @see #setFeature
0730:             */
0731:            protected void setValidationDynamic(boolean dynamic)
0732:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0733:                if (fParseInProgress) {
0734:                    // REVISIT: Localize message
0735:                    throw new SAXNotSupportedException(
0736:                            "http://apache.org/xml/features/validation/dynamic: parse is in progress");
0737:                }
0738:                try {
0739:                    fValidator.setDynamicValidationEnabled(dynamic);
0740:                } catch (Exception ex) {
0741:                    throw new SAXNotSupportedException(ex.getMessage());
0742:                }
0743:            }
0744:
0745:            /**
0746:             * Returns true if validation is based on whether a document
0747:             * contains a grammar.
0748:             *
0749:             * @see #setValidationDynamic
0750:             */
0751:            protected boolean getValidationDynamic()
0752:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0753:                return fValidator.getDynamicValidationEnabled();
0754:            }
0755:
0756:            /**
0757:             *
0758:             */
0759:            protected void setNormalizeAttributeValues(boolean normalize) {
0760:                fValidator.setNormalizeAttributeValues(normalize);
0761:            }
0762:
0763:            /**
0764:             * Allows the parser to have the choice to load DTD grammar when
0765:             * validation is off.
0766:             * <p>
0767:             * This method is the equivalent to the feature:
0768:             * <pre>
0769:             * http://apache.org/xml/features/nonvalidating/load-dtd-grammar
0770:             * </pre>
0771:             *
0772:             * @param loadDTDGrammar True to turn on the feature; false to
0773:             *                turn off the feature.
0774:             *
0775:             * @see #getLoadDTDGrammar
0776:             * @see #setFeature
0777:             */
0778:            protected void setLoadDTDGrammar(boolean loadDTDGrammar)
0779:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0780:                if (fParseInProgress) {
0781:                    // REVISIT: Localize message
0782:                    throw new SAXNotSupportedException(
0783:                            "http://apache.org/xml/features/nonvalidating/load-dtd-grammar: parse is in progress");
0784:                }
0785:                try {
0786:                    fValidator.setLoadDTDGrammar(loadDTDGrammar);
0787:                } catch (Exception ex) {
0788:                    throw new SAXNotSupportedException(ex.getMessage());
0789:                }
0790:            }
0791:
0792:            /**
0793:             * Returns true if load DTD grammar is turned on in the XMLValiator.
0794:             *
0795:             * @see #setLoadDTDGrammar
0796:             */
0797:            protected boolean getLoadDTDGrammar()
0798:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0799:                return fValidator.getLoadDTDGrammar();
0800:            }
0801:
0802:            /**
0803:             * Allows the parser to have the choice to load the external DTD when
0804:             * validation is off.
0805:             * <p>
0806:             * This method is the equivalent to the feature:
0807:             * <pre>
0808:             * http://apache.org/xml/features/nonvalidating/load-external-dtd
0809:             * </pre>
0810:             *
0811:             * @param loadExternalDTD True to turn on the feature; false to
0812:             *                turn off the feature.
0813:             *
0814:             * @see #getLoadExternalDTD
0815:             * @see #setFeature
0816:             */
0817:            protected void setLoadExternalDTD(boolean loadExternalDTD)
0818:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0819:                if (fParseInProgress) {
0820:                    // REVISIT: Localize message
0821:                    throw new SAXNotSupportedException(
0822:                            "http://apache.org/xml/features/nonvalidating/load-external-dtd: parse is in progress");
0823:                }
0824:                try {
0825:                    fScanner.setLoadExternalDTD(loadExternalDTD);
0826:                } catch (Exception ex) {
0827:                    throw new SAXNotSupportedException(ex.getMessage());
0828:                }
0829:            }
0830:
0831:            /**
0832:             * Returns true if loading of the external DTD is on.
0833:             *
0834:             * @see #setLoadExternalDTD
0835:             */
0836:            protected boolean getLoadExternalDTD()
0837:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0838:                return fScanner.getLoadExternalDTD();
0839:            }
0840:
0841:            /**
0842:             * Sets whether an error is emitted when an attribute is redefined
0843:             * in the grammar.
0844:             * <p>
0845:             * This method is the equivalent to the feature:
0846:             * <pre>
0847:             * http://apache.org/xml/features/validation/warn-on-duplicate-attdef
0848:             * </pre>
0849:             *
0850:             * @param warn True to warn; false to not warn.
0851:             *
0852:             * @see #getValidationWarnOnDuplicateAttdef
0853:             * @see #setFeature
0854:             */
0855:            protected void setValidationWarnOnDuplicateAttdef(boolean warn)
0856:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0857:                fValidator.setWarningOnDuplicateAttDef(warn);
0858:            }
0859:
0860:            /**
0861:             * Returns true if an error is emitted when an attribute is redefined
0862:             * in the grammar.
0863:             *
0864:             * @see #setValidationWarnOnDuplicateAttdef
0865:             */
0866:            protected boolean getValidationWarnOnDuplicateAttdef()
0867:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0868:                return fValidator.getWarningOnDuplicateAttDef();
0869:            }
0870:
0871:            /**
0872:             * Sets whether the parser emits an error when an element's content
0873:             * model references an element by name that is not declared in the
0874:             * grammar.
0875:             * <p>
0876:             * This method is the equivalent to the feature:
0877:             * <pre>
0878:             * http://apache.org/xml/features/validation/warn-on-undeclared-elemdef
0879:             * </pre>
0880:             *
0881:             * @param warn True to warn; false to not warn.
0882:             *
0883:             * @see #getValidationWarnOnUndeclaredElemdef
0884:             * @see #setFeature
0885:             */
0886:            protected void setValidationWarnOnUndeclaredElemdef(boolean warn)
0887:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0888:                fValidator.setWarningOnUndeclaredElements(warn);
0889:            }
0890:
0891:            /**
0892:             * Returns true if the parser emits an error when an undeclared
0893:             * element is referenced in the grammar.
0894:             *
0895:             * @see #setValidationWarnOnUndeclaredElemdef
0896:             */
0897:            protected boolean getValidationWarnOnUndeclaredElemdef()
0898:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0899:                return fValidator.getWarningOnUndeclaredElements();
0900:            }
0901:
0902:            /**
0903:             * Allows the use of Java encoding names in the XMLDecl and TextDecl
0904:             * lines in an XML document.
0905:             * <p>
0906:             * This method is the equivalent to the feature:
0907:             * <pre>
0908:             * http://apache.org/xml/features/allow-java-encodings
0909:             * </pre>
0910:             *
0911:             * @param allow True to allow Java encoding names; false to disallow.
0912:             *
0913:             * @see #getAllowJavaEncodings
0914:             * @see #setFeature
0915:             */
0916:            protected void setAllowJavaEncodings(boolean allow)
0917:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0918:                fEntityHandler.setAllowJavaEncodings(allow);
0919:            }
0920:
0921:            /**
0922:             * Returns true if Java encoding names are allowed in the XML document.
0923:             *
0924:             * @see #setAllowJavaEncodings
0925:             */
0926:            protected boolean getAllowJavaEncodings()
0927:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0928:                return fEntityHandler.getAllowJavaEncodings();
0929:            }
0930:
0931:            /**
0932:             * Allows the parser to continue after a fatal error. Normally, a
0933:             * fatal error would stop the parse.
0934:             * <p>
0935:             * This method is the equivalent to the feature:
0936:             * <pre>
0937:             * http://apache.org/xml/features/continue-after-fatal-error
0938:             * </pre>
0939:             *
0940:             * @param continueAfterFatalError True to continue; false to stop on
0941:             *                                fatal error.
0942:             *
0943:             * @see #getContinueAfterFatalError
0944:             * @see #setFeature
0945:             */
0946:            protected void setContinueAfterFatalError(
0947:                    boolean continueAfterFatalError)
0948:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0949:                fContinueAfterFatalError = continueAfterFatalError;
0950:            }
0951:
0952:            /**
0953:             * Returns true if the parser continues after a fatal error.
0954:             *
0955:             * @see #setContinueAfterFatalError
0956:             */
0957:            protected boolean getContinueAfterFatalError()
0958:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0959:                return fContinueAfterFatalError;
0960:            }
0961:
0962:            // SAX2 core properties
0963:
0964:            /**
0965:             * Set the separator to be used between the URI part of a name and the
0966:             * local part of a name when namespace processing is being performed
0967:             * (see the http://xml.org/sax/features/namespaces feature).  By default,
0968:             * the separator is a single space.
0969:             * <p>
0970:             * This property may not be set while a parse is in progress (throws a
0971:             * SAXNotSupportedException).
0972:             * <p>
0973:             * This method is the equivalent to the property:
0974:             * <pre>
0975:             * http://xml.org/sax/properties/namespace-sep
0976:             * </pre>
0977:             *
0978:             * @param separator The new namespace separator.
0979:             *
0980:             * @see #getNamespaceSep
0981:             * @see #setProperty
0982:             */
0983:            /***
0984:            protected void setNamespaceSep(String separator)
0985:                throws SAXNotRecognizedException, SAXNotSupportedException {
0986:                // REVISIT: Ask someone what it could possibly hurt to allow
0987:                //          the application to change this in mid-parse.
0988:                if (fParseInProgress) {
0989:                    throw new SAXNotSupportedException("http://xml.org/sax/properties/namespace-sep: parse is in progress");
0990:                }
0991:                fNamespaceSep = separator;
0992:            }
0993:            /***/
0994:
0995:            /**
0996:             * Returns the namespace separator.
0997:             *
0998:             * @see #setNamespaceSep
0999:             */
1000:            /***
1001:            protected String getNamespaceSep()
1002:                throws SAXNotRecognizedException, SAXNotSupportedException {
1003:                return fNamespaceSep;
1004:            }
1005:            /***/
1006:
1007:            /**
1008:             * This method is the equivalent to the property:
1009:             * <pre>
1010:             * http://xml.org/sax/properties/xml-string
1011:             * </pre>
1012:             *
1013:             * @see #getProperty
1014:             */
1015:            protected String getXMLString() throws SAXNotRecognizedException,
1016:                    SAXNotSupportedException {
1017:                throw new SAXNotSupportedException(
1018:                        "http://xml.org/sax/properties/xml-string");
1019:            }
1020:
1021:            // resetting
1022:
1023:            /**
1024:             * Reset or copy parser
1025:             * Allows parser instance reuse
1026:             */
1027:            protected void resetOrCopy() throws Exception {
1028:                fStringPool = new StringPool();
1029:                fEntityHandler.reset(fStringPool);
1030:                fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool));
1031:                fValidator.resetOrCopy(fStringPool);
1032:                fNeedReset = false;
1033:                // REVISIT: why did we do it?
1034:                //fGrammarResolver = new GrammarResolverImpl();
1035:                fGrammarResolver.clearGrammarResolver();
1036:                fScanner.setGrammarResolver(fGrammarResolver);
1037:                fValidator.setGrammarResolver(fGrammarResolver);
1038:            }
1039:
1040:            //
1041:            // Parser/XMLReader methods
1042:            //
1043:            // NOTE: This class does *not* implement the org.xml.sax.Parser
1044:            //       interface but it does share some common methods. -Ac
1045:
1046:            // handlers
1047:
1048:            /**
1049:             * Sets the resolver used to resolve external entities. The EntityResolver
1050:             * interface supports resolution of public and system identifiers.
1051:             *
1052:             * @param resolver The new entity resolver. Passing a null value will
1053:             *                 uninstall the currently installed resolver.
1054:             */
1055:            public void setEntityResolver(EntityResolver resolver) {
1056:                fEntityHandler.setEntityResolver(resolver);
1057:            }
1058:
1059:            /**
1060:             * Return the current entity resolver.
1061:             *
1062:             * @return The current entity resolver, or null if none
1063:             *         has been registered.
1064:             * @see #setEntityResolver
1065:             */
1066:            public EntityResolver getEntityResolver() {
1067:                return fEntityHandler.getEntityResolver();
1068:            }
1069:
1070:            /**
1071:             * Sets the error handler.
1072:             *
1073:             * @param handler The new error handler.
1074:             */
1075:            public void setErrorHandler(ErrorHandler handler) {
1076:                fErrorHandler = handler;
1077:            }
1078:
1079:            /**
1080:             * Return the current error handler.
1081:             *
1082:             * @return The current error handler, or null if none
1083:             *         has been registered.
1084:             * @see #setErrorHandler
1085:             */
1086:            public ErrorHandler getErrorHandler() {
1087:                return fErrorHandler;
1088:            }
1089:
1090:            // parsing
1091:
1092:            /**
1093:             * Parses the specified input source.
1094:             *
1095:             * @param source The input source.
1096:             *
1097:             * @exception org.xml.sax.SAXException Throws exception on SAX error.
1098:             * @exception java.io.IOException Throws exception on i/o error.
1099:             */
1100:            public void parse(InputSource source) throws SAXException,
1101:                    IOException {
1102:                if (fParseInProgress) {
1103:                    throw new org.xml.sax.SAXException(
1104:                            "FWK005 parse may not be called while parsing."); // REVISIT - need to add new error message
1105:                }
1106:
1107:                try {
1108:                    if (parseSomeSetup(source)) {
1109:                        fScanner.parseSome(true);
1110:                    }
1111:                } catch (org.xml.sax.SAXException ex) {
1112:                    if (PRINT_EXCEPTION_STACK_TRACE)
1113:                        ex.printStackTrace();
1114:                    throw ex;
1115:                } catch (IOException ex) {
1116:                    if (PRINT_EXCEPTION_STACK_TRACE)
1117:                        ex.printStackTrace();
1118:                    throw ex;
1119:                } catch (Exception ex) {
1120:                    if (PRINT_EXCEPTION_STACK_TRACE)
1121:                        ex.printStackTrace();
1122:                    throw new org.xml.sax.SAXException(ex);
1123:                } finally {
1124:                    fParseInProgress = false;
1125:                }
1126:
1127:            } // parse(InputSource)
1128:
1129:            /**
1130:             * Parses the input source specified by the given system identifier.
1131:             * <p>
1132:             * This method is <em>almost</em> equivalent to the following:
1133:             * <pre>
1134:             *     parse(new InputSource(systemId));
1135:             * </pre>
1136:             * The only difference is that this method will attempt to close
1137:             * the stream that was opened.
1138:             *
1139:             * @param source The input source.
1140:             *
1141:             * @exception org.xml.sax.SAXException Throws exception on SAX error.
1142:             * @exception java.io.IOException Throws exception on i/o error.
1143:             */
1144:            public void parse(String systemId) throws SAXException, IOException {
1145:
1146:                InputSource source = new InputSource(systemId);
1147:                try {
1148:                    parse(source);
1149:                } finally {
1150:                    // NOTE: Changed code to attempt to close the stream
1151:                    //       even after parsing failure. -Ac
1152:                    try {
1153:                        Reader reader = source.getCharacterStream();
1154:                        if (reader != null) {
1155:                            reader.close();
1156:                        } else {
1157:                            InputStream is = source.getByteStream();
1158:                            if (is != null) {
1159:                                is.close();
1160:                            }
1161:                        }
1162:                    } catch (IOException e) {
1163:                        // ignore
1164:                    }
1165:                }
1166:
1167:            } // parse(String)
1168:
1169:            // locale
1170:
1171:            /**
1172:             * Set the locale to use for messages.
1173:             *
1174:             * @param locale The locale object to use for localization of messages.
1175:             *
1176:             * @exception SAXException An exception thrown if the parser does not
1177:             *                         support the specified locale.
1178:             *
1179:             * @see org.xml.sax.Parser
1180:             */
1181:            public void setLocale(Locale locale) throws SAXException {
1182:
1183:                if (fParseInProgress) {
1184:                    throw new org.xml.sax.SAXException(
1185:                            "FWK006 setLocale may not be called while parsing"); // REVISIT - need to add new error message
1186:                }
1187:
1188:                fLocale = locale;
1189:                fgXMLMessages.setLocale(locale);
1190:                fgImplementationMessages.setLocale(locale);
1191:
1192:            } // setLocale(Locale)
1193:
1194:            //
1195:            // XMLErrorReporter methods
1196:            //
1197:
1198:            /**
1199:             * Report an error.
1200:             *
1201:             * @param locator Location of error.
1202:             * @param errorDomain The error domain.
1203:             * @param majorCode The major code of the error.
1204:             * @param minorCode The minor code of the error.
1205:             * @param args Arguments for replacement text.
1206:             * @param errorType The type of the error.
1207:             *
1208:             * @exception Exception Thrown on error.
1209:             *
1210:             * @see XMLErrorReporter#ERRORTYPE_WARNING
1211:             * @see XMLErrorReporter#ERRORTYPE_FATAL_ERROR
1212:             */
1213:            public void reportError(Locator locator, String errorDomain,
1214:                    int majorCode, int minorCode, Object args[], int errorType)
1215:                    throws Exception {
1216:
1217:                // create the appropriate message
1218:                SAXParseException spe;
1219:                if (errorDomain.equals(XMLMessages.XML_DOMAIN)) {
1220:                    spe = new SAXParseException(fgXMLMessages.createMessage(
1221:                            fLocale, majorCode, minorCode, args), locator);
1222:                } else if (errorDomain.equals(XMLMessages.XMLNS_DOMAIN)) {
1223:                    spe = new SAXParseException(fgXMLMessages.createMessage(
1224:                            fLocale, majorCode, minorCode, args), locator);
1225:                } else if (errorDomain
1226:                        .equals(ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN)) {
1227:                    spe = new SAXParseException(
1228:                            fgImplementationMessages.createMessage(fLocale,
1229:                                    majorCode, minorCode, args), locator);
1230:                } else if (errorDomain
1231:                        .equals(SchemaMessageProvider.SCHEMA_DOMAIN)) {
1232:                    spe = new SAXParseException(fgSchemaMessages.createMessage(
1233:                            fLocale, majorCode, minorCode, args), locator);
1234:                } else if (errorDomain
1235:                        .equals(DatatypeMessageProvider.DATATYPE_DOMAIN)) {
1236:                    spe = new SAXParseException(
1237:                            fgDatatypeMessages.createMessage(fLocale,
1238:                                    majorCode, minorCode, args), locator);
1239:                } else {
1240:                    throw new RuntimeException("FWK007 Unknown error domain \""
1241:                            + errorDomain + "\"." + "\n" + errorDomain);
1242:                }
1243:
1244:                // default error handling
1245:                if (fErrorHandler == null) {
1246:                    if (errorType == XMLErrorReporter.ERRORTYPE_FATAL_ERROR
1247:                            && !fContinueAfterFatalError) {
1248:                        throw spe;
1249:                    }
1250:                    return;
1251:                }
1252:
1253:                // make appropriate callback
1254:                if (errorType == XMLErrorReporter.ERRORTYPE_WARNING) {
1255:                    fErrorHandler.warning(spe);
1256:                } else if (errorType == XMLErrorReporter.ERRORTYPE_FATAL_ERROR) {
1257:                    fErrorHandler.fatalError(spe);
1258:                    if (!fContinueAfterFatalError) {
1259:                        Object[] fatalArgs = { spe.getMessage() };
1260:                        throw new SAXException(fgImplementationMessages
1261:                                .createMessage(fLocale,
1262:                                        ImplementationMessages.FATAL_ERROR, 0,
1263:                                        fatalArgs));
1264:                    }
1265:                } else {
1266:                    fErrorHandler.error(spe);
1267:                }
1268:
1269:            } // reportError(Locator,String,int,int,Object[],int)
1270:
1271:            //
1272:            // XMLReader methods
1273:            //
1274:
1275:            /**
1276:             * Set the state of a feature.
1277:             *
1278:             * Set the state of any feature in a SAX2 parser.  The parser
1279:             * might not recognize the feature, and if it does recognize
1280:             * it, it might not be able to fulfill the request.
1281:             *
1282:             * @param featureId The unique identifier (URI) of the feature.
1283:             * @param state The requested state of the feature (true or false).
1284:             *
1285:             * @exception org.xml.sax.SAXNotRecognizedException If the
1286:             *            requested feature is not known.
1287:             * @exception org.xml.sax.SAXNotSupportedException If the
1288:             *            requested feature is known, but the requested
1289:             *            state is not supported.
1290:             * @exception org.xml.sax.SAXException If there is any other
1291:             *            problem fulfilling the request.
1292:             */
1293:            public void setFeature(String featureId, boolean state)
1294:                    throws SAXNotRecognizedException, SAXNotSupportedException {
1295:
1296:                //
1297:                // SAX2 Features
1298:                //
1299:
1300:                if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
1301:                    String feature = featureId.substring(SAX2_FEATURES_PREFIX
1302:                            .length());
1303:                    //
1304:                    // http://xml.org/sax/features/validation
1305:                    //   Validate (true) or don't validate (false).
1306:                    //
1307:                    if (feature.equals("validation")) {
1308:                        setValidation(state);
1309:                        return;
1310:                    }
1311:                    //
1312:                    // http://xml.org/sax/features/external-general-entities
1313:                    //   Expand external general entities (true) or don't expand (false).
1314:                    //
1315:                    if (feature.equals("external-general-entities")) {
1316:                        setExternalGeneralEntities(state);
1317:                        return;
1318:                    }
1319:                    //
1320:                    // http://xml.org/sax/features/external-parameter-entities
1321:                    //   Expand external parameter entities (true) or don't expand (false).
1322:                    //
1323:                    if (feature.equals("external-parameter-entities")) {
1324:                        setExternalParameterEntities(state);
1325:                        return;
1326:                    }
1327:                    //
1328:                    // http://xml.org/sax/features/namespaces
1329:                    //   Preprocess namespaces (true) or don't preprocess (false).  See also
1330:                    //   the http://xml.org/sax/properties/namespace-sep property.
1331:                    //
1332:                    if (feature.equals("namespaces")) {
1333:                        setNamespaces(state);
1334:                        return;
1335:                    }
1336:                    //
1337:                    // Not recognized
1338:                    //
1339:                }
1340:
1341:                //
1342:                // Xerces Features
1343:                //
1344:
1345:                else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
1346:                    String feature = featureId.substring(XERCES_FEATURES_PREFIX
1347:                            .length());
1348:                    //
1349:                    // http://apache.org/xml/features/validation/schema
1350:                    //   Lets the user turn Schema validation support on/off.
1351:                    //
1352:                    if (feature.equals("validation/schema")) {
1353:                        setValidationSchema(state);
1354:                        return;
1355:                    }
1356:                    //
1357:                    // http://apache.org/xml/features/validation/schema-full-checking
1358:                    //   Lets the user turn Schema full constraint checking on/off.
1359:                    //
1360:                    if (feature.equals("validation/schema-full-checking")) {
1361:                        setValidationSchemaFullChecking(state);
1362:                        return;
1363:                    }
1364:
1365:                    //
1366:                    // http://apache.org/xml/features/validation/dynamic
1367:                    //   Allows the parser to validate a document only when it
1368:                    //   contains a grammar. Validation is turned on/off based
1369:                    //   on each document instance, automatically.
1370:                    //
1371:                    if (feature.equals("validation/dynamic")) {
1372:                        setValidationDynamic(state);
1373:                        return;
1374:                    }
1375:                    //
1376:                    // http://apache.org/xml/features/validation/default-attribute-values
1377:                    //
1378:                    if (feature.equals("validation/default-attribute-values")) {
1379:                        // REVISIT
1380:                        throw new SAXNotSupportedException(featureId);
1381:                    }
1382:
1383:                    if (feature.equals("schema/expose-normalized-values")) {
1384:                        setNormalizeContents(state);
1385:                        return;
1386:                    }
1387:                    //
1388:                    // http://apache.org/xml/features/validation/normalize-attribute-values
1389:                    //
1390:                    if (feature.equals("validation/normalize-attribute-values")) {
1391:                        setNormalizeAttributeValues(state);
1392:                    }
1393:                    //
1394:                    // http://apache.org/xml/features/validation/validate-content-models
1395:                    //
1396:                    if (feature.equals("validation/validate-content-models")) {
1397:                        // REVISIT
1398:                        throw new SAXNotSupportedException(featureId);
1399:                    }
1400:                    //
1401:                    // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
1402:                    //
1403:                    if (feature.equals("nonvalidating/load-dtd-grammar")) {
1404:                        setLoadDTDGrammar(state);
1405:                        return;
1406:                    }
1407:                    //
1408:                    // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
1409:                    //
1410:                    if (feature.equals("nonvalidating/load-external-dtd")) {
1411:                        setLoadExternalDTD(state);
1412:                        return;
1413:                    }
1414:
1415:                    //
1416:                    // http://apache.org/xml/features/validation/default-attribute-values
1417:                    //
1418:                    if (feature.equals("validation/validate-datatypes")) {
1419:                        // REVISIT
1420:                        throw new SAXNotSupportedException(featureId);
1421:                    }
1422:                    //
1423:                    // http://apache.org/xml/features/validation/warn-on-duplicate-attdef
1424:                    //   Emits an error when an attribute is redefined.
1425:                    //
1426:                    if (feature.equals("validation/warn-on-duplicate-attdef")) {
1427:                        setValidationWarnOnDuplicateAttdef(state);
1428:                        return;
1429:                    }
1430:                    //
1431:                    // http://apache.org/xml/features/validation/warn-on-undeclared-elemdef
1432:                    //   Emits an error when an element's content model
1433:                    //   references an element, by name, that is not declared
1434:                    //   in the grammar.
1435:                    //
1436:                    if (feature.equals("validation/warn-on-undeclared-elemdef")) {
1437:                        setValidationWarnOnUndeclaredElemdef(state);
1438:                        return;
1439:                    }
1440:                    //
1441:                    // http://apache.org/xml/features/allow-java-encodings
1442:                    //   Allows the use of Java encoding names in the XML
1443:                    //   and TextDecl lines.
1444:                    //
1445:                    if (feature.equals("allow-java-encodings")) {
1446:                        setAllowJavaEncodings(state);
1447:                        return;
1448:                    }
1449:                    //
1450:                    // http://apache.org/xml/features/continue-after-fatal-error
1451:                    //   Allows the parser to continue after a fatal error.
1452:                    //   Normally, a fatal error would stop the parse.
1453:                    //
1454:                    if (feature.equals("continue-after-fatal-error")) {
1455:                        setContinueAfterFatalError(state);
1456:                        return;
1457:                    }
1458:                    //
1459:                    // Not recognized
1460:                    //
1461:                }
1462:
1463:                //
1464:                // Not recognized
1465:                //
1466:
1467:                throw new SAXNotRecognizedException(featureId);
1468:
1469:            } // setFeature(String,boolean)
1470:
1471:            /**
1472:             * Query the state of a feature.
1473:             *
1474:             * Query the current state of any feature in a SAX2 parser.  The
1475:             * parser might not recognize the feature.
1476:             *
1477:             * @param featureId The unique identifier (URI) of the feature
1478:             *                  being set.
1479:             * @return The current state of the feature.
1480:             * @exception org.xml.sax.SAXNotRecognizedException If the
1481:             *            requested feature is not known.
1482:             * @exception org.xml.sax.SAXException If there is any other
1483:             *            problem fulfilling the request.
1484:             */
1485:            public boolean getFeature(String featureId)
1486:                    throws SAXNotRecognizedException, SAXNotSupportedException {
1487:
1488:                //
1489:                // SAX2 Features
1490:                //
1491:
1492:                if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
1493:                    String feature = featureId.substring(SAX2_FEATURES_PREFIX
1494:                            .length());
1495:                    //
1496:                    // http://xml.org/sax/features/validation
1497:                    //   Validate (true) or don't validate (false).
1498:                    //
1499:                    if (feature.equals("validation")) {
1500:                        return getValidation();
1501:                    }
1502:                    //
1503:                    // http://xml.org/sax/features/external-general-entities
1504:                    //   Expand external general entities (true) or don't expand (false).
1505:                    //
1506:                    if (feature.equals("external-general-entities")) {
1507:                        return getExternalGeneralEntities();
1508:                    }
1509:                    //
1510:                    // http://xml.org/sax/features/external-parameter-entities
1511:                    //   Expand external parameter entities (true) or don't expand (false).
1512:                    //
1513:                    if (feature.equals("external-parameter-entities")) {
1514:                        return getExternalParameterEntities();
1515:                    }
1516:                    //
1517:                    // http://xml.org/sax/features/namespaces
1518:                    //   Preprocess namespaces (true) or don't preprocess (false).  See also
1519:                    //   the http://xml.org/sax/properties/namespace-sep property.
1520:                    //
1521:                    if (feature.equals("namespaces")) {
1522:                        return getNamespaces();
1523:                    }
1524:                    //
1525:                    // Not recognized
1526:                    //
1527:                }
1528:
1529:                //
1530:                // Xerces Features
1531:                //
1532:
1533:                else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
1534:                    String feature = featureId.substring(XERCES_FEATURES_PREFIX
1535:                            .length());
1536:                    //
1537:                    // http://apache.org/xml/features/validation/schema
1538:                    //   Lets the user turn Schema validation support on/off.
1539:                    //
1540:                    if (feature.equals("validation/schema")) {
1541:                        return getValidationSchema();
1542:                    }
1543:                    // http://apache.org/xml/features/validation/schema-full-checking
1544:                    //   Lets the user turn Schema full constraint checking on/off.
1545:                    //
1546:                    if (feature.equals("validation/schema-full-checking")) {
1547:                        return getValidationSchemaFullChecking();
1548:                    }
1549:                    //
1550:                    //
1551:                    // http://apache.org/xml/features/validation/dynamic
1552:                    //   Allows the parser to validate a document only when it
1553:                    //   contains a grammar. Validation is turned on/off based
1554:                    //   on each document instance, automatically.
1555:                    //
1556:                    if (feature.equals("validation/dynamic")) {
1557:                        return getValidationDynamic();
1558:                    }
1559:                    //
1560:                    // http://apache.org/xml/features/validation/default-attribute-values
1561:                    //
1562:                    if (feature.equals("validation/default-attribute-values")) {
1563:                        // REVISIT
1564:                        throw new SAXNotRecognizedException(featureId);
1565:                    }
1566:                    if (feature.equals("validation/normalize-element-contents")) {
1567:                        return getNormalizeContents();
1568:                    }
1569:                    //
1570:                    // http://apache.org/xml/features/validation/validate-content-models
1571:                    //
1572:                    if (feature.equals("validation/validate-content-models")) {
1573:                        // REVISIT
1574:                        throw new SAXNotRecognizedException(featureId);
1575:                    }
1576:                    //
1577:                    // http://apache.org/xml/features/nonvalidating/load-dtd-grammar
1578:                    //
1579:                    if (feature.equals("nonvalidating/load-dtd-grammar")) {
1580:                        return getLoadDTDGrammar();
1581:                    }
1582:                    //
1583:                    // http://apache.org/xml/features/nonvalidating/load-external-dtd
1584:                    //
1585:                    if (feature.equals("nonvalidating/load-external-dtd")) {
1586:                        return getLoadExternalDTD();
1587:                    }
1588:                    //
1589:                    // http://apache.org/xml/features/validation/validate-datatypes
1590:                    //
1591:                    if (feature.equals("validation/validate-datatypes")) {
1592:                        // REVISIT
1593:                        throw new SAXNotRecognizedException(featureId);
1594:                    }
1595:                    //
1596:                    // http://apache.org/xml/features/validation/warn-on-duplicate-attdef
1597:                    //   Emits an error when an attribute is redefined.
1598:                    //
1599:                    if (feature.equals("validation/warn-on-duplicate-attdef")) {
1600:                        return getValidationWarnOnDuplicateAttdef();
1601:                    }
1602:                    //
1603:                    // http://apache.org/xml/features/validation/warn-on-undeclared-elemdef
1604:                    //   Emits an error when an element's content model
1605:                    //   references an element, by name, that is not declared
1606:                    //   in the grammar.
1607:                    //
1608:                    if (feature.equals("validation/warn-on-undeclared-elemdef")) {
1609:                        return getValidationWarnOnUndeclaredElemdef();
1610:                    }
1611:                    //
1612:                    // http://apache.org/xml/features/allow-java-encodings
1613:                    //   Allows the use of Java encoding names in the XML
1614:                    //   and TextDecl lines.
1615:                    //
1616:                    if (feature.equals("allow-java-encodings")) {
1617:                        return getAllowJavaEncodings();
1618:                    }
1619:                    //
1620:                    // http://apache.org/xml/features/continue-after-fatal-error
1621:                    //   Allows the parser to continue after a fatal error.
1622:                    //   Normally, a fatal error would stop the parse.
1623:                    //
1624:                    if (feature.equals("continue-after-fatal-error")) {
1625:                        return getContinueAfterFatalError();
1626:                    }
1627:                    //
1628:                    // Not recognized
1629:                    //
1630:                }
1631:
1632:                //
1633:                // Not recognized
1634:                //
1635:
1636:                throw new SAXNotRecognizedException(featureId);
1637:
1638:            } // getFeature(String):boolean
1639:
1640:            /**
1641:             * Set the value of a property.
1642:             *
1643:             * Set the value of any property in a SAX2 parser.  The parser
1644:             * might not recognize the property, and if it does recognize
1645:             * it, it might not support the requested value.
1646:             *
1647:             * @param propertyId The unique identifier (URI) of the property
1648:             *                   being set.
1649:             * @param Object The value to which the property is being set.
1650:             * @exception org.xml.sax.SAXNotRecognizedException If the
1651:             *            requested property is not known.
1652:             * @exception org.xml.sax.SAXNotSupportedException If the
1653:             *            requested property is known, but the requested
1654:             *            value is not supported.
1655:             * @exception org.xml.sax.SAXException If there is any other
1656:             *            problem fulfilling the request.
1657:             */
1658:            public void setProperty(String propertyId, Object value)
1659:                    throws SAXNotRecognizedException, SAXNotSupportedException {
1660:
1661:                //
1662:                // SAX2 Properties
1663:                //
1664:                String property;
1665:                if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
1666:                    property = propertyId.substring(SAX2_PROPERTIES_PREFIX
1667:                            .length());
1668:
1669:                    //
1670:                    // http://xml.org/sax/properties/namespace-sep
1671:                    // Value type: String
1672:                    // Access: read/write, pre-parse only
1673:                    //   Set the separator to be used between the URI part of a name and the
1674:                    //   local part of a name when namespace processing is being performed
1675:                    //   (see the http://xml.org/sax/features/namespaces feature).  By
1676:                    //   default, the separator is a single space.  This property may not be
1677:                    //   set while a parse is in progress (throws a SAXNotSupportedException).
1678:                    //
1679:                    /***
1680:                    if (property.equals("namespace-sep")) {
1681:                        try {
1682:                            setNamespaceSep((String)value);
1683:                        }
1684:                        catch (ClassCastException e) {
1685:                            throw new SAXNotSupportedException(propertyId);
1686:                        }
1687:                        return;
1688:                    }
1689:                    /***/
1690:
1691:                    //
1692:                    // http://xml.org/sax/properties/xml-string
1693:                    // Value type: String
1694:                    // Access: read-only
1695:                    //   Get the literal string of characters associated with the current
1696:                    //   event.  If the parser recognises and supports this property but is
1697:                    //   not currently parsing text, it should return null (this is a good
1698:                    //   way to check for availability before the parse begins).
1699:                    //
1700:                    if (property.equals("xml-string")) {
1701:                        // REVISIT - we should probably ask xml-dev for a precise definition
1702:                        // of what this is actually supposed to return, and in exactly which
1703:                        // circumstances.
1704:                        throw new SAXNotSupportedException(propertyId);
1705:                    }
1706:                    //
1707:                    // Not recognized
1708:                    //
1709:                }
1710:
1711:                //
1712:                // Xerces Properties
1713:                //
1714:
1715:                if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
1716:                    property = propertyId.substring(XERCES_PROPERTIES_PREFIX
1717:                            .length());
1718:
1719:                    if (property.equals("schema/external-schemaLocation")) {
1720:                        setExternalSchemaLocation(value);
1721:                        return;
1722:                    } else if (property
1723:                            .equals("schema/external-noNamespaceSchemaLocation")) {
1724:                        setExternalNoNamespaceSchemaLocation(value);
1725:                        return;
1726:                    }
1727:
1728:                }
1729:
1730:                //
1731:                // Not recognized
1732:                //
1733:
1734:                throw new SAXNotRecognizedException(propertyId);
1735:
1736:            } // setProperty(String,Object)
1737:
1738:            /**
1739:             * Query the value of a property.
1740:             *
1741:             * Return the current value of a property in a SAX2 parser.
1742:             * The parser might not recognize the property.
1743:             *
1744:             * @param propertyId The unique identifier (URI) of the property
1745:             *                   being set.
1746:             * @return The current value of the property.
1747:             * @exception org.xml.sax.SAXNotRecognizedException If the
1748:             *            requested property is not known.
1749:             * @exception org.xml.sax.SAXException If there is any other
1750:             *            problem fulfilling the request.
1751:             * @see org.xml.sax.XMLReader#getProperty
1752:             */
1753:            public Object getProperty(String propertyId)
1754:                    throws SAXNotRecognizedException, SAXNotSupportedException {
1755:
1756:                //
1757:                // SAX2 Properties
1758:                //
1759:
1760:                if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
1761:                    String property = propertyId
1762:                            .substring(SAX2_PROPERTIES_PREFIX.length());
1763:                    //
1764:                    // http://xml.org/sax/properties/namespace-sep
1765:                    // Value type: String
1766:                    // Access: read/write, pre-parse only
1767:                    //   Set the separator to be used between the URI part of a name and the
1768:                    //   local part of a name when namespace processing is being performed
1769:                    //   (see the http://xml.org/sax/features/namespaces feature).  By
1770:                    //   default, the separator is a single space.  This property may not be
1771:                    //   set while a parse is in progress (throws a SAXNotSupportedException).
1772:                    //
1773:                    /***
1774:                    if (property.equals("namespace-sep")) {
1775:                        return getNamespaceSep();
1776:                    }
1777:                    /***/
1778:                    //
1779:                    // http://xml.org/sax/properties/xml-string
1780:                    // Value type: String
1781:                    // Access: read-only
1782:                    //   Get the literal string of characters associated with the current
1783:                    //   event.  If the parser recognises and supports this property but is
1784:                    //   not currently parsing text, it should return null (this is a good
1785:                    //   way to check for availability before the parse begins).
1786:                    //
1787:                    if (property.equals("xml-string")) {
1788:                        return getXMLString();
1789:                    }
1790:                    //
1791:                    // Not recognized
1792:                    //
1793:                }
1794:
1795:                //
1796:                // Xerces Properties
1797:                //
1798:
1799:                else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
1800:                    //
1801:                    // No properties defined yet that are common to all parsers.
1802:                    //
1803:
1804:                    String property = propertyId
1805:                            .substring(XERCES_PROPERTIES_PREFIX.length());
1806:                    //
1807:                    // http://apache.org/xml/features/validation/schema
1808:                    //   Lets the user turn Schema validation support on/off.
1809:                    //
1810:                    if (property.equals("schema/external-schemaLocation")) {
1811:                        return fValidator.getExternalSchemas();
1812:                    }
1813:                    if (property
1814:                            .equals("schema/external-noNamespaceSchemaLocation")) {
1815:                        return fValidator.getExternalNoNamespaceSchema();
1816:                    }
1817:                }
1818:
1819:                //
1820:                // Not recognized
1821:                //
1822:
1823:                throw new SAXNotRecognizedException(propertyId);
1824:
1825:            } // getProperty(String):Object
1826:
1827:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.