validatorhandlerimpl.java

来自「JAVA 所有包」· Java 代码 · 共 1,050 行 · 第 1/3 页

JAVA
1,050
字号
        }    }    public void startElement(QName element, XMLAttributes attributes,            Augmentations augs) throws XNIException {        if (fContentHandler != null) {            try {                fTypeInfoProvider.beginStartElement(augs, attributes);                fContentHandler.startElement((element.uri != null) ? element.uri : XMLSymbols.EMPTY_STRING,                         element.localpart, element.rawname, fAttrAdapter);            }            catch (SAXException e) {                throw new XNIException(e);            }            finally {                fTypeInfoProvider.finishStartElement();            }        }    }    public void emptyElement(QName element, XMLAttributes attributes,            Augmentations augs) throws XNIException {        /** Split empty element event. **/        startElement(element, attributes, augs);        endElement(element, augs);    }    public void startGeneralEntity(String name,            XMLResourceIdentifier identifier, String encoding,            Augmentations augs) throws XNIException {}    public void textDecl(String version, String encoding, Augmentations augs)            throws XNIException {}    public void endGeneralEntity(String name, Augmentations augs)            throws XNIException {}    public void characters(XMLString text, Augmentations augs)            throws XNIException {        if (fContentHandler != null) {            // if the type is union it is possible that we receive            // a character call with empty data            if (text.length == 0) {                return;            }            try {                fContentHandler.characters(text.ch, text.offset, text.length);            }            catch (SAXException e) {                throw new XNIException(e);            }        }    }    public void ignorableWhitespace(XMLString text, Augmentations augs)            throws XNIException {        if (fContentHandler != null) {            try {                fContentHandler.ignorableWhitespace(text.ch, text.offset, text.length);            }            catch (SAXException e) {                throw new XNIException(e);            }        }    }    public void endElement(QName element, Augmentations augs)            throws XNIException {        if (fContentHandler != null) {            try {                fTypeInfoProvider.beginEndElement(augs);                fContentHandler.endElement((element.uri != null) ? element.uri : XMLSymbols.EMPTY_STRING,                        element.localpart, element.rawname);            }            catch (SAXException e) {                throw new XNIException(e);            }            finally {                fTypeInfoProvider.finishEndElement();            }        }    }    public void startCDATA(Augmentations augs) throws XNIException {}    public void endCDATA(Augmentations augs) throws XNIException {}    public void endDocument(Augmentations augs) throws XNIException {        if (fContentHandler != null) {            try {                fContentHandler.endDocument();            }            catch (SAXException e) {                throw new XNIException(e);            }        }    }    // NO-OP    public void setDocumentSource(XMLDocumentSource source) {}    public XMLDocumentSource getDocumentSource() {        return fSchemaValidator;    }        /*     * ContentHandler methods     */    public void setDocumentLocator(Locator locator) {        fSAXLocatorWrapper.setLocator(locator);        if (fContentHandler != null) {            fContentHandler.setDocumentLocator(locator);        }    }    public void startDocument() throws SAXException {        fComponentManager.reset();        fSchemaValidator.setDocumentHandler(this);        fValidationManager.setEntityState(this);        fTypeInfoProvider.finishStartElement(); // cleans up TypeInfoProvider        fNeedPushNSContext = true;        if (fUnparsedEntities != null && !fUnparsedEntities.isEmpty()) {            // should only clear this if the last document contained unparsed entities            fUnparsedEntities.clear();        }        fErrorReporter.setDocumentLocator(fSAXLocatorWrapper);        try {            fSchemaValidator.startDocument(fSAXLocatorWrapper, fSAXLocatorWrapper.getEncoding(), fNamespaceContext, null);        }        catch (XMLParseException e) {            throw Util.toSAXParseException(e);        }        catch (XNIException e) {            throw Util.toSAXException(e);        }    }    public void endDocument() throws SAXException {        fSAXLocatorWrapper.setLocator(null);        try {            fSchemaValidator.endDocument(null);        }        catch (XMLParseException e) {            throw Util.toSAXParseException(e);        }        catch (XNIException e) {            throw Util.toSAXException(e);        }    }    public void startPrefixMapping(String prefix, String uri)            throws SAXException {        String prefixSymbol;        String uriSymbol;        if (!fStringsInternalized) {            prefixSymbol = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING;            uriSymbol = (uri != null && uri.length() > 0) ? fSymbolTable.addSymbol(uri) : null;        }        else {            prefixSymbol = (prefix != null) ? prefix : XMLSymbols.EMPTY_STRING;            uriSymbol = (uri != null && uri.length() > 0) ? uri : null;        }        if (fNeedPushNSContext) {            fNeedPushNSContext = false;            fNamespaceContext.pushContext();        }        fNamespaceContext.declarePrefix(prefixSymbol, uriSymbol);        if (fContentHandler != null) {            fContentHandler.startPrefixMapping(prefix, uri);        }    }    public void endPrefixMapping(String prefix) throws SAXException {        if (fContentHandler != null) {            fContentHandler.endPrefixMapping(prefix);        }    }    public void startElement(String uri, String localName, String qName,            Attributes atts) throws SAXException {        if (fNeedPushNSContext) {            fNamespaceContext.pushContext();        }        fNeedPushNSContext = true;                // Fill element QName        fillQName(fElementQName, uri, localName, qName);                // Fill XMLAttributes        if (atts instanceof Attributes2) {            fillXMLAttributes2((Attributes2) atts);        }        else {            fillXMLAttributes(atts);        }                try {            fSchemaValidator.startElement(fElementQName, fAttributes, null);        }        catch (XMLParseException e) {            throw Util.toSAXParseException(e);        }        catch (XNIException e) {            throw Util.toSAXException(e);        }    }    public void endElement(String uri, String localName, String qName)            throws SAXException {        fillQName(fElementQName, uri, localName, qName);        try {            fSchemaValidator.endElement(fElementQName, null);        }        catch (XMLParseException e) {            throw Util.toSAXParseException(e);        }        catch (XNIException e) {            throw Util.toSAXException(e);        }        finally {            fNamespaceContext.popContext();        }    }    public void characters(char[] ch, int start, int length)            throws SAXException {        try {            fTempString.setValues(ch, start, length);            fSchemaValidator.characters(fTempString, null);        }        catch (XMLParseException e) {            throw Util.toSAXParseException(e);        }        catch (XNIException e) {            throw Util.toSAXException(e);        }    }    public void ignorableWhitespace(char[] ch, int start, int length)            throws SAXException {        try {            fTempString.setValues(ch, start, length);            fSchemaValidator.ignorableWhitespace(fTempString, null);        }        catch (XMLParseException e) {            throw Util.toSAXParseException(e);        }        catch (XNIException e) {            throw Util.toSAXException(e);        }    }    public void processingInstruction(String target, String data)            throws SAXException {        /**          * Processing instructions do not participate in schema validation,         * so just forward the event to the application's content         * handler.          */        if (fContentHandler != null) {            fContentHandler.processingInstruction(target, data);        }    }    public void skippedEntity(String name) throws SAXException {        // there seems to be no corresponding method on XMLDocumentFilter.        // just pass it down to the output, if any.        if (fContentHandler != null) {            fContentHandler.skippedEntity(name);        }    }        /*     * DTDHandler methods     */        public void notationDecl(String name, String publicId,             String systemId) throws SAXException {}    public void unparsedEntityDecl(String name, String publicId,             String systemId, String notationName) throws SAXException {        if (fUnparsedEntities == null) {            fUnparsedEntities = new HashMap();        }        fUnparsedEntities.put(name, name);    }        /*     * ValidatorHelper methods     */        public void validate(Source source, Result result)         throws SAXException, IOException {        if (result instanceof SAXResult || result == null) {            final SAXSource saxSource = (SAXSource) source;            final SAXResult saxResult = (SAXResult) result;                        if (result != null) {                setContentHandler(saxResult.getHandler());            }                        try {                XMLReader reader = saxSource.getXMLReader();                if( reader==null ) {                    // create one now                    SAXParserFactory spf = SAXParserFactory.newInstance();                    spf.setNamespaceAware(true);                    try {                        reader = spf.newSAXParser().getXMLReader();                        // If this is a Xerces SAX parser, set the security manager if there is one                        if (reader instanceof com.sun.org.apache.xerces.internal.parsers.SAXParser) {                           SecurityManager securityManager = (SecurityManager) fComponentManager.getProperty(SECURITY_MANAGER);                           if (securityManager != null) {                               try {                                   reader.setProperty(SECURITY_MANAGER, securityManager);                               }                               // Ignore the exception if the security manager cannot be set.                               catch (SAXException exc) {}                           }                        }                    } catch( Exception e ) {                        // this is impossible, but better safe than sorry                        throw new FactoryConfigurationError(e);                    }                }                                // If XML names and Namespace URIs are already internalized we                // can avoid running them through the SymbolTable.                try {                    fStringsInternalized = reader.getFeature(STRING_INTERNING);                }                catch (SAXException exc) {                    // The feature isn't recognized or getting it is not supported.                    // In either case, assume that strings are not internalized.                    fStringsInternalized = false;                }                                ErrorHandler errorHandler = fComponentManager.getErrorHandler();                reader.setErrorHandler(errorHandler != null ? errorHandler : DraconianErrorHandler.getInstance());                reader.setEntityResolver(fResolutionForwarder);                fResolutionForwarder.setEntityResolver(fComponentManager.getResourceResolver());                reader.setContentHandler(this);                reader.setDTDHandler(this);                                InputSource is = saxSource.getInputSource();                reader.parse(is);            }             finally {                // release the reference to user's handler ASAP

⌨️ 快捷键说明

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