saxparserimpl.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 432 行 · 第 1/2 页

JAVA
432
字号
        if (features != null) {            for (Enumeration e = features.keys(); e.hasMoreElements();) {                String feature = (String)e.nextElement();                boolean value = ((Boolean)features.get(feature)).booleanValue();				if(!feature.equals(Constants.FEATURE_SECURE_PROCESSING))                	xmlReader.setFeature(feature, value);            }        }    }        /**     * @deprecated     */    public org.xml.sax.Parser getParser() throws SAXException {        return xmlReader;    }    /**	  * <p>Reset this <code>DocumentBuilder</code> to its original configuration.</p>	  * 	  * <p><code>DocumentBuilder</code> is reset to the same state as when it was created with	  * {@link DocumentBuilderFactory#newDocumentBuilder()}.	  * <code>reset()</code> is designed to allow the reuse of existing <code>DocumentBuilder</code>s	  * thus saving resources associated with the creation of new <code>DocumentBuilder</code>s.</p>	  * 	  * <p>The reset <code>DocumentBuilder</code> is not guaranteed to have the same {@link EntityResolver} or {@link ErrorHandler}	  * <code>Object</code>s, e.g. {@link Object#equals(Object obj)}.  It is guaranteed to have a functionally equal	  * <code>EntityResolver</code> and <code>ErrorHandler</code>.</p>	  * 	  * @since 1.5	  */    public void reset(){        if(xmlReader != null){            try{                xmlReader.reset();                //set the object back to its factory settings                resetSettings();                            }            //xxx: underlying implementation reset throws XNIException what should we do in this case ?            //if there was any propery that is not being supported            //exception would have been thrown when setting it on the underlying implementation.            catch(XNIException ex){                //coninue.            }            catch(SAXException sax){}        }    }        /**     * Returns the XMLReader that is encapsulated by the implementation of     * this class.     */    public XMLReader getXMLReader() {        return xmlReader;    }    public boolean isNamespaceAware() {        try {            return xmlReader.getFeature(Constants.SAX_FEATURE_PREFIX +                                        Constants.NAMESPACES_FEATURE);        } catch (SAXException x) {            throw new IllegalStateException(x.getMessage());        }    }    public boolean isValidating() {        try {            return xmlReader.getFeature(Constants.SAX_FEATURE_PREFIX +                                        Constants.VALIDATION_FEATURE);        } catch (SAXException x) {            throw new IllegalStateException(x.getMessage());        }    }    /**     * Sets the particular property in the underlying implementation of      * org.xml.sax.XMLReader.     */    public void setProperty(String name, Object value)        throws SAXNotRecognizedException, SAXNotSupportedException    {        // the spec says if a schema is given via SAXParserFactory        // the JAXP 1.2 properties shouldn't be allowed. So        // reject them first.        if(grammar!=null) {            if (JAXP_SCHEMA_LANGUAGE.equals(name)            ||  JAXP_SCHEMA_SOURCE.equals(name)) {                throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(null, "schema-already-specified", null));            }        }                if (JAXP_SCHEMA_LANGUAGE.equals(name)) {            // JAXP 1.2 support                        if ( W3C_XML_SCHEMA.equals(value) ) {                //None of the properties will take effect till the setValidating(true) has been called                                                                        if( isValidating() ) {                    schemaLanguage = W3C_XML_SCHEMA;                    xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +                                     Constants.SCHEMA_VALIDATION_FEATURE,                                     true);                    //also set the schema full checking to true.                    xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +                                     Constants.SCHEMA_FULL_CHECKING,                                     true);                    //add this among the list of parser  features since this is added                     //on the parser instance and should be set to default value during                     //reset.                    parserFeatures.put(Constants.XERCES_FEATURE_PREFIX +                                     Constants.SCHEMA_VALIDATION_FEATURE, new Boolean(true));                    parserFeatures.put(Constants.XERCES_FEATURE_PREFIX +                                     Constants.SCHEMA_FULL_CHECKING, new Boolean(true));                                                         // this will allow the parser not to emit DTD-related                    // errors, as the spec demands                    xmlReader.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);                    parserFeatures.put(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);                                    }                else{                    //System.out.println("Property = " + name + "is not set");                }                            } else if (value == null) {                schemaLanguage = null;                xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +                                     Constants.SCHEMA_VALIDATION_FEATURE,                                     false);                parserFeatures.put(Constants.XERCES_FEATURE_PREFIX +                                     Constants.SCHEMA_VALIDATION_FEATURE,                                     new Boolean(false));                            } else {                // REVISIT: It would be nice if we could format this message                // using a user specified locale as we do in the underlying                // XMLReader -- mrglavas                throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(null, "schema-not-supported", null));            }        }         else if(JAXP_SCHEMA_SOURCE.equals(name)) {            //If we are not validating then don't check for  JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCED                        if ( isValidating() ) {                String val = (String)getProperty(JAXP_SCHEMA_LANGUAGE);                if ( val != null && W3C_XML_SCHEMA.equals(val) ) {                    xmlReader.setProperty(name, value);                    parserFeatures.put(name, value);                }                else {                    throw new SAXNotSupportedException(                        SAXMessageFormatter.formatMessage(null,                         "jaxp-order-not-supported",                         new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));                }            }		}		/*else if(name.equlas(Constants.ENTITY_EXPANSION_LIMIT)){			String elimit = (String)value;			if(elimit != null && elimit != ""){				int val = Integer.parseInt(elimit);				secureProcessing.setEntityExpansionLimit(val);			}		}else if(name.equals(Constants.MAX_OCCUR_LIMIT)) {			String mlimit = (String)value;			if(mlimit != null && mlimit != ""){				int val = Integer.parseInt(mlimit);				secureProcessing.setMaxOccurNodeLimit(val);			}		}*/        else if(value instanceof Boolean){            //assume feature            xmlReader.setFeature(name,((Boolean)value).booleanValue());            parserFeatures.put(name, value);        }else{            xmlReader.setProperty(name, value);            parserFeatures.put(name, value);        }    }    /**     * returns the particular property requested for in the underlying      * implementation of org.xml.sax.XMLReader.     */    public Object getProperty(String name)        throws SAXNotRecognizedException, SAXNotSupportedException    {        // TODO: reroute those properties to use new JAXP1.3 API. -KK        if (JAXP_SCHEMA_LANGUAGE.equals(name)) {            // JAXP 1.2 support            return schemaLanguage;        } else {            return xmlReader.getProperty(name);        }    }        public Schema getSchema(){        return grammar;    }        /**     * <p>Return True if secure processing in effect.</p>     * Defaults to <code>false</code>.</p>     *     * @return state of Schema Caching     */    public boolean isSecureProcessing(){        return secureProcessing!=null;    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?