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.dom;
0019:
0020: import java.io.IOException;
0021: import java.util.ArrayList;
0022: import java.util.HashMap;
0023: import java.util.Locale;
0024: import java.util.StringTokenizer;
0025: import java.util.Vector;
0026:
0027: import org.w3c.dom.DOMConfiguration;
0028: import org.w3c.dom.DOMErrorHandler;
0029: import org.w3c.dom.DOMStringList;
0030:
0031: import org.apache.xerces.impl.Constants;
0032: import org.apache.xerces.impl.XMLEntityManager;
0033: import org.apache.xerces.impl.XMLErrorReporter;
0034: import org.apache.xerces.impl.dv.DTDDVFactory;
0035: import org.apache.xerces.impl.msg.XMLMessageFormatter;
0036: import org.apache.xerces.impl.validation.ValidationManager;
0037: import org.apache.xerces.util.DOMEntityResolverWrapper;
0038: import org.apache.xerces.util.DOMErrorHandlerWrapper;
0039: import org.apache.xerces.util.MessageFormatter;
0040: import org.apache.xerces.util.ParserConfigurationSettings;
0041: import org.apache.xerces.util.SymbolTable;
0042: import org.apache.xerces.xni.XMLDTDContentModelHandler;
0043: import org.apache.xerces.xni.XMLDTDHandler;
0044: import org.apache.xerces.xni.XMLDocumentHandler;
0045: import org.apache.xerces.xni.XNIException;
0046: import org.apache.xerces.xni.grammars.XMLGrammarPool;
0047: import org.apache.xerces.xni.parser.XMLComponent;
0048: import org.apache.xerces.xni.parser.XMLComponentManager;
0049: import org.apache.xerces.xni.parser.XMLConfigurationException;
0050: import org.apache.xerces.xni.parser.XMLEntityResolver;
0051: import org.apache.xerces.xni.parser.XMLErrorHandler;
0052: import org.apache.xerces.xni.parser.XMLInputSource;
0053: import org.apache.xerces.xni.parser.XMLParserConfiguration;
0054: import org.w3c.dom.DOMException;
0055: import org.w3c.dom.ls.LSResourceResolver;
0056:
0057: /**
0058: * Xerces implementation of DOMConfiguration that maintains a table of recognized parameters.
0059: *
0060: * @xerces.internal
0061: *
0062: * @author Elena Litani, IBM
0063: * @author Neeraj Bajaj, Sun Microsystems.
0064: * @version $Id: DOMConfigurationImpl.java 530107 2007-04-18 17:59:54Z mrglavas $
0065: */
0066: public class DOMConfigurationImpl extends ParserConfigurationSettings
0067: implements XMLParserConfiguration, DOMConfiguration {
0068:
0069: //
0070: // Constants
0071: //
0072:
0073: protected static final String XML11_DATATYPE_VALIDATOR_FACTORY = "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl";
0074:
0075: // feature identifiers
0076:
0077: /** Feature identifier: validation. */
0078: protected static final String XERCES_VALIDATION = Constants.SAX_FEATURE_PREFIX
0079: + Constants.VALIDATION_FEATURE;
0080:
0081: /** Feature identifier: namespaces. */
0082: protected static final String XERCES_NAMESPACES = Constants.SAX_FEATURE_PREFIX
0083: + Constants.NAMESPACES_FEATURE;
0084:
0085: protected static final String SCHEMA = Constants.XERCES_FEATURE_PREFIX
0086: + Constants.SCHEMA_VALIDATION_FEATURE;
0087:
0088: protected static final String SCHEMA_FULL_CHECKING = Constants.XERCES_FEATURE_PREFIX
0089: + Constants.SCHEMA_FULL_CHECKING;
0090:
0091: protected static final String DYNAMIC_VALIDATION = Constants.XERCES_FEATURE_PREFIX
0092: + Constants.DYNAMIC_VALIDATION_FEATURE;
0093:
0094: protected static final String NORMALIZE_DATA = Constants.XERCES_FEATURE_PREFIX
0095: + Constants.SCHEMA_NORMALIZED_VALUE;
0096:
0097: /** Feature identifier: send element default value via characters() */
0098: protected static final String SCHEMA_ELEMENT_DEFAULT = Constants.XERCES_FEATURE_PREFIX
0099: + Constants.SCHEMA_ELEMENT_DEFAULT;
0100:
0101: /** sending psvi in the pipeline */
0102: protected static final String SEND_PSVI = Constants.XERCES_FEATURE_PREFIX
0103: + Constants.SCHEMA_AUGMENT_PSVI;
0104:
0105: /** Feature: generate synthetic annotations */
0106: protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = Constants.XERCES_FEATURE_PREFIX
0107: + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;
0108:
0109: /** Feature identifier: validate annotations */
0110: protected static final String VALIDATE_ANNOTATIONS = Constants.XERCES_FEATURE_PREFIX
0111: + Constants.VALIDATE_ANNOTATIONS_FEATURE;
0112:
0113: /** Feature identifier: honour all schemaLocations */
0114: protected static final String HONOUR_ALL_SCHEMALOCATIONS = Constants.XERCES_FEATURE_PREFIX
0115: + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE;
0116:
0117: /** Feature identifier: use grammar pool only */
0118: protected static final String USE_GRAMMAR_POOL_ONLY = Constants.XERCES_FEATURE_PREFIX
0119: + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
0120:
0121: /** Feature identifier: load external DTD. */
0122: protected static final String DISALLOW_DOCTYPE_DECL_FEATURE = Constants.XERCES_FEATURE_PREFIX
0123: + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;
0124:
0125: /** Feature identifier: balance syntax trees. */
0126: protected static final String BALANCE_SYNTAX_TREES = Constants.XERCES_FEATURE_PREFIX
0127: + Constants.BALANCE_SYNTAX_TREES;
0128:
0129: /** Feature identifier: warn on duplicate attribute definition. */
0130: protected static final String WARN_ON_DUPLICATE_ATTDEF = Constants.XERCES_FEATURE_PREFIX
0131: + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
0132:
0133: // property identifiers
0134:
0135: /** Property identifier: entity manager. */
0136: protected static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX
0137: + Constants.ENTITY_MANAGER_PROPERTY;
0138:
0139: /** Property identifier: error reporter. */
0140: protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX
0141: + Constants.ERROR_REPORTER_PROPERTY;
0142:
0143: /** Property identifier: xml string. */
0144: protected static final String XML_STRING = Constants.SAX_PROPERTY_PREFIX
0145: + Constants.XML_STRING_PROPERTY;
0146:
0147: /** Property identifier: symbol table. */
0148: protected static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX
0149: + Constants.SYMBOL_TABLE_PROPERTY;
0150:
0151: /** Property id: Grammar pool*/
0152: protected static final String GRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX
0153: + Constants.XMLGRAMMAR_POOL_PROPERTY;
0154:
0155: /** Property identifier: error handler. */
0156: protected static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX
0157: + Constants.ERROR_HANDLER_PROPERTY;
0158:
0159: /** Property identifier: entity resolver. */
0160: protected static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX
0161: + Constants.ENTITY_RESOLVER_PROPERTY;
0162:
0163: /** Property identifier: JAXP schema language / DOM schema-type. */
0164: protected static final String JAXP_SCHEMA_LANGUAGE = Constants.JAXP_PROPERTY_PREFIX
0165: + Constants.SCHEMA_LANGUAGE;
0166:
0167: /** Property identifier: JAXP schema source/ DOM schema-location. */
0168: protected static final String JAXP_SCHEMA_SOURCE = Constants.JAXP_PROPERTY_PREFIX
0169: + Constants.SCHEMA_SOURCE;
0170:
0171: /** Property identifier: DTD validator. */
0172: protected final static String DTD_VALIDATOR_PROPERTY = Constants.XERCES_PROPERTY_PREFIX
0173: + Constants.DTD_VALIDATOR_PROPERTY;
0174:
0175: /** Property identifier: datatype validator factory. */
0176: protected static final String DTD_VALIDATOR_FACTORY_PROPERTY = Constants.XERCES_PROPERTY_PREFIX
0177: + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
0178:
0179: protected static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX
0180: + Constants.VALIDATION_MANAGER_PROPERTY;
0181:
0182: /** Property identifier: schema location. */
0183: protected static final String SCHEMA_LOCATION = Constants.XERCES_PROPERTY_PREFIX
0184: + Constants.SCHEMA_LOCATION;
0185:
0186: /** Property identifier: no namespace schema location. */
0187: protected static final String SCHEMA_NONS_LOCATION = Constants.XERCES_PROPERTY_PREFIX
0188: + Constants.SCHEMA_NONS_LOCATION;
0189:
0190: //
0191: // Data
0192: //
0193: XMLDocumentHandler fDocumentHandler;
0194:
0195: /** Normalization features*/
0196: protected short features = 0;
0197:
0198: protected final static short NAMESPACES = 0x1 << 0;
0199: protected final static short DTNORMALIZATION = 0x1 << 1;
0200: protected final static short ENTITIES = 0x1 << 2;
0201: protected final static short CDATA = 0x1 << 3;
0202: protected final static short SPLITCDATA = 0x1 << 4;
0203: protected final static short COMMENTS = 0x1 << 5;
0204: protected final static short VALIDATE = 0x1 << 6;
0205: protected final static short PSVI = 0x1 << 7;
0206: protected final static short WELLFORMED = 0x1 << 8;
0207: protected final static short NSDECL = 0x1 << 9;
0208:
0209: protected final static short INFOSET_TRUE_PARAMS = NAMESPACES
0210: | COMMENTS | WELLFORMED | NSDECL;
0211: protected final static short INFOSET_FALSE_PARAMS = ENTITIES
0212: | DTNORMALIZATION | CDATA;
0213: protected final static short INFOSET_MASK = INFOSET_TRUE_PARAMS
0214: | INFOSET_FALSE_PARAMS;
0215:
0216: // components
0217:
0218: /** Symbol table. */
0219: protected SymbolTable fSymbolTable;
0220:
0221: /** Components. */
0222: protected ArrayList fComponents;
0223:
0224: protected ValidationManager fValidationManager;
0225:
0226: /** Locale. */
0227: protected Locale fLocale;
0228:
0229: /** Error reporter */
0230: protected XMLErrorReporter fErrorReporter;
0231:
0232: protected final DOMErrorHandlerWrapper fErrorHandlerWrapper = new DOMErrorHandlerWrapper();
0233:
0234: /** Current Datatype validator factory. */
0235: protected DTDDVFactory fCurrentDVFactory;
0236:
0237: /** The XML 1.0 Datatype validator factory. */
0238: protected DTDDVFactory fDatatypeValidatorFactory;
0239:
0240: /** The XML 1.1 Datatype validator factory. **/
0241: protected DTDDVFactory fXML11DatatypeFactory;
0242:
0243: // private data
0244:
0245: private String fSchemaLocation = null;
0246: private DOMStringList fRecognizedParameters;
0247:
0248: //
0249: // Constructors
0250: //
0251:
0252: /** Default Constructor. */
0253: protected DOMConfigurationImpl() {
0254: this (null, null);
0255: } // <init>()
0256:
0257: /**
0258: * Constructs a parser configuration using the specified symbol table.
0259: *
0260: * @param symbolTable The symbol table to use.
0261: */
0262: protected DOMConfigurationImpl(SymbolTable symbolTable) {
0263: this (symbolTable, null);
0264: } // <init>(SymbolTable)
0265:
0266: /**
0267: * Constructs a parser configuration using the specified symbol table
0268: * and parent settings.
0269: *
0270: * @param symbolTable The symbol table to use.
0271: * @param parentSettings The parent settings.
0272: */
0273: protected DOMConfigurationImpl(SymbolTable symbolTable,
0274: XMLComponentManager parentSettings) {
0275: super (parentSettings);
0276:
0277: // create storage for recognized features and properties
0278: fRecognizedFeatures = new ArrayList();
0279: fRecognizedProperties = new ArrayList();
0280:
0281: // create table for features and properties
0282: fFeatures = new HashMap();
0283: fProperties = new HashMap();
0284:
0285: // add default recognized features
0286: final String[] recognizedFeatures = { XERCES_VALIDATION,
0287: XERCES_NAMESPACES, SCHEMA, SCHEMA_FULL_CHECKING,
0288: DYNAMIC_VALIDATION, NORMALIZE_DATA,
0289: SCHEMA_ELEMENT_DEFAULT, SEND_PSVI,
0290: GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS,
0291: HONOUR_ALL_SCHEMALOCATIONS, USE_GRAMMAR_POOL_ONLY,
0292: DISALLOW_DOCTYPE_DECL_FEATURE, BALANCE_SYNTAX_TREES,
0293: WARN_ON_DUPLICATE_ATTDEF, PARSER_SETTINGS };
0294: addRecognizedFeatures(recognizedFeatures);
0295:
0296: // set state for default features
0297: setFeature(XERCES_VALIDATION, false);
0298: setFeature(SCHEMA, false);
0299: setFeature(SCHEMA_FULL_CHECKING, false);
0300: setFeature(DYNAMIC_VALIDATION, false);
0301: setFeature(NORMALIZE_DATA, false);
0302: setFeature(SCHEMA_ELEMENT_DEFAULT, false);
0303: setFeature(XERCES_NAMESPACES, true);
0304: setFeature(SEND_PSVI, true);
0305: setFeature(GENERATE_SYNTHETIC_ANNOTATIONS, false);
0306: setFeature(VALIDATE_ANNOTATIONS, false);
0307: setFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
0308: setFeature(USE_GRAMMAR_POOL_ONLY, false);
0309: setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, false);
0310: setFeature(BALANCE_SYNTAX_TREES, false);
0311: setFeature(WARN_ON_DUPLICATE_ATTDEF, false);
0312: setFeature(PARSER_SETTINGS, true);
0313:
0314: // add default recognized properties
0315: final String[] recognizedProperties = { XML_STRING,
0316: SYMBOL_TABLE, ERROR_HANDLER, ENTITY_RESOLVER,
0317: ERROR_REPORTER, ENTITY_MANAGER, VALIDATION_MANAGER,
0318: GRAMMAR_POOL, JAXP_SCHEMA_SOURCE, JAXP_SCHEMA_LANGUAGE,
0319: SCHEMA_LOCATION, SCHEMA_NONS_LOCATION,
0320: DTD_VALIDATOR_PROPERTY, DTD_VALIDATOR_FACTORY_PROPERTY };
0321: addRecognizedProperties(recognizedProperties);
0322:
0323: // set default values for normalization features
0324: features |= NAMESPACES;
0325: features |= ENTITIES;
0326: features |= COMMENTS;
0327: features |= CDATA;
0328: features |= SPLITCDATA;
0329: features |= WELLFORMED;
0330: features |= NSDECL;
0331:
0332: if (symbolTable == null) {
0333: symbolTable = new SymbolTable();
0334: }
0335: fSymbolTable = symbolTable;
0336:
0337: fComponents = new ArrayList();
0338:
0339: setProperty(SYMBOL_TABLE, fSymbolTable);
0340: fErrorReporter = new XMLErrorReporter();
0341: setProperty(ERROR_REPORTER, fErrorReporter);
0342: addComponent(fErrorReporter);
0343:
0344: fDatatypeValidatorFactory = DTDDVFactory.getInstance();
0345: fXML11DatatypeFactory = DTDDVFactory
0346: .getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
0347: fCurrentDVFactory = fDatatypeValidatorFactory;
0348: setProperty(DTD_VALIDATOR_FACTORY_PROPERTY, fCurrentDVFactory);
0349:
0350: XMLEntityManager manager = new XMLEntityManager();
0351: setProperty(ENTITY_MANAGER, manager);
0352: addComponent(manager);
0353:
0354: fValidationManager = createValidationManager();
0355: setProperty(VALIDATION_MANAGER, fValidationManager);
0356:
0357: // add message formatters
0358: if (fErrorReporter
0359: .getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
0360: XMLMessageFormatter xmft = new XMLMessageFormatter();
0361: fErrorReporter.putMessageFormatter(
0362: XMLMessageFormatter.XML_DOMAIN, xmft);
0363: fErrorReporter.putMessageFormatter(
0364: XMLMessageFormatter.XMLNS_DOMAIN, xmft);
0365: }
0366:
0367: // REVISIT: try to include XML Schema formatter.
0368: // This is a hack to allow DTD configuration to be build.
0369: //
0370: if (fErrorReporter
0371: .getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) {
0372: MessageFormatter xmft = null;
0373: try {
0374: xmft = (MessageFormatter) (ObjectFactory.newInstance(
0375: "org.apache.xerces.impl.xs.XSMessageFormatter",
0376: ObjectFactory.findClassLoader(), true));
0377: } catch (Exception exception) {
0378: }
0379:
0380: if (xmft != null) {
0381: fErrorReporter.putMessageFormatter(
0382: "http://www.w3.org/TR/xml-schema-1", xmft);
0383: }
0384: }
0385:
0386: // set locale
0387: try {
0388: setLocale(Locale.getDefault());
0389: } catch (XNIException e) {
0390: // do nothing
0391: // REVISIT: What is the right thing to do? -Ac
0392: }
0393:
0394: } // <init>(SymbolTable)
0395:
0396: //
0397: // XMLParserConfiguration methods
0398: //
0399:
0400: /**
0401: * Parse an XML document.
0402: * <p>
0403: * The parser can use this method to instruct this configuration
0404: * to begin parsing an XML document from any valid input source
0405: * (a character stream, a byte stream, or a URI).
0406: * <p>
0407: * Parsers may not invoke this method while a parse is in progress.
0408: * Once a parse is complete, the parser may then parse another XML
0409: * document.
0410: * <p>
0411: * This method is synchronous: it will not return until parsing
0412: * has ended. If a client application wants to terminate
0413: * parsing early, it should throw an exception.
0414: *
0415: * @param inputSource The input source for the top-level of the
0416: * XML document.
0417: *
0418: * @exception XNIException Any XNI exception, possibly wrapping
0419: * another exception.
0420: * @exception IOException An IO exception from the parser, possibly
0421: * from a byte stream or character stream
0422: * supplied by the parser.
0423: */
0424: public void parse(XMLInputSource inputSource) throws XNIException,
0425: IOException {
0426: // no-op
0427: }
0428:
0429: /**
0430: * Sets the document handler on the last component in the pipeline
0431: * to receive information about the document.
0432: *
0433: * @param documentHandler The document handler.
0434: */
0435: public void setDocumentHandler(XMLDocumentHandler documentHandler) {
0436: fDocumentHandler = documentHandler;
0437: } // setDocumentHandler(XMLDocumentHandler)
0438:
0439: /** Returns the registered document handler. */
0440: public XMLDocumentHandler getDocumentHandler() {
0441: return fDocumentHandler;
0442: } // getDocumentHandler():XMLDocumentHandler
0443:
0444: /**
0445: * Sets the DTD handler.
0446: *
0447: * @param dtdHandler The DTD handler.
0448: */
0449: public void setDTDHandler(XMLDTDHandler dtdHandler) {
0450: //no-op
0451: } // setDTDHandler(XMLDTDHandler)
0452:
0453: /** Returns the registered DTD handler. */
0454: public XMLDTDHandler getDTDHandler() {
0455: return null;
0456: } // getDTDHandler():XMLDTDHandler
0457:
0458: /**
0459: * Sets the DTD content model handler.
0460: *
0461: * @param handler The DTD content model handler.
0462: */
0463: public void setDTDContentModelHandler(
0464: XMLDTDContentModelHandler handler) {
0465: //no-op
0466:
0467: } // setDTDContentModelHandler(XMLDTDContentModelHandler)
0468:
0469: /** Returns the registered DTD content model handler. */
0470: public XMLDTDContentModelHandler getDTDContentModelHandler() {
0471: return null;
0472: } // getDTDContentModelHandler():XMLDTDContentModelHandler
0473:
0474: /**
0475: * Sets the resolver used to resolve external entities. The EntityResolver
0476: * interface supports resolution of public and system identifiers.
0477: *
0478: * @param resolver The new entity resolver. Passing a null value will
0479: * uninstall the currently installed resolver.
0480: */
0481: public void setEntityResolver(XMLEntityResolver resolver) {
0482: fProperties.put(ENTITY_RESOLVER, resolver);
0483: } // setEntityResolver(XMLEntityResolver)
0484:
0485: /**
0486: * Return the current entity resolver.
0487: *
0488: * @return The current entity resolver, or null if none
0489: * has been registered.
0490: * @see #setEntityResolver
0491: */
0492: public XMLEntityResolver getEntityResolver() {
0493: return (XMLEntityResolver) fProperties.get(ENTITY_RESOLVER);
0494: } // getEntityResolver():XMLEntityResolver
0495:
0496: /**
0497: * Allow an application to register an error event handler.
0498: *
0499: * <p>If the application does not register an error handler, all
0500: * error events reported by the SAX parser will be silently
0501: * ignored; however, normal processing may not continue. It is
0502: * highly recommended that all SAX applications implement an
0503: * error handler to avoid unexpected bugs.</p>
0504: *
0505: * <p>Applications may register a new or different handler in the
0506: * middle of a parse, and the SAX parser must begin using the new
0507: * handler immediately.</p>
0508: *
0509: * @param errorHandler The error handler.
0510: * @exception java.lang.NullPointerException If the handler
0511: * argument is null.
0512: * @see #getErrorHandler
0513: */
0514: public void setErrorHandler(XMLErrorHandler errorHandler) {
0515: if (errorHandler != null) {
0516: fProperties.put(ERROR_HANDLER, errorHandler);
0517: }
0518: } // setErrorHandler(XMLErrorHandler)
0519:
0520: /**
0521: * Return the current error handler.
0522: *
0523: * @return The current error handler, or null if none
0524: * has been registered.
0525: * @see #setErrorHandler
0526: */
0527: public XMLErrorHandler getErrorHandler() {
0528: return (XMLErrorHandler) fProperties.get(ERROR_HANDLER);
0529: } // getErrorHandler():XMLErrorHandler
0530:
0531: /**
0532: * Returns the state of a feature.
0533: *
0534: * @param featureId The feature identifier.
0535: * @return true if the feature is supported
0536: *
0537: * @throws XMLConfigurationException Thrown for configuration error.
0538: * In general, components should
0539: * only throw this exception if
0540: * it is <strong>really</strong>
0541: * a critical error.
0542: */
0543: public boolean getFeature(String featureId)
0544: throws XMLConfigurationException {
0545: if (featureId.equals(PARSER_SETTINGS)) {
0546: return true;
0547: }
0548: return super .getFeature(featureId);
0549: }
0550:
0551: /**
0552: * Set the state of a feature.
0553: *
0554: * Set the state of any feature in a SAX2 parser. The parser
0555: * might not recognize the feature, and if it does recognize
0556: * it, it might not be able to fulfill the request.
0557: *
0558: * @param featureId The unique identifier (URI) of the feature.
0559: * @param state The requested state of the feature (true or false).
0560: *
0561: * @exception org.apache.xerces.xni.parser.XMLConfigurationException If the
0562: * requested feature is not known.
0563: */
0564: public void setFeature(String featureId, boolean state)
0565: throws XMLConfigurationException {
0566:
0567: // save state if noone "objects"
0568: super .setFeature(featureId, state);
0569:
0570: } // setFeature(String,boolean)
0571:
0572: /**
0573: * setProperty
0574: *
0575: * @param propertyId
0576: * @param value
0577: */
0578: public void setProperty(String propertyId, Object value)
0579: throws XMLConfigurationException {
0580:
0581: // store value if noone "objects"
0582: super .setProperty(propertyId, value);
0583:
0584: } // setProperty(String,Object)
0585:
0586: /**
0587: * Set the locale to use for messages.
0588: *
0589: * @param locale The locale object to use for localization of messages.
0590: *
0591: * @exception XNIException Thrown if the parser does not support the
0592: * specified locale.
0593: */
0594: public void setLocale(Locale locale) throws XNIException {
0595: fLocale = locale;
0596: fErrorReporter.setLocale(locale);
0597:
0598: } // setLocale(Locale)
0599:
0600: /** Returns the locale. */
0601: public Locale getLocale() {
0602: return fLocale;
0603: } // getLocale():Locale
0604:
0605: /**
0606: * DOM Level 3 WD - Experimental.
0607: * setParameter
0608: */
0609: public void setParameter(String name, Object value)
0610: throws DOMException {
0611: boolean found = true;
0612:
0613: // REVISIT: Recognizes DOM L3 default features only.
0614: // Does not yet recognize Xerces features.
0615: if (value instanceof Boolean) {
0616: boolean state = ((Boolean) value).booleanValue();
0617:
0618: if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
0619: features = (short) (state ? features | COMMENTS
0620: : features & ~COMMENTS);
0621: } else if (name
0622: .equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
0623: setFeature(NORMALIZE_DATA, state);
0624: features = (short) (state ? features | DTNORMALIZATION
0625: : features & ~DTNORMALIZATION);
0626: if (state) {
0627: features = (short) (features | VALIDATE);
0628: }
0629: } else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
0630: features = (short) (state ? features | NAMESPACES
0631: : features & ~NAMESPACES);
0632: } else if (name
0633: .equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
0634: features = (short) (state ? features | CDATA : features
0635: & ~CDATA);
0636: } else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
0637: features = (short) (state ? features | ENTITIES
0638: : features & ~ENTITIES);
0639: } else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) {
0640: features = (short) (state ? features | SPLITCDATA
0641: : features & ~SPLITCDATA);
0642: } else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
0643: features = (short) (state ? features | VALIDATE
0644: : features & ~VALIDATE);
0645: } else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) {
0646: features = (short) (state ? features | WELLFORMED
0647: : features & ~WELLFORMED);
0648: } else if (name
0649: .equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
0650: features = (short) (state ? features | NSDECL
0651: : features & ~NSDECL);
0652: } else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
0653: // Setting to false has no effect.
0654: if (state) {
0655: features = (short) (features | INFOSET_TRUE_PARAMS);
0656: features = (short) (features & ~INFOSET_FALSE_PARAMS);
0657: setFeature(NORMALIZE_DATA, false);
0658: }
0659: } else if (name
0660: .equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
0661: || name
0662: .equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
0663: || name
0664: .equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
0665: || name
0666: .equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)) {
0667: if (state) { // true is not supported
0668: String msg = DOMMessageFormatter.formatMessage(
0669: DOMMessageFormatter.DOM_DOMAIN,
0670: "FEATURE_NOT_SUPPORTED",
0671: new Object[] { name });
0672: throw new DOMException(
0673: DOMException.NOT_SUPPORTED_ERR, msg);
0674: }
0675: } else if (name
0676: .equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
0677: if (!state) { // false is not supported
0678: String msg = DOMMessageFormatter.formatMessage(
0679: DOMMessageFormatter.DOM_DOMAIN,
0680: "FEATURE_NOT_SUPPORTED",
0681: new Object[] { name });
0682: throw new DOMException(
0683: DOMException.NOT_SUPPORTED_ERR, msg);
0684: }
0685: } else if (name.equalsIgnoreCase(SEND_PSVI)) {
0686: // REVISIT: turning augmentation of PSVI is not support,
0687: // because in this case we won't be able to retrieve element
0688: // default value.
0689: if (!state) { // false is not supported
0690: String msg = DOMMessageFormatter.formatMessage(
0691: DOMMessageFormatter.DOM_DOMAIN,
0692: "FEATURE_NOT_SUPPORTED",
0693: new Object[] { name });
0694: throw new DOMException(
0695: DOMException.NOT_SUPPORTED_ERR, msg);
0696: }
0697: } else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
0698: features = (short) (state ? features | PSVI : features
0699: & ~PSVI);
0700: } else {
0701: found = false;
0702: /*
0703: String msg =
0704: DOMMessageFormatter.formatMessage(
0705: DOMMessageFormatter.DOM_DOMAIN,
0706: "FEATURE_NOT_FOUND",
0707: new Object[] { name });
0708: throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
0709: */
0710: }
0711:
0712: }
0713:
0714: if (!found || !(value instanceof Boolean)) { // set properties
0715: found = true;
0716:
0717: if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
0718: if (value instanceof DOMErrorHandler || value == null) {
0719: fErrorHandlerWrapper
0720: .setErrorHandler((DOMErrorHandler) value);
0721: setErrorHandler(fErrorHandlerWrapper);
0722: }
0723:
0724: else {
0725: // REVISIT: type mismatch
0726: String msg = DOMMessageFormatter.formatMessage(
0727: DOMMessageFormatter.DOM_DOMAIN,
0728: "TYPE_MISMATCH_ERR", new Object[] { name });
0729: throw new DOMException(
0730: DOMException.TYPE_MISMATCH_ERR, msg);
0731: }
0732: } else if (name
0733: .equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
0734: if (value instanceof LSResourceResolver
0735: || value == null) {
0736: try {
0737: setEntityResolver(new DOMEntityResolverWrapper(
0738: (LSResourceResolver) value));
0739: } catch (XMLConfigurationException e) {
0740: }
0741: } else {
0742: // REVISIT: type mismatch
0743: String msg = DOMMessageFormatter.formatMessage(
0744: DOMMessageFormatter.DOM_DOMAIN,
0745: "TYPE_MISMATCH_ERR", new Object[] { name });
0746: throw new DOMException(
0747: DOMException.TYPE_MISMATCH_ERR, msg);
0748: }
0749:
0750: } else if (name
0751: .equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
0752: if (value instanceof String || value == null) {
0753: try {
0754: if (value == null) {
0755: fSchemaLocation = null;
0756: setProperty(Constants.JAXP_PROPERTY_PREFIX
0757: + Constants.SCHEMA_SOURCE, null);
0758: } else {
0759: fSchemaLocation = (String) value;
0760: // map DOM schema-location to JAXP schemaSource property
0761: // tokenize location string
0762: StringTokenizer t = new StringTokenizer(
0763: fSchemaLocation, " \n\t\r");
0764: if (t.hasMoreTokens()) {
0765: ArrayList locations = new ArrayList();
0766: locations.add(t.nextToken());
0767: while (t.hasMoreTokens()) {
0768: locations.add(t.nextToken());
0769: }
0770: setProperty(
0771: Constants.JAXP_PROPERTY_PREFIX
0772: + Constants.SCHEMA_SOURCE,
0773: locations
0774: .toArray(new String[locations
0775: .size()]));
0776: } else {
0777: setProperty(
0778: Constants.JAXP_PROPERTY_PREFIX
0779: + Constants.SCHEMA_SOURCE,
0780: new String[] { (String) value });
0781: }
0782: }
0783: } catch (XMLConfigurationException e) {
0784: }
0785: } else {
0786: // REVISIT: type mismatch
0787: String msg = DOMMessageFormatter.formatMessage(
0788: DOMMessageFormatter.DOM_DOMAIN,
0789: "TYPE_MISMATCH_ERR", new Object[] { name });
0790: throw new DOMException(
0791: DOMException.TYPE_MISMATCH_ERR, msg);
0792: }
0793:
0794: } else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
0795: if (value instanceof String || value == null) {
0796: try {
0797: if (value == null) {
0798: setProperty(Constants.JAXP_PROPERTY_PREFIX
0799: + Constants.SCHEMA_LANGUAGE, null);
0800: } else if (value.equals(Constants.NS_XMLSCHEMA)) {
0801: // REVISIT: when add support to DTD validation
0802: setProperty(Constants.JAXP_PROPERTY_PREFIX
0803: + Constants.SCHEMA_LANGUAGE,
0804: Constants.NS_XMLSCHEMA);
0805: } else if (value.equals(Constants.NS_DTD)) {
0806: // Added support for revalidation against DTDs
0807: setProperty(Constants.JAXP_PROPERTY_PREFIX
0808: + Constants.SCHEMA_LANGUAGE,
0809: Constants.NS_DTD);
0810: }
0811: } catch (XMLConfigurationException e) {
0812: }
0813: } else {
0814: String msg = DOMMessageFormatter.formatMessage(
0815: DOMMessageFormatter.DOM_DOMAIN,
0816: "TYPE_MISMATCH_ERR", new Object[] { name });
0817: throw new DOMException(
0818: DOMException.TYPE_MISMATCH_ERR, msg);
0819: }
0820:
0821: } else if (name.equalsIgnoreCase(ENTITY_RESOLVER)) {
0822: if (value instanceof XMLEntityResolver || value == null) {
0823: try {
0824: setEntityResolver((XMLEntityResolver) value);
0825: } catch (XMLConfigurationException e) {
0826: }
0827: } else {
0828: String msg = DOMMessageFormatter.formatMessage(
0829: DOMMessageFormatter.DOM_DOMAIN,
0830: "TYPE_MISMATCH_ERR", new Object[] { name });
0831: throw new DOMException(
0832: DOMException.TYPE_MISMATCH_ERR, msg);
0833: }
0834: } else if (name.equalsIgnoreCase(SYMBOL_TABLE)) {
0835: // Xerces Symbol Table
0836: if (value instanceof SymbolTable) {
0837: setProperty(SYMBOL_TABLE, value);
0838: } else {
0839: // REVISIT: type mismatch
0840: String msg = DOMMessageFormatter.formatMessage(
0841: DOMMessageFormatter.DOM_DOMAIN,
0842: "TYPE_MISMATCH_ERR", new Object[] { name });
0843: throw new DOMException(
0844: DOMException.TYPE_MISMATCH_ERR, msg);
0845: }
0846: } else if (name.equalsIgnoreCase(GRAMMAR_POOL)) {
0847: if (value instanceof XMLGrammarPool || value == null) {
0848: setProperty(GRAMMAR_POOL, value);
0849: } else {
0850: // REVISIT: type mismatch
0851: String msg = DOMMessageFormatter.formatMessage(
0852: DOMMessageFormatter.DOM_DOMAIN,
0853: "TYPE_MISMATCH_ERR", new Object[] { name });
0854: throw new DOMException(
0855: DOMException.TYPE_MISMATCH_ERR, msg);
0856: }
0857:
0858: } else {
0859: // REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
0860: //parameter is not recognized
0861: String msg = DOMMessageFormatter.formatMessage(
0862: DOMMessageFormatter.DOM_DOMAIN,
0863: "FEATURE_NOT_FOUND", new Object[] { name });
0864: throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
0865: }
0866: }
0867:
0868: }
0869:
0870: /**
0871: * DOM Level 3 WD - Experimental.
0872: * getParameter
0873: */
0874: public Object getParameter(String name) throws DOMException {
0875:
0876: // REVISIT: Recognizes DOM L3 default features only.
0877: // Does not yet recognize Xerces features.
0878:
0879: if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
0880: return ((features & COMMENTS) != 0) ? Boolean.TRUE
0881: : Boolean.FALSE;
0882: } else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
0883: return (features & NAMESPACES) != 0 ? Boolean.TRUE
0884: : Boolean.FALSE;
0885: } else if (name
0886: .equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
0887: // REVISIT: datatype-normalization only takes effect if validation is on
0888: return (features & DTNORMALIZATION) != 0 ? Boolean.TRUE
0889: : Boolean.FALSE;
0890: } else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
0891: return (features & CDATA) != 0 ? Boolean.TRUE
0892: : Boolean.FALSE;
0893: } else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
0894: return (features & ENTITIES) != 0 ? Boolean.TRUE
0895: : Boolean.FALSE;
0896: } else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) {
0897: return (features & SPLITCDATA) != 0 ? Boolean.TRUE
0898: : Boolean.FALSE;
0899: } else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
0900: return (features & VALIDATE) != 0 ? Boolean.TRUE
0901: : Boolean.FALSE;
0902: } else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) {
0903: return (features & WELLFORMED) != 0 ? Boolean.TRUE
0904: : Boolean.FALSE;
0905: } else if (name
0906: .equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
0907: return (features & NSDECL) != 0 ? Boolean.TRUE
0908: : Boolean.FALSE;
0909: } else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
0910: return (features & INFOSET_MASK) == INFOSET_TRUE_PARAMS ? Boolean.TRUE
0911: : Boolean.FALSE;
0912: } else if (name
0913: .equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
0914: || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
0915: || name
0916: .equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
0917: || name
0918: .equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)) {
0919: return Boolean.FALSE;
0920: } else if (name.equalsIgnoreCase(SEND_PSVI)) {
0921: return Boolean.TRUE;
0922: } else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
0923: return (features & PSVI) != 0 ? Boolean.TRUE
0924: : Boolean.FALSE;
0925: } else if (name
0926: .equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
0927: return Boolean.TRUE;
0928: } else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
0929: return fErrorHandlerWrapper.getErrorHandler();
0930: } else if (name
0931: .equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
0932: XMLEntityResolver entityResolver = getEntityResolver();
0933: if (entityResolver != null
0934: && entityResolver instanceof DOMEntityResolverWrapper) {
0935: return ((DOMEntityResolverWrapper) entityResolver)
0936: .getEntityResolver();
0937: }
0938: return null;
0939: } else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
0940: return getProperty(Constants.JAXP_PROPERTY_PREFIX
0941: + Constants.SCHEMA_LANGUAGE);
0942: } else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
0943: return fSchemaLocation;
0944: } else if (name.equalsIgnoreCase(ENTITY_RESOLVER)) {
0945: return getEntityResolver();
0946: } else if (name.equalsIgnoreCase(SYMBOL_TABLE)) {
0947: return getProperty(SYMBOL_TABLE);
0948: } else if (name.equalsIgnoreCase(GRAMMAR_POOL)) {
0949: return getProperty(GRAMMAR_POOL);
0950: } else {
0951: String msg = DOMMessageFormatter.formatMessage(
0952: DOMMessageFormatter.DOM_DOMAIN,
0953: "FEATURE_NOT_FOUND", new Object[] { name });
0954: throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
0955: }
0956:
0957: }
0958:
0959: /**
0960: * DOM Level 3 WD - Experimental.
0961: * Check if setting a parameter to a specific value is supported.
0962: *
0963: * @param name The name of the parameter to check.
0964: *
0965: * @param value An object. if null, the returned value is true.
0966: *
0967: * @return true if the parameter could be successfully set to the
0968: * specified value, or false if the parameter is not recognized or
0969: * the requested value is not supported. This does not change the
0970: * current value of the parameter itself.
0971: */
0972: public boolean canSetParameter(String name, Object value) {
0973:
0974: if (value == null) {
0975: //if null, the returned value is true.
0976: //REVISIT: I dont like this --- even for unrecognized parameter it would
0977: //return 'true'. I think it should return false in that case.
0978: // Application will be surprised to find that setParameter throws not
0979: //recognized exception when canSetParameter returns 'true' Then what is the use
0980: //of having canSetParameter ??? - nb.
0981: return true;
0982: }
0983: if (value instanceof Boolean) {
0984: //features whose parameter value can be set either 'true' or 'false'
0985: // or they accept any boolean value -- so we just need to check that
0986: // its a boolean value..
0987: if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)
0988: || name
0989: .equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)
0990: || name
0991: .equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)
0992: || name.equalsIgnoreCase(Constants.DOM_ENTITIES)
0993: || name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)
0994: || name.equalsIgnoreCase(Constants.DOM_NAMESPACES)
0995: || name.equalsIgnoreCase(Constants.DOM_VALIDATE)
0996: || name.equalsIgnoreCase(Constants.DOM_WELLFORMED)
0997: || name.equalsIgnoreCase(Constants.DOM_INFOSET)
0998: || name
0999: .equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
1000: return true;
1001: }//features whose parameter value can not be set to 'true'
1002: else if (name
1003: .equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
1004: || name
1005: .equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
1006: || name
1007: .equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
1008: || name
1009: .equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)) {
1010: return (value.equals(Boolean.TRUE)) ? false : true;
1011: }//features whose parameter value can not be set to 'false'
1012: else if (name
1013: .equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)
1014: || name.equalsIgnoreCase(SEND_PSVI)) {
1015: return (value.equals(Boolean.TRUE)) ? true : false;
1016: }// if name is not among the above listed above -- its not recognized. return false
1017: else {
1018: return false;
1019: }
1020: } else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
1021: return (value instanceof DOMErrorHandler) ? true : false;
1022: } else if (name
1023: .equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
1024: return (value instanceof LSResourceResolver) ? true : false;
1025: } else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
1026: return (value instanceof String) ? true : false;
1027: } else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
1028: // REVISIT: should null value be supported?
1029: // as of now we are only supporting W3C XML Schema and DTD.
1030: return ((value instanceof String) && (value
1031: .equals(Constants.NS_XMLSCHEMA) || value
1032: .equals(Constants.NS_DTD))) ? true : false;
1033: } else if (name.equalsIgnoreCase(ENTITY_RESOLVER)) {
1034: return (value instanceof XMLEntityResolver) ? true : false;
1035: } else if (name.equalsIgnoreCase(SYMBOL_TABLE)) {
1036: // Xerces Symbol Table
1037: return (value instanceof SymbolTable) ? true : false;
1038: } else if (name.equalsIgnoreCase(GRAMMAR_POOL)) {
1039: return (value instanceof XMLGrammarPool) ? true : false;
1040: } else {
1041: //false if the parameter is not recognized or the requested value is not supported.
1042: return false;
1043: }
1044:
1045: } //canSetParameter
1046:
1047: /**
1048: * DOM Level 3 CR - Experimental.
1049: *
1050: * The list of the parameters supported by this
1051: * <code>DOMConfiguration</code> object and for which at least one value
1052: * can be set by the application. Note that this list can also contain
1053: * parameter names defined outside this specification.
1054: */
1055: public DOMStringList getParameterNames() {
1056: if (fRecognizedParameters == null) {
1057: Vector parameters = new Vector();
1058:
1059: //Add DOM recognized parameters
1060: //REVISIT: Would have been nice to have a list of
1061: //recognized paramters.
1062: parameters.add(Constants.DOM_COMMENTS);
1063: parameters.add(Constants.DOM_DATATYPE_NORMALIZATION);
1064: parameters.add(Constants.DOM_CDATA_SECTIONS);
1065: parameters.add(Constants.DOM_ENTITIES);
1066: parameters.add(Constants.DOM_SPLIT_CDATA);
1067: parameters.add(Constants.DOM_NAMESPACES);
1068: parameters.add(Constants.DOM_VALIDATE);
1069:
1070: parameters.add(Constants.DOM_INFOSET);
1071: parameters.add(Constants.DOM_NORMALIZE_CHARACTERS);
1072: parameters.add(Constants.DOM_CANONICAL_FORM);
1073: parameters.add(Constants.DOM_VALIDATE_IF_SCHEMA);
1074: parameters.add(Constants.DOM_CHECK_CHAR_NORMALIZATION);
1075: parameters.add(Constants.DOM_WELLFORMED);
1076:
1077: parameters.add(Constants.DOM_NAMESPACE_DECLARATIONS);
1078: parameters.add(Constants.DOM_ELEMENT_CONTENT_WHITESPACE);
1079:
1080: parameters.add(Constants.DOM_ERROR_HANDLER);
1081: parameters.add(Constants.DOM_SCHEMA_TYPE);
1082: parameters.add(Constants.DOM_SCHEMA_LOCATION);
1083: parameters.add(Constants.DOM_RESOURCE_RESOLVER);
1084:
1085: //Add recognized xerces features and properties
1086: parameters.add(ENTITY_RESOLVER);
1087: parameters.add(GRAMMAR_POOL);
1088: parameters.add(SYMBOL_TABLE);
1089: parameters.add(SEND_PSVI);
1090:
1091: fRecognizedParameters = new DOMStringListImpl(parameters);
1092:
1093: }
1094:
1095: return fRecognizedParameters;
1096: }//getParameterNames
1097:
1098: //
1099: // Protected methods
1100: //
1101:
1102: /**
1103: * reset all components before parsing
1104: */
1105: protected void reset() throws XNIException {
1106:
1107: if (fValidationManager != null)
1108: fValidationManager.reset();
1109:
1110: int count = fComponents.size();
1111: for (int i = 0; i < count; i++) {
1112: XMLComponent c = (XMLComponent) fComponents.get(i);
1113: c.reset(this );
1114: }
1115:
1116: } // reset()
1117:
1118: /**
1119: * Check a property. If the property is known and supported, this method
1120: * simply returns. Otherwise, the appropriate exception is thrown.
1121: *
1122: * @param propertyId The unique identifier (URI) of the property
1123: * being set.
1124: * @exception org.apache.xerces.xni.parser.XMLConfigurationException If the
1125: * requested feature is not known or supported.
1126: */
1127: protected void checkProperty(String propertyId)
1128: throws XMLConfigurationException {
1129:
1130: // special cases
1131: if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1132: final int suffixLength = propertyId.length()
1133: - Constants.SAX_PROPERTY_PREFIX.length();
1134:
1135: //
1136: // http://xml.org/sax/properties/xml-string
1137: // Value type: String
1138: // Access: read-only
1139: // Get the literal string of characters associated with the
1140: // current event. If the parser recognises and supports this
1141: // property but is not currently parsing text, it should return
1142: // null (this is a good way to check for availability before the
1143: // parse begins).
1144: //
1145: if (suffixLength == Constants.XML_STRING_PROPERTY.length()
1146: && propertyId
1147: .endsWith(Constants.XML_STRING_PROPERTY)) {
1148: // REVISIT - we should probably ask xml-dev for a precise
1149: // definition of what this is actually supposed to return, and
1150: // in exactly which circumstances.
1151: short type = XMLConfigurationException.NOT_SUPPORTED;
1152: throw new XMLConfigurationException(type, propertyId);
1153: }
1154: }
1155:
1156: // check property
1157: super .checkProperty(propertyId);
1158:
1159: } // checkProperty(String)
1160:
1161: protected void addComponent(XMLComponent component) {
1162:
1163: // don't add a component more than once
1164: if (fComponents.contains(component)) {
1165: return;
1166: }
1167: fComponents.add(component);
1168:
1169: // register component's recognized features
1170: String[] recognizedFeatures = component.getRecognizedFeatures();
1171: addRecognizedFeatures(recognizedFeatures);
1172:
1173: // register component's recognized properties
1174: String[] recognizedProperties = component
1175: .getRecognizedProperties();
1176: addRecognizedProperties(recognizedProperties);
1177:
1178: } // addComponent(XMLComponent)
1179:
1180: protected ValidationManager createValidationManager() {
1181: return new ValidationManager();
1182: }
1183:
1184: protected final void setDTDValidatorFactory(String version) {
1185: if ("1.1".equals(version)) {
1186: if (fCurrentDVFactory != fXML11DatatypeFactory) {
1187: fCurrentDVFactory = fXML11DatatypeFactory;
1188: setProperty(DTD_VALIDATOR_FACTORY_PROPERTY,
1189: fCurrentDVFactory);
1190: }
1191: } else if (fCurrentDVFactory != fDatatypeValidatorFactory) {
1192: fCurrentDVFactory = fDatatypeValidatorFactory;
1193: setProperty(DTD_VALIDATOR_FACTORY_PROPERTY,
1194: fCurrentDVFactory);
1195: }
1196: }
1197:
1198: } // class XMLParser
|