0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017:
0018: package org.apache.xerces.parsers;
0019:
0020: import java.io.IOException;
0021: import java.util.ArrayList;
0022: import java.util.HashMap;
0023: import java.util.Locale;
0024:
0025: import org.apache.xerces.impl.Constants;
0026: import org.apache.xerces.impl.XML11DTDScannerImpl;
0027: import org.apache.xerces.impl.XML11DocumentScannerImpl;
0028: import org.apache.xerces.impl.XML11NSDocumentScannerImpl;
0029: import org.apache.xerces.impl.XMLDTDScannerImpl;
0030: import org.apache.xerces.impl.XMLDocumentScannerImpl;
0031: import org.apache.xerces.impl.XMLEntityHandler;
0032: import org.apache.xerces.impl.XMLEntityManager;
0033: import org.apache.xerces.impl.XMLErrorReporter;
0034: import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
0035: import org.apache.xerces.impl.XMLVersionDetector;
0036: import org.apache.xerces.impl.dtd.XML11DTDProcessor;
0037: import org.apache.xerces.impl.dtd.XML11DTDValidator;
0038: import org.apache.xerces.impl.dtd.XML11NSDTDValidator;
0039: import org.apache.xerces.impl.dtd.XMLDTDProcessor;
0040: import org.apache.xerces.impl.dtd.XMLDTDValidator;
0041: import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
0042: import org.apache.xerces.impl.dv.DTDDVFactory;
0043: import org.apache.xerces.impl.msg.XMLMessageFormatter;
0044: import org.apache.xerces.impl.validation.ValidationManager;
0045: import org.apache.xerces.util.ParserConfigurationSettings;
0046: import org.apache.xerces.util.SymbolTable;
0047: import org.apache.xerces.xni.XMLDTDContentModelHandler;
0048: import org.apache.xerces.xni.XMLDTDHandler;
0049: import org.apache.xerces.xni.XMLDocumentHandler;
0050: import org.apache.xerces.xni.XMLLocator;
0051: import org.apache.xerces.xni.XNIException;
0052: import org.apache.xerces.xni.grammars.XMLGrammarPool;
0053: import org.apache.xerces.xni.parser.XMLComponent;
0054: import org.apache.xerces.xni.parser.XMLComponentManager;
0055: import org.apache.xerces.xni.parser.XMLConfigurationException;
0056: import org.apache.xerces.xni.parser.XMLDTDScanner;
0057: import org.apache.xerces.xni.parser.XMLDocumentScanner;
0058: import org.apache.xerces.xni.parser.XMLDocumentSource;
0059: import org.apache.xerces.xni.parser.XMLEntityResolver;
0060: import org.apache.xerces.xni.parser.XMLErrorHandler;
0061: import org.apache.xerces.xni.parser.XMLInputSource;
0062: import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
0063:
0064: /**
0065: * This class is the DTD-only parser configuration
0066: * used to parse XML 1.0 and XML 1.1 documents.
0067: *
0068: * <p>
0069: * This class recognizes the following features and properties:
0070: * <ul>
0071: * <li>Features
0072: * <ul>
0073: * <li>http://xml.org/sax/features/validation</li>
0074: * <li>http://xml.org/sax/features/namespaces</li>
0075: * <li>http://xml.org/sax/features/external-general-entities</li>
0076: * <li>http://xml.org/sax/features/external-parameter-entities</li>
0077: * <li>http://apache.org/xml/features/continue-after-fatal-error</li>
0078: * <li>http://apache.org/xml/features/load-external-dtd</li>
0079: * </ul>
0080: * <li>Properties
0081: * <ul>
0082: * <li>http://xml.org/sax/properties/xml-string</li>
0083: * <li>http://apache.org/xml/properties/internal/symbol-table</li>
0084: * <li>http://apache.org/xml/properties/internal/error-handler</li>
0085: * <li>http://apache.org/xml/properties/internal/entity-resolver</li>
0086: * <li>http://apache.org/xml/properties/internal/error-reporter</li>
0087: * <li>http://apache.org/xml/properties/internal/entity-manager</li>
0088: * <li>http://apache.org/xml/properties/internal/document-scanner</li>
0089: * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
0090: * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
0091: * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
0092: * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
0093: * </ul>
0094: * </ul>
0095: * @author Elena Litani, IBM
0096: * @author Neil Graham, IBM
0097: * @author Michael Glavassevich, IBM
0098: * @author John Kim, IBM
0099: *
0100: * @version $Id: XML11DTDConfiguration.java 447239 2006-09-18 05:08:26Z mrglavas $
0101: */
0102: public class XML11DTDConfiguration extends ParserConfigurationSettings
0103: implements XMLPullParserConfiguration, XML11Configurable {
0104:
0105: //
0106: // Constants
0107: //
0108: protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl";
0109:
0110: // feature identifiers
0111:
0112: /** Feature identifier: validation. */
0113: protected static final String VALIDATION = Constants.SAX_FEATURE_PREFIX
0114: + Constants.VALIDATION_FEATURE;
0115:
0116: /** Feature identifier: namespaces. */
0117: protected static final String NAMESPACES = Constants.SAX_FEATURE_PREFIX
0118: + Constants.NAMESPACES_FEATURE;
0119:
0120: /** Feature identifier: external general entities. */
0121: protected static final String EXTERNAL_GENERAL_ENTITIES = Constants.SAX_FEATURE_PREFIX
0122: + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE;
0123:
0124: /** Feature identifier: external parameter entities. */
0125: protected static final String EXTERNAL_PARAMETER_ENTITIES = Constants.SAX_FEATURE_PREFIX
0126: + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE;
0127:
0128: /** Feature identifier: continue after fatal error. */
0129: protected static final String CONTINUE_AFTER_FATAL_ERROR = Constants.XERCES_FEATURE_PREFIX
0130: + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
0131:
0132: /** Feature identifier: load external DTD. */
0133: protected static final String LOAD_EXTERNAL_DTD = Constants.XERCES_FEATURE_PREFIX
0134: + Constants.LOAD_EXTERNAL_DTD_FEATURE;
0135:
0136: // property identifiers
0137:
0138: /** Property identifier: xml string. */
0139: protected static final String XML_STRING = Constants.SAX_PROPERTY_PREFIX
0140: + Constants.XML_STRING_PROPERTY;
0141:
0142: /** Property identifier: symbol table. */
0143: protected static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX
0144: + Constants.SYMBOL_TABLE_PROPERTY;
0145:
0146: /** Property identifier: error handler. */
0147: protected static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX
0148: + Constants.ERROR_HANDLER_PROPERTY;
0149:
0150: /** Property identifier: entity resolver. */
0151: protected static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX
0152: + Constants.ENTITY_RESOLVER_PROPERTY;
0153:
0154: /** Property identifier: error reporter. */
0155: protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX
0156: + Constants.ERROR_REPORTER_PROPERTY;
0157:
0158: /** Property identifier: entity manager. */
0159: protected static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX
0160: + Constants.ENTITY_MANAGER_PROPERTY;
0161:
0162: /** Property identifier document scanner: */
0163: protected static final String DOCUMENT_SCANNER = Constants.XERCES_PROPERTY_PREFIX
0164: + Constants.DOCUMENT_SCANNER_PROPERTY;
0165:
0166: /** Property identifier: DTD scanner. */
0167: protected static final String DTD_SCANNER = Constants.XERCES_PROPERTY_PREFIX
0168: + Constants.DTD_SCANNER_PROPERTY;
0169:
0170: /** Property identifier: grammar pool. */
0171: protected static final String XMLGRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX
0172: + Constants.XMLGRAMMAR_POOL_PROPERTY;
0173:
0174: /** Property identifier: DTD loader. */
0175: protected static final String DTD_PROCESSOR = Constants.XERCES_PROPERTY_PREFIX
0176: + Constants.DTD_PROCESSOR_PROPERTY;
0177:
0178: /** Property identifier: DTD validator. */
0179: protected static final String DTD_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX
0180: + Constants.DTD_VALIDATOR_PROPERTY;
0181:
0182: /** Property identifier: namespace binder. */
0183: protected static final String NAMESPACE_BINDER = Constants.XERCES_PROPERTY_PREFIX
0184: + Constants.NAMESPACE_BINDER_PROPERTY;
0185:
0186: /** Property identifier: datatype validator factory. */
0187: protected static final String DATATYPE_VALIDATOR_FACTORY = Constants.XERCES_PROPERTY_PREFIX
0188: + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
0189:
0190: protected static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX
0191: + Constants.VALIDATION_MANAGER_PROPERTY;
0192:
0193: /** Property identifier: JAXP schema language / DOM schema-type. */
0194: protected static final String JAXP_SCHEMA_LANGUAGE = Constants.JAXP_PROPERTY_PREFIX
0195: + Constants.SCHEMA_LANGUAGE;
0196:
0197: /** Property identifier: JAXP schema source/ DOM schema-location. */
0198: protected static final String JAXP_SCHEMA_SOURCE = Constants.JAXP_PROPERTY_PREFIX
0199: + Constants.SCHEMA_SOURCE;
0200:
0201: // debugging
0202:
0203: /** Set to true and recompile to print exception stack trace. */
0204: protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
0205:
0206: //
0207: // Data
0208: //
0209: protected SymbolTable fSymbolTable;
0210: protected XMLInputSource fInputSource;
0211: protected ValidationManager fValidationManager;
0212: protected XMLVersionDetector fVersionDetector;
0213: protected XMLLocator fLocator;
0214: protected Locale fLocale;
0215:
0216: /** XML 1.0 Components. */
0217: protected ArrayList fComponents;
0218:
0219: /** XML 1.1. Components. */
0220: protected ArrayList fXML11Components = null;
0221:
0222: /** Common components: XMLEntityManager, XMLErrorReporter */
0223: protected ArrayList fCommonComponents = null;
0224:
0225: /** The document handler. */
0226: protected XMLDocumentHandler fDocumentHandler;
0227:
0228: /** The DTD handler. */
0229: protected XMLDTDHandler fDTDHandler;
0230:
0231: /** The DTD content model handler. */
0232: protected XMLDTDContentModelHandler fDTDContentModelHandler;
0233:
0234: /** Last component in the document pipeline */
0235: protected XMLDocumentSource fLastComponent;
0236:
0237: /**
0238: * True if a parse is in progress. This state is needed because
0239: * some features/properties cannot be set while parsing (e.g.
0240: * validation and namespaces).
0241: */
0242: protected boolean fParseInProgress = false;
0243:
0244: /**
0245: * fConfigUpdated is set to true if there has been any change to the configuration settings,
0246: * i.e a feature or a property was changed.
0247: */
0248: protected boolean fConfigUpdated = false;
0249:
0250: //
0251: // XML 1.0 components
0252: //
0253:
0254: /** The XML 1.0 Datatype validator factory. */
0255: protected DTDDVFactory fDatatypeValidatorFactory;
0256:
0257: /** The XML 1.0 Document scanner that does namespace binding. */
0258: protected XMLNSDocumentScannerImpl fNamespaceScanner;
0259:
0260: /** The XML 1.0 Non-namespace implementation of scanner */
0261: protected XMLDocumentScannerImpl fNonNSScanner;
0262:
0263: /** The XML 1.0 DTD Validator: binds namespaces */
0264: protected XMLDTDValidator fDTDValidator;
0265:
0266: /** The XML 1.0 DTD Validator that does not bind namespaces */
0267: protected XMLDTDValidator fNonNSDTDValidator;
0268:
0269: /** The XML 1.0 DTD scanner. */
0270: protected XMLDTDScanner fDTDScanner;
0271:
0272: /** The XML 1.0 DTD Processor . */
0273: protected XMLDTDProcessor fDTDProcessor;
0274:
0275: //
0276: // XML 1.1 components
0277: //
0278:
0279: /** The XML 1.1 datatype factory. **/
0280: protected DTDDVFactory fXML11DatatypeFactory = null;
0281:
0282: /** The XML 1.1 document scanner that does namespace binding. **/
0283: protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null;
0284:
0285: /** The XML 1.1 document scanner that does not do namespace binding. **/
0286: protected XML11DocumentScannerImpl fXML11DocScanner = null;
0287:
0288: /** The XML 1.1 DTD validator that does namespace binding. **/
0289: protected XML11NSDTDValidator fXML11NSDTDValidator = null;
0290:
0291: /** The XML 1.1 DTD validator that does not do namespace binding. **/
0292: protected XML11DTDValidator fXML11DTDValidator = null;
0293:
0294: /** The XML 1.1 DTD scanner. **/
0295: protected XML11DTDScannerImpl fXML11DTDScanner = null;
0296:
0297: /** The XML 1.1 DTD processor. **/
0298: protected XML11DTDProcessor fXML11DTDProcessor = null;
0299:
0300: //
0301: // Common components
0302: //
0303:
0304: /** Grammar pool. */
0305: protected XMLGrammarPool fGrammarPool;
0306:
0307: /** Error reporter. */
0308: protected XMLErrorReporter fErrorReporter;
0309:
0310: /** Entity manager. */
0311: protected XMLEntityManager fEntityManager;
0312:
0313: /** Current scanner */
0314: protected XMLDocumentScanner fCurrentScanner;
0315:
0316: /** Current Datatype validator factory. */
0317: protected DTDDVFactory fCurrentDVFactory;
0318:
0319: /** Current DTD scanner. */
0320: protected XMLDTDScanner fCurrentDTDScanner;
0321:
0322: /** Flag indiciating whether XML11 components have been initialized. */
0323: private boolean f11Initialized = false;
0324:
0325: //
0326: // Constructors
0327: //
0328:
0329: /** Default constructor. */
0330: public XML11DTDConfiguration() {
0331: this (null, null, null);
0332: } // <init>()
0333:
0334: /**
0335: * Constructs a parser configuration using the specified symbol table.
0336: *
0337: * @param symbolTable The symbol table to use.
0338: */
0339: public XML11DTDConfiguration(SymbolTable symbolTable) {
0340: this (symbolTable, null, null);
0341: } // <init>(SymbolTable)
0342:
0343: /**
0344: * Constructs a parser configuration using the specified symbol table and
0345: * grammar pool.
0346: * <p>
0347: * <strong>REVISIT:</strong>
0348: * Grammar pool will be updated when the new validation engine is
0349: * implemented.
0350: *
0351: * @param symbolTable The symbol table to use.
0352: * @param grammarPool The grammar pool to use.
0353: */
0354: public XML11DTDConfiguration(SymbolTable symbolTable,
0355: XMLGrammarPool grammarPool) {
0356: this (symbolTable, grammarPool, null);
0357: } // <init>(SymbolTable,XMLGrammarPool)
0358:
0359: /**
0360: * Constructs a parser configuration using the specified symbol table,
0361: * grammar pool, and parent settings.
0362: * <p>
0363: * <strong>REVISIT:</strong>
0364: * Grammar pool will be updated when the new validation engine is
0365: * implemented.
0366: *
0367: * @param symbolTable The symbol table to use.
0368: * @param grammarPool The grammar pool to use.
0369: * @param parentSettings The parent settings.
0370: */
0371: public XML11DTDConfiguration(SymbolTable symbolTable,
0372: XMLGrammarPool grammarPool,
0373: XMLComponentManager parentSettings) {
0374:
0375: super (parentSettings);
0376:
0377: // create a vector to hold all the components in use
0378: // XML 1.0 specialized components
0379: fComponents = new ArrayList();
0380: // XML 1.1 specialized components
0381: fXML11Components = new ArrayList();
0382: // Common components for XML 1.1. and XML 1.0
0383: fCommonComponents = new ArrayList();
0384:
0385: // create storage for recognized features and properties
0386: fRecognizedFeatures = new ArrayList();
0387: fRecognizedProperties = new ArrayList();
0388:
0389: // create table for features and properties
0390: fFeatures = new HashMap();
0391: fProperties = new HashMap();
0392:
0393: // add default recognized features
0394: final String[] recognizedFeatures = {
0395: CONTINUE_AFTER_FATAL_ERROR,
0396: LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
0397: VALIDATION, NAMESPACES, EXTERNAL_GENERAL_ENTITIES,
0398: EXTERNAL_PARAMETER_ENTITIES, PARSER_SETTINGS };
0399: addRecognizedFeatures(recognizedFeatures);
0400: // set state for default features
0401: fFeatures.put(VALIDATION, Boolean.FALSE);
0402: fFeatures.put(NAMESPACES, Boolean.TRUE);
0403: fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
0404: fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
0405: fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
0406: fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
0407: fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
0408:
0409: // add default recognized properties
0410: final String[] recognizedProperties = { SYMBOL_TABLE,
0411: ERROR_HANDLER, ENTITY_RESOLVER, ERROR_REPORTER,
0412: ENTITY_MANAGER, DOCUMENT_SCANNER, DTD_SCANNER,
0413: DTD_PROCESSOR, DTD_VALIDATOR,
0414: DATATYPE_VALIDATOR_FACTORY, VALIDATION_MANAGER,
0415: XML_STRING, XMLGRAMMAR_POOL, JAXP_SCHEMA_SOURCE,
0416: JAXP_SCHEMA_LANGUAGE };
0417: addRecognizedProperties(recognizedProperties);
0418:
0419: if (symbolTable == null) {
0420: symbolTable = new SymbolTable();
0421: }
0422: fSymbolTable = symbolTable;
0423: fProperties.put(SYMBOL_TABLE, fSymbolTable);
0424:
0425: fGrammarPool = grammarPool;
0426: if (fGrammarPool != null) {
0427: fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
0428: }
0429:
0430: fEntityManager = new XMLEntityManager();
0431: fProperties.put(ENTITY_MANAGER, fEntityManager);
0432: addCommonComponent(fEntityManager);
0433:
0434: fErrorReporter = new XMLErrorReporter();
0435: fErrorReporter.setDocumentLocator(fEntityManager
0436: .getEntityScanner());
0437: fProperties.put(ERROR_REPORTER, fErrorReporter);
0438: addCommonComponent(fErrorReporter);
0439:
0440: fNamespaceScanner = new XMLNSDocumentScannerImpl();
0441: fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
0442: addComponent((XMLComponent) fNamespaceScanner);
0443:
0444: fDTDScanner = new XMLDTDScannerImpl();
0445: fProperties.put(DTD_SCANNER, fDTDScanner);
0446: addComponent((XMLComponent) fDTDScanner);
0447:
0448: fDTDProcessor = new XMLDTDProcessor();
0449: fProperties.put(DTD_PROCESSOR, fDTDProcessor);
0450: addComponent((XMLComponent) fDTDProcessor);
0451:
0452: fDTDValidator = new XMLNSDTDValidator();
0453: fProperties.put(DTD_VALIDATOR, fDTDValidator);
0454: addComponent(fDTDValidator);
0455:
0456: fDatatypeValidatorFactory = DTDDVFactory.getInstance();
0457: fProperties.put(DATATYPE_VALIDATOR_FACTORY,
0458: fDatatypeValidatorFactory);
0459:
0460: fValidationManager = new ValidationManager();
0461: fProperties.put(VALIDATION_MANAGER, fValidationManager);
0462:
0463: fVersionDetector = new XMLVersionDetector();
0464:
0465: // add message formatters
0466: if (fErrorReporter
0467: .getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
0468: XMLMessageFormatter xmft = new XMLMessageFormatter();
0469: fErrorReporter.putMessageFormatter(
0470: XMLMessageFormatter.XML_DOMAIN, xmft);
0471: fErrorReporter.putMessageFormatter(
0472: XMLMessageFormatter.XMLNS_DOMAIN, xmft);
0473: }
0474:
0475: // set locale
0476: try {
0477: setLocale(Locale.getDefault());
0478: } catch (XNIException e) {
0479: // do nothing
0480: // REVISIT: What is the right thing to do? -Ac
0481: }
0482:
0483: fConfigUpdated = false;
0484:
0485: } // <init>(SymbolTable,XMLGrammarPool)
0486:
0487: //
0488: // Public methods
0489: //
0490: /**
0491: * Sets the input source for the document to parse.
0492: *
0493: * @param inputSource The document's input source.
0494: *
0495: * @exception XMLConfigurationException Thrown if there is a
0496: * configuration error when initializing the
0497: * parser.
0498: * @exception IOException Thrown on I/O error.
0499: *
0500: * @see #parse(boolean)
0501: */
0502: public void setInputSource(XMLInputSource inputSource)
0503: throws XMLConfigurationException, IOException {
0504:
0505: // REVISIT: this method used to reset all the components and
0506: // construct the pipeline. Now reset() is called
0507: // in parse (boolean) just before we parse the document
0508: // Should this method still throw exceptions..?
0509:
0510: fInputSource = inputSource;
0511:
0512: } // setInputSource(XMLInputSource)
0513:
0514: /**
0515: * Set the locale to use for messages.
0516: *
0517: * @param locale The locale object to use for localization of messages.
0518: *
0519: * @exception XNIException Thrown if the parser does not support the
0520: * specified locale.
0521: */
0522: public void setLocale(Locale locale) throws XNIException {
0523: fLocale = locale;
0524: fErrorReporter.setLocale(locale);
0525: } // setLocale(Locale)
0526:
0527: /**
0528: * Sets the document handler on the last component in the pipeline
0529: * to receive information about the document.
0530: *
0531: * @param documentHandler The document handler.
0532: */
0533: public void setDocumentHandler(XMLDocumentHandler documentHandler) {
0534: fDocumentHandler = documentHandler;
0535: if (fLastComponent != null) {
0536: fLastComponent.setDocumentHandler(fDocumentHandler);
0537: if (fDocumentHandler != null) {
0538: fDocumentHandler.setDocumentSource(fLastComponent);
0539: }
0540: }
0541: } // setDocumentHandler(XMLDocumentHandler)
0542:
0543: /** Returns the registered document handler. */
0544: public XMLDocumentHandler getDocumentHandler() {
0545: return fDocumentHandler;
0546: } // getDocumentHandler():XMLDocumentHandler
0547:
0548: /**
0549: * Sets the DTD handler.
0550: *
0551: * @param dtdHandler The DTD handler.
0552: */
0553: public void setDTDHandler(XMLDTDHandler dtdHandler) {
0554: fDTDHandler = dtdHandler;
0555: } // setDTDHandler(XMLDTDHandler)
0556:
0557: /** Returns the registered DTD handler. */
0558: public XMLDTDHandler getDTDHandler() {
0559: return fDTDHandler;
0560: } // getDTDHandler():XMLDTDHandler
0561:
0562: /**
0563: * Sets the DTD content model handler.
0564: *
0565: * @param handler The DTD content model handler.
0566: */
0567: public void setDTDContentModelHandler(
0568: XMLDTDContentModelHandler handler) {
0569: fDTDContentModelHandler = handler;
0570: } // setDTDContentModelHandler(XMLDTDContentModelHandler)
0571:
0572: /** Returns the registered DTD content model handler. */
0573: public XMLDTDContentModelHandler getDTDContentModelHandler() {
0574: return fDTDContentModelHandler;
0575: } // getDTDContentModelHandler():XMLDTDContentModelHandler
0576:
0577: /**
0578: * Sets the resolver used to resolve external entities. The EntityResolver
0579: * interface supports resolution of public and system identifiers.
0580: *
0581: * @param resolver The new entity resolver. Passing a null value will
0582: * uninstall the currently installed resolver.
0583: */
0584: public void setEntityResolver(XMLEntityResolver resolver) {
0585: fProperties.put(ENTITY_RESOLVER, resolver);
0586: } // setEntityResolver(XMLEntityResolver)
0587:
0588: /**
0589: * Return the current entity resolver.
0590: *
0591: * @return The current entity resolver, or null if none
0592: * has been registered.
0593: * @see #setEntityResolver
0594: */
0595: public XMLEntityResolver getEntityResolver() {
0596: return (XMLEntityResolver) fProperties.get(ENTITY_RESOLVER);
0597: } // getEntityResolver():XMLEntityResolver
0598:
0599: /**
0600: * Allow an application to register an error event handler.
0601: *
0602: * <p>If the application does not register an error handler, all
0603: * error events reported by the SAX parser will be silently
0604: * ignored; however, normal processing may not continue. It is
0605: * highly recommended that all SAX applications implement an
0606: * error handler to avoid unexpected bugs.</p>
0607: *
0608: * <p>Applications may register a new or different handler in the
0609: * middle of a parse, and the SAX parser must begin using the new
0610: * handler immediately.</p>
0611: *
0612: * @param errorHandler The error handler.
0613: * @exception java.lang.NullPointerException If the handler
0614: * argument is null.
0615: * @see #getErrorHandler
0616: */
0617: public void setErrorHandler(XMLErrorHandler errorHandler) {
0618: fProperties.put(ERROR_HANDLER, errorHandler);
0619: } // setErrorHandler(XMLErrorHandler)
0620:
0621: /**
0622: * Return the current error handler.
0623: *
0624: * @return The current error handler, or null if none
0625: * has been registered.
0626: * @see #setErrorHandler
0627: */
0628: public XMLErrorHandler getErrorHandler() {
0629: // REVISIT: Should this be a property?
0630: return (XMLErrorHandler) fProperties.get(ERROR_HANDLER);
0631: } // getErrorHandler():XMLErrorHandler
0632:
0633: /**
0634: * If the application decides to terminate parsing before the xml document
0635: * is fully parsed, the application should call this method to free any
0636: * resource allocated during parsing. For example, close all opened streams.
0637: */
0638: public void cleanup() {
0639: fEntityManager.closeReaders();
0640: }
0641:
0642: /**
0643: * Parses the specified input source.
0644: *
0645: * @param source The input source.
0646: *
0647: * @exception XNIException Throws exception on XNI error.
0648: * @exception java.io.IOException Throws exception on i/o error.
0649: */
0650: public void parse(XMLInputSource source) throws XNIException,
0651: IOException {
0652:
0653: if (fParseInProgress) {
0654: // REVISIT - need to add new error message
0655: throw new XNIException(
0656: "FWK005 parse may not be called while parsing.");
0657: }
0658: fParseInProgress = true;
0659:
0660: try {
0661: setInputSource(source);
0662: parse(true);
0663: } catch (XNIException ex) {
0664: if (PRINT_EXCEPTION_STACK_TRACE)
0665: ex.printStackTrace();
0666: throw ex;
0667: } catch (IOException ex) {
0668: if (PRINT_EXCEPTION_STACK_TRACE)
0669: ex.printStackTrace();
0670: throw ex;
0671: } catch (RuntimeException ex) {
0672: if (PRINT_EXCEPTION_STACK_TRACE)
0673: ex.printStackTrace();
0674: throw ex;
0675: } catch (Exception ex) {
0676: if (PRINT_EXCEPTION_STACK_TRACE)
0677: ex.printStackTrace();
0678: throw new XNIException(ex);
0679: } finally {
0680: fParseInProgress = false;
0681: // close all streams opened by xerces
0682: this .cleanup();
0683: }
0684:
0685: } // parse(InputSource)
0686:
0687: public boolean parse(boolean complete) throws XNIException,
0688: IOException {
0689: //
0690: // reset and configure pipeline and set InputSource.
0691: if (fInputSource != null) {
0692: try {
0693: fValidationManager.reset();
0694: fVersionDetector.reset(this );
0695: resetCommon();
0696:
0697: short version = fVersionDetector
0698: .determineDocVersion(fInputSource);
0699: // XML 1.0
0700: if (version == Constants.XML_VERSION_1_0) {
0701: configurePipeline();
0702: reset();
0703: }
0704: // XML 1.1
0705: else if (version == Constants.XML_VERSION_1_1) {
0706: initXML11Components();
0707: configureXML11Pipeline();
0708: resetXML11();
0709: }
0710: // Unrecoverable error reported during version detection
0711: else {
0712: return false;
0713: }
0714:
0715: // mark configuration as fixed
0716: fConfigUpdated = false;
0717:
0718: // resets and sets the pipeline.
0719: fVersionDetector.startDocumentParsing(
0720: (XMLEntityHandler) fCurrentScanner, version);
0721: fInputSource = null;
0722: } catch (XNIException ex) {
0723: if (PRINT_EXCEPTION_STACK_TRACE)
0724: ex.printStackTrace();
0725: throw ex;
0726: } catch (IOException ex) {
0727: if (PRINT_EXCEPTION_STACK_TRACE)
0728: ex.printStackTrace();
0729: throw ex;
0730: } catch (RuntimeException ex) {
0731: if (PRINT_EXCEPTION_STACK_TRACE)
0732: ex.printStackTrace();
0733: throw ex;
0734: } catch (Exception ex) {
0735: if (PRINT_EXCEPTION_STACK_TRACE)
0736: ex.printStackTrace();
0737: throw new XNIException(ex);
0738: }
0739: }
0740:
0741: try {
0742: return fCurrentScanner.scanDocument(complete);
0743: } catch (XNIException ex) {
0744: if (PRINT_EXCEPTION_STACK_TRACE)
0745: ex.printStackTrace();
0746: throw ex;
0747: } catch (IOException ex) {
0748: if (PRINT_EXCEPTION_STACK_TRACE)
0749: ex.printStackTrace();
0750: throw ex;
0751: } catch (RuntimeException ex) {
0752: if (PRINT_EXCEPTION_STACK_TRACE)
0753: ex.printStackTrace();
0754: throw ex;
0755: } catch (Exception ex) {
0756: if (PRINT_EXCEPTION_STACK_TRACE)
0757: ex.printStackTrace();
0758: throw new XNIException(ex);
0759: }
0760:
0761: } // parse(boolean):boolean
0762:
0763: /**
0764: * Returns the state of a feature.
0765: *
0766: * @param featureId The feature identifier.
0767: * @return true if the feature is supported
0768: *
0769: * @throws XMLConfigurationException Thrown for configuration error.
0770: * In general, components should
0771: * only throw this exception if
0772: * it is <strong>really</strong>
0773: * a critical error.
0774: */
0775: public boolean getFeature(String featureId)
0776: throws XMLConfigurationException {
0777: // make this feature special
0778: if (featureId.equals(PARSER_SETTINGS)) {
0779: return fConfigUpdated;
0780: }
0781: return super .getFeature(featureId);
0782:
0783: } // getFeature(String):boolean
0784:
0785: /**
0786: * Set the state of a feature.
0787: *
0788: * Set the state of any feature in a SAX2 parser. The parser
0789: * might not recognize the feature, and if it does recognize
0790: * it, it might not be able to fulfill the request.
0791: *
0792: * @param featureId The unique identifier (URI) of the feature.
0793: * @param state The requested state of the feature (true or false).
0794: *
0795: * @exception org.apache.xerces.xni.parser.XMLConfigurationException If the
0796: * requested feature is not known.
0797: */
0798: public void setFeature(String featureId, boolean state)
0799: throws XMLConfigurationException {
0800: fConfigUpdated = true;
0801: // forward to every XML 1.0 component
0802: int count = fComponents.size();
0803: for (int i = 0; i < count; i++) {
0804: XMLComponent c = (XMLComponent) fComponents.get(i);
0805: c.setFeature(featureId, state);
0806: }
0807: // forward it to common components
0808: count = fCommonComponents.size();
0809: for (int i = 0; i < count; i++) {
0810: XMLComponent c = (XMLComponent) fCommonComponents.get(i);
0811: c.setFeature(featureId, state);
0812: }
0813:
0814: // forward to every XML 1.1 component
0815: count = fXML11Components.size();
0816: for (int i = 0; i < count; i++) {
0817: XMLComponent c = (XMLComponent) fXML11Components.get(i);
0818: try {
0819: c.setFeature(featureId, state);
0820: } catch (Exception e) {
0821: // no op
0822: }
0823: }
0824: // save state if noone "objects"
0825: super .setFeature(featureId, state);
0826:
0827: } // setFeature(String,boolean)
0828:
0829: /**
0830: * setProperty
0831: *
0832: * @param propertyId
0833: * @param value
0834: */
0835: public void setProperty(String propertyId, Object value)
0836: throws XMLConfigurationException {
0837: fConfigUpdated = true;
0838: // forward to every XML 1.0 component
0839: int count = fComponents.size();
0840: for (int i = 0; i < count; i++) {
0841: XMLComponent c = (XMLComponent) fComponents.get(i);
0842: c.setProperty(propertyId, value);
0843: }
0844: // forward it to every common Component
0845: count = fCommonComponents.size();
0846: for (int i = 0; i < count; i++) {
0847: XMLComponent c = (XMLComponent) fCommonComponents.get(i);
0848: c.setProperty(propertyId, value);
0849: }
0850: // forward it to every XML 1.1 component
0851: count = fXML11Components.size();
0852: for (int i = 0; i < count; i++) {
0853: XMLComponent c = (XMLComponent) fXML11Components.get(i);
0854: try {
0855: c.setProperty(propertyId, value);
0856: } catch (Exception e) {
0857: // ignore it
0858: }
0859: }
0860:
0861: // store value if noone "objects"
0862: super .setProperty(propertyId, value);
0863:
0864: } // setProperty(String,Object)
0865:
0866: /** Returns the locale. */
0867: public Locale getLocale() {
0868: return fLocale;
0869: } // getLocale():Locale
0870:
0871: /**
0872: * reset all XML 1.0 components before parsing and namespace context
0873: */
0874: protected void reset() throws XNIException {
0875: int count = fComponents.size();
0876: for (int i = 0; i < count; i++) {
0877: XMLComponent c = (XMLComponent) fComponents.get(i);
0878: c.reset(this );
0879: }
0880:
0881: } // reset()
0882:
0883: /**
0884: * reset all common components before parsing
0885: */
0886: protected void resetCommon() throws XNIException {
0887: // reset common components
0888: int count = fCommonComponents.size();
0889: for (int i = 0; i < count; i++) {
0890: XMLComponent c = (XMLComponent) fCommonComponents.get(i);
0891: c.reset(this );
0892: }
0893:
0894: } // resetCommon()
0895:
0896: /**
0897: * reset all components before parsing and namespace context
0898: */
0899: protected void resetXML11() throws XNIException {
0900: // reset every component
0901: int count = fXML11Components.size();
0902: for (int i = 0; i < count; i++) {
0903: XMLComponent c = (XMLComponent) fXML11Components.get(i);
0904: c.reset(this );
0905: }
0906:
0907: } // resetXML11()
0908:
0909: /**
0910: * Configures the XML 1.1 pipeline.
0911: * Note: this method also resets the new XML11 components.
0912: */
0913: protected void configureXML11Pipeline() {
0914: if (fCurrentDVFactory != fXML11DatatypeFactory) {
0915: fCurrentDVFactory = fXML11DatatypeFactory;
0916: setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
0917: }
0918: if (fCurrentDTDScanner != fXML11DTDScanner) {
0919: fCurrentDTDScanner = fXML11DTDScanner;
0920: setProperty(DTD_SCANNER, fCurrentDTDScanner);
0921: setProperty(DTD_PROCESSOR, fXML11DTDProcessor);
0922: }
0923:
0924: fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
0925: fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
0926: fXML11DTDProcessor.setDTDHandler(fDTDHandler);
0927: if (fDTDHandler != null) {
0928: fDTDHandler.setDTDSource(fXML11DTDProcessor);
0929: }
0930:
0931: fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);
0932: fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);
0933: fXML11DTDProcessor
0934: .setDTDContentModelHandler(fDTDContentModelHandler);
0935: if (fDTDContentModelHandler != null) {
0936: fDTDContentModelHandler
0937: .setDTDContentModelSource(fXML11DTDProcessor);
0938: }
0939:
0940: // setup XML 1.1 document pipeline
0941: if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
0942: if (fCurrentScanner != fXML11NSDocScanner) {
0943: fCurrentScanner = fXML11NSDocScanner;
0944: setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);
0945: setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);
0946: }
0947:
0948: fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);
0949: fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);
0950: fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);
0951: fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);
0952:
0953: if (fDocumentHandler != null) {
0954: fDocumentHandler
0955: .setDocumentSource(fXML11NSDTDValidator);
0956: }
0957: fLastComponent = fXML11NSDTDValidator;
0958:
0959: } else {
0960: // create components
0961: if (fXML11DocScanner == null) {
0962: // non namespace document pipeline
0963: fXML11DocScanner = new XML11DocumentScannerImpl();
0964: addXML11Component(fXML11DocScanner);
0965: fXML11DTDValidator = new XML11DTDValidator();
0966: addXML11Component(fXML11DTDValidator);
0967: }
0968: if (fCurrentScanner != fXML11DocScanner) {
0969: fCurrentScanner = fXML11DocScanner;
0970: setProperty(DOCUMENT_SCANNER, fXML11DocScanner);
0971: setProperty(DTD_VALIDATOR, fXML11DTDValidator);
0972: }
0973: fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);
0974: fXML11DTDValidator.setDocumentSource(fXML11DocScanner);
0975: fXML11DTDValidator.setDocumentHandler(fDocumentHandler);
0976:
0977: if (fDocumentHandler != null) {
0978: fDocumentHandler.setDocumentSource(fXML11DTDValidator);
0979: }
0980: fLastComponent = fXML11DTDValidator;
0981: }
0982:
0983: } // configureXML11Pipeline()
0984:
0985: /** Configures the pipeline. */
0986: protected void configurePipeline() {
0987: if (fCurrentDVFactory != fDatatypeValidatorFactory) {
0988: fCurrentDVFactory = fDatatypeValidatorFactory;
0989: // use XML 1.0 datatype library
0990: setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
0991: }
0992:
0993: // setup DTD pipeline
0994: if (fCurrentDTDScanner != fDTDScanner) {
0995: fCurrentDTDScanner = fDTDScanner;
0996: setProperty(DTD_SCANNER, fCurrentDTDScanner);
0997: setProperty(DTD_PROCESSOR, fDTDProcessor);
0998: }
0999: fDTDScanner.setDTDHandler(fDTDProcessor);
1000: fDTDProcessor.setDTDSource(fDTDScanner);
1001: fDTDProcessor.setDTDHandler(fDTDHandler);
1002: if (fDTDHandler != null) {
1003: fDTDHandler.setDTDSource(fDTDProcessor);
1004: }
1005:
1006: fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
1007: fDTDProcessor.setDTDContentModelSource(fDTDScanner);
1008: fDTDProcessor
1009: .setDTDContentModelHandler(fDTDContentModelHandler);
1010: if (fDTDContentModelHandler != null) {
1011: fDTDContentModelHandler
1012: .setDTDContentModelSource(fDTDProcessor);
1013: }
1014:
1015: // setup document pipeline
1016: if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
1017: if (fCurrentScanner != fNamespaceScanner) {
1018: fCurrentScanner = fNamespaceScanner;
1019: setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
1020: setProperty(DTD_VALIDATOR, fDTDValidator);
1021: }
1022: fNamespaceScanner.setDTDValidator(fDTDValidator);
1023: fNamespaceScanner.setDocumentHandler(fDTDValidator);
1024: fDTDValidator.setDocumentSource(fNamespaceScanner);
1025: fDTDValidator.setDocumentHandler(fDocumentHandler);
1026: if (fDocumentHandler != null) {
1027: fDocumentHandler.setDocumentSource(fDTDValidator);
1028: }
1029: fLastComponent = fDTDValidator;
1030: } else {
1031: // create components
1032: if (fNonNSScanner == null) {
1033: fNonNSScanner = new XMLDocumentScannerImpl();
1034: fNonNSDTDValidator = new XMLDTDValidator();
1035: // add components
1036: addComponent((XMLComponent) fNonNSScanner);
1037: addComponent((XMLComponent) fNonNSDTDValidator);
1038: }
1039: if (fCurrentScanner != fNonNSScanner) {
1040: fCurrentScanner = fNonNSScanner;
1041: setProperty(DOCUMENT_SCANNER, fNonNSScanner);
1042: setProperty(DTD_VALIDATOR, fNonNSDTDValidator);
1043: }
1044:
1045: fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
1046: fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
1047: fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
1048: if (fDocumentHandler != null) {
1049: fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
1050: }
1051: fLastComponent = fNonNSDTDValidator;
1052: }
1053:
1054: } // configurePipeline()
1055:
1056: // features and properties
1057:
1058: /**
1059: * Check a feature. If feature is know and supported, this method simply
1060: * returns. Otherwise, the appropriate exception is thrown.
1061: *
1062: * @param featureId The unique identifier (URI) of the feature.
1063: *
1064: * @throws XMLConfigurationException Thrown for configuration error.
1065: * In general, components should
1066: * only throw this exception if
1067: * it is <strong>really</strong>
1068: * a critical error.
1069: */
1070: protected void checkFeature(String featureId)
1071: throws XMLConfigurationException {
1072:
1073: //
1074: // Xerces Features
1075: //
1076:
1077: if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
1078: final int suffixLength = featureId.length()
1079: - Constants.XERCES_FEATURE_PREFIX.length();
1080:
1081: //
1082: // http://apache.org/xml/features/validation/dynamic
1083: // Allows the parser to validate a document only when it
1084: // contains a grammar. Validation is turned on/off based
1085: // on each document instance, automatically.
1086: //
1087: if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE
1088: .length()
1089: && featureId
1090: .endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
1091: return;
1092: }
1093:
1094: //
1095: // http://apache.org/xml/features/validation/default-attribute-values
1096: //
1097: if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE
1098: .length()
1099: && featureId
1100: .endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
1101: // REVISIT
1102: short type = XMLConfigurationException.NOT_SUPPORTED;
1103: throw new XMLConfigurationException(type, featureId);
1104: }
1105: //
1106: // http://apache.org/xml/features/validation/default-attribute-values
1107: //
1108: if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE
1109: .length()
1110: && featureId
1111: .endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
1112: // REVISIT
1113: short type = XMLConfigurationException.NOT_SUPPORTED;
1114: throw new XMLConfigurationException(type, featureId);
1115: }
1116: //
1117: // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
1118: //
1119: if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE
1120: .length()
1121: && featureId
1122: .endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
1123: return;
1124: }
1125: //
1126: // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
1127: //
1128: if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE
1129: .length()
1130: && featureId
1131: .endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
1132: return;
1133: }
1134:
1135: //
1136: // http://apache.org/xml/features/validation/default-attribute-values
1137: //
1138: if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE
1139: .length()
1140: && featureId
1141: .endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
1142: short type = XMLConfigurationException.NOT_SUPPORTED;
1143: throw new XMLConfigurationException(type, featureId);
1144: }
1145:
1146: // special performance feature: only component manager is allowed to set it.
1147: if (suffixLength == Constants.PARSER_SETTINGS.length()
1148: && featureId.endsWith(Constants.PARSER_SETTINGS)) {
1149: short type = XMLConfigurationException.NOT_SUPPORTED;
1150: throw new XMLConfigurationException(type, featureId);
1151: }
1152: }
1153:
1154: //
1155: // Not recognized
1156: //
1157:
1158: super .checkFeature(featureId);
1159:
1160: } // checkFeature(String)
1161:
1162: /**
1163: * Check a property. If the property is know and supported, this method
1164: * simply returns. Otherwise, the appropriate exception is thrown.
1165: *
1166: * @param propertyId The unique identifier (URI) of the property
1167: * being set.
1168: *
1169: * @throws XMLConfigurationException Thrown for configuration error.
1170: * In general, components should
1171: * only throw this exception if
1172: * it is <strong>really</strong>
1173: * a critical error.
1174: */
1175: protected void checkProperty(String propertyId)
1176: throws XMLConfigurationException {
1177:
1178: //
1179: // Xerces Properties
1180: //
1181:
1182: if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
1183: final int suffixLength = propertyId.length()
1184: - Constants.XERCES_PROPERTY_PREFIX.length();
1185:
1186: if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length()
1187: && propertyId
1188: .endsWith(Constants.DTD_SCANNER_PROPERTY)) {
1189: return;
1190: }
1191: }
1192:
1193: // special cases
1194: if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1195: final int suffixLength = propertyId.length()
1196: - Constants.SAX_PROPERTY_PREFIX.length();
1197:
1198: //
1199: // http://xml.org/sax/properties/xml-string
1200: // Value type: String
1201: // Access: read-only
1202: // Get the literal string of characters associated with the
1203: // current event. If the parser recognises and supports this
1204: // property but is not currently parsing text, it should return
1205: // null (this is a good way to check for availability before the
1206: // parse begins).
1207: //
1208: if (suffixLength == Constants.XML_STRING_PROPERTY.length()
1209: && propertyId
1210: .endsWith(Constants.XML_STRING_PROPERTY)) {
1211: // REVISIT - we should probably ask xml-dev for a precise
1212: // definition of what this is actually supposed to return, and
1213: // in exactly which circumstances.
1214: short type = XMLConfigurationException.NOT_SUPPORTED;
1215: throw new XMLConfigurationException(type, propertyId);
1216: }
1217: }
1218:
1219: //
1220: // Not recognized
1221: //
1222:
1223: super .checkProperty(propertyId);
1224:
1225: } // checkProperty(String)
1226:
1227: /**
1228: * Adds a component to the parser configuration. This method will
1229: * also add all of the component's recognized features and properties
1230: * to the list of default recognized features and properties.
1231: *
1232: * @param component The component to add.
1233: */
1234: protected void addComponent(XMLComponent component) {
1235:
1236: // don't add a component more than once
1237: if (fComponents.contains(component)) {
1238: return;
1239: }
1240: fComponents.add(component);
1241: addRecognizedParamsAndSetDefaults(component);
1242:
1243: } // addComponent(XMLComponent)
1244:
1245: /**
1246: * Adds common component to the parser configuration. This method will
1247: * also add all of the component's recognized features and properties
1248: * to the list of default recognized features and properties.
1249: *
1250: * @param component The component to add.
1251: */
1252: protected void addCommonComponent(XMLComponent component) {
1253:
1254: // don't add a component more than once
1255: if (fCommonComponents.contains(component)) {
1256: return;
1257: }
1258: fCommonComponents.add(component);
1259: addRecognizedParamsAndSetDefaults(component);
1260:
1261: } // addCommonComponent(XMLComponent)
1262:
1263: /**
1264: * Adds an XML 1.1 component to the parser configuration. This method will
1265: * also add all of the component's recognized features and properties
1266: * to the list of default recognized features and properties.
1267: *
1268: * @param component The component to add.
1269: */
1270: protected void addXML11Component(XMLComponent component) {
1271:
1272: // don't add a component more than once
1273: if (fXML11Components.contains(component)) {
1274: return;
1275: }
1276: fXML11Components.add(component);
1277: addRecognizedParamsAndSetDefaults(component);
1278:
1279: } // addXML11Component(XMLComponent)
1280:
1281: /**
1282: * Adds all of the component's recognized features and properties
1283: * to the list of default recognized features and properties, and
1284: * sets default values on the configuration for features and
1285: * properties which were previously absent from the configuration.
1286: *
1287: * @param component The component whose recognized features
1288: * and properties will be added to the configuration
1289: */
1290: protected void addRecognizedParamsAndSetDefaults(
1291: XMLComponent component) {
1292:
1293: // register component's recognized features
1294: String[] recognizedFeatures = component.getRecognizedFeatures();
1295: addRecognizedFeatures(recognizedFeatures);
1296:
1297: // register component's recognized properties
1298: String[] recognizedProperties = component
1299: .getRecognizedProperties();
1300: addRecognizedProperties(recognizedProperties);
1301:
1302: // set default values
1303: if (recognizedFeatures != null) {
1304: for (int i = 0; i < recognizedFeatures.length; ++i) {
1305: String featureId = recognizedFeatures[i];
1306: Boolean state = component.getFeatureDefault(featureId);
1307: if (state != null) {
1308: // Do not overwrite values already set on the configuration.
1309: if (!fFeatures.containsKey(featureId)) {
1310: fFeatures.put(featureId, state);
1311: // For newly added components who recognize this feature
1312: // but did not offer a default value, we need to make
1313: // sure these components will get an opportunity to read
1314: // the value before parsing begins.
1315: fConfigUpdated = true;
1316: }
1317: }
1318: }
1319: }
1320: if (recognizedProperties != null) {
1321: for (int i = 0; i < recognizedProperties.length; ++i) {
1322: String propertyId = recognizedProperties[i];
1323: Object value = component.getPropertyDefault(propertyId);
1324: if (value != null) {
1325: // Do not overwrite values already set on the configuration.
1326: if (!fProperties.containsKey(propertyId)) {
1327: fProperties.put(propertyId, value);
1328: // For newly added components who recognize this property
1329: // but did not offer a default value, we need to make
1330: // sure these components will get an opportunity to read
1331: // the value before parsing begins.
1332: fConfigUpdated = true;
1333: }
1334: }
1335: }
1336: }
1337: }
1338:
1339: private void initXML11Components() {
1340: if (!f11Initialized) {
1341:
1342: // create datatype factory
1343: fXML11DatatypeFactory = DTDDVFactory
1344: .getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
1345:
1346: // setup XML 1.1 DTD pipeline
1347: fXML11DTDScanner = new XML11DTDScannerImpl();
1348: addXML11Component(fXML11DTDScanner);
1349: fXML11DTDProcessor = new XML11DTDProcessor();
1350: addXML11Component(fXML11DTDProcessor);
1351:
1352: // setup XML 1.1. document pipeline - namespace aware
1353: fXML11NSDocScanner = new XML11NSDocumentScannerImpl();
1354: addXML11Component(fXML11NSDocScanner);
1355: fXML11NSDTDValidator = new XML11NSDTDValidator();
1356: addXML11Component(fXML11NSDTDValidator);
1357:
1358: f11Initialized = true;
1359: }
1360: }
1361:
1362: } // class XML11DTDConfiguration
|