📄 saxreader.java
字号:
/** Returns whether adjacent text nodes should be merged together. * @return Value of property mergeAdjacentText. */ public boolean isMergeAdjacentText() { return mergeAdjacentText; } /** Sets whether or not adjacent text nodes should be merged * together when parsing. * @param mergeAdjacentText New value of property mergeAdjacentText. */ public void setMergeAdjacentText(boolean mergeAdjacentText) { this.mergeAdjacentText = mergeAdjacentText; } /** Sets whether whitespace between element start and end tags should be ignored * * @return Value of property stripWhitespaceText. */ public boolean isStripWhitespaceText() { return stripWhitespaceText; } /** Sets whether whitespace between element start and end tags should be ignored. * * @param stripWhitespaceText New value of property stripWhitespaceText. */ public void setStripWhitespaceText(boolean stripWhitespaceText) { this.stripWhitespaceText = stripWhitespaceText; } /** * Returns whether we should ignore comments or not. * @return boolean */ public boolean isIgnoreComments() { return ignoreComments; } /** * Sets whether we should ignore comments or not. * @param ignoreComments whether we should ignore comments or not. */ public void setIgnoreComments(boolean ignoreComments) { this.ignoreComments = ignoreComments; } /** * @return the <code>DocumentFactory</code> used to create document objects * @deprecated Use getNodeFactory() instead. */ public DocumentFactory getDocumentFactory() { DocumentFactory result = null; NodeFactory nodeFactory = getNodeFactory(); if (nodeFactory instanceof DocumentFactory) { result = (DocumentFactory) nodeFactory; } else { XPathFactory xpathFactory = DocumentFactory.getInstance(); result = new DelegateDocumentFactory(nodeFactory, xpathFactory); } return result; } public NodeFactory getNodeFactory() { if (factory == null) { factory = DocumentFactory.getInstance(); } return factory; } /** <p>This sets the <code>DocumentFactory</code> used to create new documents. * This method allows the building of custom DOM4J tree objects to be implemented * easily using a custom derivation of {@link DocumentFactory}</p> * * @param factory <code>DocumentFactory</code> used to create DOM4J objects * @deprecated Use setNodeFactory(NodeFactory) instead */ public void setDocumentFactory(DocumentFactory factory) { this.factory = factory; } public void setNodeFactory(NodeFactory factory) { this.factory = factory; } /** @return the <code>ErrorHandler</code> used by SAX */ public ErrorHandler getErrorHandler() { return errorHandler; } /** Sets the <code>ErrorHandler</code> used by the SAX * <code>XMLReader</code>. * * @param errorHandler is the <code>ErrorHandler</code> used by SAX */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; } /** Returns the current entity resolver used to resolve entities */ public EntityResolver getEntityResolver() { return entityResolver; } /** Sets the entity resolver used to resolve entities. */ public void setEntityResolver(EntityResolver entityResolver) { this.entityResolver = entityResolver; } /** @return the <code>XMLReader</code> used to parse SAX events */ public XMLReader getXMLReader() throws SAXException { if (xmlReader == null) { xmlReader = createXMLReader(); } return xmlReader; } /** Sets the <code>XMLReader</code> used to parse SAX events * * @param xmlReader is the <code>XMLReader</code> to parse SAX events */ public void setXMLReader(XMLReader xmlReader) { this.xmlReader = xmlReader; } /** Sets the class name of the <code>XMLReader</code> to be used * to parse SAX events. * * @param xmlReaderClassName is the class name of the <code>XMLReader</code> * to parse SAX events */ public void setXMLReaderClassName(String xmlReaderClassName) throws SAXException { setXMLReader( XMLReaderFactory.createXMLReader(xmlReaderClassName) ); } /** Adds the <code>ElementHandler</code> to be called when the * specified path is encounted. * * @param path is the path to be handled * @param handler is the <code>ElementHandler</code> to be called * by the event based processor. */ public void addHandler(String path, ElementHandler handler) { getDispatchHandler().addHandler(path, handler); } /** Removes the <code>ElementHandler</code> from the event based * processor, for the specified path. * * @param path is the path to remove the <code>ElementHandler</code> for. */ public void removeHandler(String path) { getDispatchHandler().removeHandler(path); } /** When multiple <code>ElementHandler</code> instances have been * registered, this will set a default <code>ElementHandler</code> * to be called for any path which does <b>NOT</b> have a handler * registered. * @param handler is the <code>ElementHandler</code> to be called * by the event based processor. */ public void setDefaultHandler(ElementHandler handler) { getDispatchHandler().setDefaultHandler(handler); } /** * This method clears out all the existing handlers and default handler * setting things back as if no handler existed. Useful when reusing an * object instance. */ public void resetHandlers() { getDispatchHandler().resetHandlers(); } /** Returns the SAX filter being used to filter SAX events. * * @return the SAX filter being used or null if no SAX filter is installed */ public XMLFilter getXMLFilter() { return xmlFilter; } /** Sets the SAX filter to be used when filtering SAX events * * @param xmlFilter is the SAX filter to use or null to disable filtering */ public void setXMLFilter(XMLFilter xmlFilter) { this.xmlFilter = xmlFilter; } // Implementation methods //------------------------------------------------------------------------- /** Installs any XMLFilter objects required to allow the SAX event stream * to be filtered and preprocessed before it gets to dom4j. * * @return the new XMLFilter if applicable or the original XMLReader if no * filter is being used. */ protected XMLReader installXMLFilter(XMLReader xmlReader) { XMLFilter xmlFilter = getXMLFilter(); if ( xmlFilter != null ) { // find the root XMLFilter XMLFilter root = xmlFilter; while (true) { XMLReader parent = root.getParent(); if ( parent instanceof XMLFilter ) { root = (XMLFilter) parent; } else { break; } } root.setParent(xmlReader); return xmlFilter; } return xmlReader; } protected DispatchHandler getDispatchHandler() { if (dispatchHandler == null) { dispatchHandler = new DispatchHandler(); } return dispatchHandler; } protected void setDispatchHandler(DispatchHandler dispatchHandler) { this.dispatchHandler = dispatchHandler; } /** Factory Method to allow alternate methods of * creating and configuring XMLReader objects */ protected XMLReader createXMLReader() throws SAXException { return SAXHelper.createXMLReader( isValidating() ); } /** Configures the XMLReader before use */ protected void configureReader(XMLReader reader, DefaultHandler contentHandler) throws DocumentException { // configure lexical handling SAXHelper.setParserProperty( reader, "http://xml.org/sax/handlers/LexicalHandler", contentHandler ); // try alternate property just in case SAXHelper.setParserProperty( reader, "http://xml.org/sax/properties/lexical-handler", contentHandler ); // register the DeclHandler if ( includeInternalDTDDeclarations ) { SAXHelper.setParserProperty( reader, "http://xml.org/sax/properties/declaration-handler", contentHandler ); } // configure namespace support SAXHelper.setParserFeature( reader, "http://xml.org/sax/features/namespaces", true ); SAXHelper.setParserFeature( reader, "http://xml.org/sax/features/namespace-prefixes", false ); // string interning SAXHelper.setParserFeature( reader, "http://xml.org/sax/features/string-interning", isStringInternEnabled() ); // external entites/* SAXHelper.setParserFeature( reader, "http://xml.org/sax/properties/external-general-entities", includeExternalGeneralEntities ); SAXHelper.setParserFeature( reader, "http://xml.org/sax/properties/external-parameter-entities", includeExternalParameterEntities );*/ try { // configure validation support reader.setFeature( "http://xml.org/sax/features/validation", isValidating() ); if (errorHandler != null) { reader.setErrorHandler(errorHandler); } else { reader.setErrorHandler(contentHandler); } } catch (Exception e) { if (isValidating()) { throw new DocumentException( "Validation not supported for XMLReader: " + reader, e ); } } } /** Factory Method to allow user derived SAXContentHandler objects to be used */ protected SAXContentHandler createContentHandler(XMLReader reader) { return new SAXContentHandler( getDocumentFactory(), dispatchHandler ); } protected EntityResolver createDefaultEntityResolver( String documentSystemId ) { String prefix = null; if ( documentSystemId != null && documentSystemId.length() > 0 ) { int idx = documentSystemId.lastIndexOf( '/' ); if ( idx > 0 ) { prefix = documentSystemId.substring(0, idx+1); } } return new SAXEntityResolver(prefix); } protected static class SAXEntityResolver implements EntityResolver, Serializable { String uriPrefix; public SAXEntityResolver(String uriPrefix) { this.uriPrefix = uriPrefix; } public InputSource resolveEntity(String publicId, String systemId) { // try create a relative URI reader... if ( systemId != null && systemId.length() > 0 ) { if ( uriPrefix != null && systemId.indexOf( ':' ) <= 0 ) { systemId = uriPrefix + systemId; } } return new InputSource(systemId); } } }/* * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "DOM4J" must not be used to endorse or promote * products derived from this Software without prior written * permission of MetaStuff, Ltd. For written permission, * please contact dom4j-info@metastuff.com. * * 4. Products derived from this Software may not be called "DOM4J" * nor may "DOM4J" appear in their names without prior written * permission of MetaStuff, Ltd. DOM4J is a registered * trademark of MetaStuff, Ltd. * * 5. Due credit should be given to the DOM4J Project * (http://dom4j.org/). * * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. * * $Id: SAXReader.java,v 1.2 2003/06/10 16:18:34 per_nyfelt Exp $ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -