📄 saxoutputter.java
字号:
} /** * Returns whether attribute namespace declarations shall be reported as * "xmlns" attributes. * * @return whether attribute namespace declarations shall be reported as * "xmlns" attributes. */ public boolean getReportNamespaceDeclarations() { return declareNamespaces; } /** * This will define whether attribute namespace declarations shall be * reported as "xmlns" attributes. This flag defaults to <code>false</code> * and behaves as the "namespace-prefixes" SAX core feature. * * @param declareNamespaces whether attribute namespace declarations * shall be reported as "xmlns" attributes. */ public void setReportNamespaceDeclarations(boolean declareNamespaces) { this.declareNamespaces = declareNamespaces; } /** * Returns whether DTD events will be reported. * * @return whether DTD events will be reported */ public boolean getReportDTDEvents() { return reportDtdEvents; } /** * This will define whether to report DTD events to SAX DeclHandlers * and LexicalHandlers if these handlers are registered and the * document to output includes a DocType declaration. * * @param reportDtdEvents whether to notify DTD events. */ public void setReportDTDEvents(boolean reportDtdEvents) { this.reportDtdEvents = reportDtdEvents; } /** * This will set the state of a SAX feature. * <p> * All XMLReaders are required to support setting to true and to false. * </p> * <p> * SAXOutputter currently supports the following SAX core features: * <dl> * <dt><code>http://xml.org/sax/features/namespaces</code></dt> * <dd><strong>description:</strong> <code>true</code> indicates * namespace URIs and unprefixed local names for element and * attribute names will be available</dd> * <dd><strong>access:</strong> read/write, but always * <code>true</code>!</dd> * <dt><code>http://xml.org/sax/features/namespace-prefixes</code></dt> * <dd><strong>description:</strong> <code>true</code> indicates * XML 1.0 names (with prefixes) and attributes (including xmlns* * attributes) will be available</dd> * <dd><strong>access:</strong> read/write</dd> * <dt><code>http://xml.org/sax/features/validation</code></dt> * <dd><strong>description:</strong> controls whether SAXOutputter * is reporting DTD-related events; if <code>true</code>, the * DocType internal subset will be parsed to fire DTD events</dd> * <dd><strong>access:</strong> read/write, defaults to * <code>true</code></dd> * </dl> * </p> * * @param name <code>String</code> the feature name, which is a * fully-qualified URI. * @param value <code>boolean</code> the requested state of the * feature (true or false). * * @throws SAXNotRecognizedException when SAXOutputter does not * recognize the feature name. * @throws SAXNotSupportedException when SAXOutputter recognizes * the feature name but cannot set the requested value. */ public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if (NS_PREFIXES_SAX_FEATURE.equals(name)) { // Namespace prefix declarations. this.setReportNamespaceDeclarations(value); } else { if (NAMESPACES_SAX_FEATURE.equals(name)) { if (value != true) { // Namespaces feature always supported by SAXOutputter. throw new SAXNotSupportedException(name); } // Else: true is OK! } else { if (VALIDATION_SAX_FEATURE.equals(name)) { // Report DTD events. this.setReportDTDEvents(value); } else { // Not a supported feature. throw new SAXNotRecognizedException(name); } } } } /** * This will look up the value of a SAX feature. * * @param name <code>String</code> the feature name, which is a * fully-qualified URI. * @return <code>boolean</code> the current state of the feature * (true or false). * * @throws SAXNotRecognizedException when SAXOutputter does not * recognize the feature name. * @throws SAXNotSupportedException when SAXOutputter recognizes * the feature name but determine its value at this time. */ public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if (NS_PREFIXES_SAX_FEATURE.equals(name)) { // Namespace prefix declarations. return (this.declareNamespaces); } else { if (NAMESPACES_SAX_FEATURE.equals(name)) { // Namespaces feature always supported by SAXOutputter. return (true); } else { if (VALIDATION_SAX_FEATURE.equals(name)) { // Report DTD events. return (this.reportDtdEvents); } else { // Not a supported feature. throw new SAXNotRecognizedException(name); } } } } /** * This will set the value of a SAX property. * This method is also the standard mechanism for setting extended * handlers. * <p> * SAXOutputter currently supports the following SAX properties: * <dl> * <dt><code>http://xml.org/sax/properties/lexical-handler</code></dt> * <dd><strong>data type:</strong> * <code>org.xml.sax.ext.LexicalHandler</code></dd> * <dd><strong>description:</strong> An optional extension handler for * lexical events like comments.</dd> * <dd><strong>access:</strong> read/write</dd> * <dt><code>http://xml.org/sax/properties/declaration-handler</code></dt> * <dd><strong>data type:</strong> * <code>org.xml.sax.ext.DeclHandler</code></dd> * <dd><strong>description:</strong> An optional extension handler for * DTD-related events other than notations and unparsed entities.</dd> * <dd><strong>access:</strong> read/write</dd> * </dl> * </p> * * @param name <code>String</code> the property name, which is a * fully-qualified URI. * @param value <code>Object</code> the requested value for the property. * * @throws SAXNotRecognizedException when SAXOutputter does not recognize * the property name. * @throws SAXNotSupportedException when SAXOutputter recognizes the * property name but cannot set the requested value. */ public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if ((LEXICAL_HANDLER_SAX_PROPERTY.equals(name)) || (LEXICAL_HANDLER_ALT_PROPERTY.equals(name))) { this.setLexicalHandler((LexicalHandler)value); } else { if ((DECL_HANDLER_SAX_PROPERTY.equals(name)) || (DECL_HANDLER_ALT_PROPERTY.equals(name))) { this.setDeclHandler((DeclHandler)value); } else { throw new SAXNotRecognizedException(name); } } } /** * This will look up the value of a SAX property. * * @param name <code>String</code> the property name, which is a * fully-qualified URI. * @return <code>Object</code> the current value of the property. * * @throws SAXNotRecognizedException when SAXOutputter does not recognize * the property name. * @throws SAXNotSupportedException when SAXOutputter recognizes the * property name but cannot determine its value at this time. */ public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if ((LEXICAL_HANDLER_SAX_PROPERTY.equals(name)) || (LEXICAL_HANDLER_ALT_PROPERTY.equals(name))) { return this.getLexicalHandler(); } else { if ((DECL_HANDLER_SAX_PROPERTY.equals(name)) || (DECL_HANDLER_ALT_PROPERTY.equals(name))) { return this.getDeclHandler(); } else { throw new SAXNotRecognizedException(name); } } } /** * This will output the <code>JDOM Document</code>, firing off the * SAX events that have been registered. * * @param document <code>JDOM Document</code> to output. * * @throws JDOMException if any error occurred. */ public void output(Document document) throws JDOMException { if (document == null) { return; } // contentHandler.setDocumentLocator() documentLocator(document); // contentHandler.startDocument() startDocument(); // Fire DTD events if (this.reportDtdEvents) { dtdEvents(document); } // Handle root element, as well as any root level // processing instructions and comments Iterator i = document.getContent().iterator(); while (i.hasNext()) { Object obj = i.next(); // update locator locator.setNode(obj); if (obj instanceof Element) { // process root element and its content element(document.getRootElement(), new NamespaceStack()); } else if (obj instanceof ProcessingInstruction) { // contentHandler.processingInstruction() processingInstruction((ProcessingInstruction) obj); } else if (obj instanceof Comment) { // lexicalHandler.comment() comment(((Comment) obj).getText()); } } // contentHandler.endDocument() endDocument(); } /** * This will output a list of JDOM nodes as a document, firing * off the SAX events that have been registered. * <p> * <strong>Warning</strong>: This method may output ill-formed XML * documents if the list contains top-level objects that are not * legal at the document level (e.g. Text or CDATA nodes, multiple * Element nodes, etc.). Thus, it should only be used to output * document portions towards ContentHandlers capable of accepting * such ill-formed documents (such as XSLT processors).</p> * * @param nodes <code>List</code> of JDOM nodes to output. * * @throws JDOMException if any error occurred. * * @see #output(org.jdom.Document) */ public void output(List nodes) throws JDOMException { if ((nodes == null) || (nodes.size() == 0)) { return; } // contentHandler.setDocumentLocator() documentLocator(null); // contentHandler.startDocument() startDocument(); // Process node list. elementContent(nodes, new NamespaceStack()); // contentHandler.endDocument() endDocument(); } /** * This will output a single JDOM element as a document, firing * off the SAX events that have been registered. * * @param node the <code>Element</code> node to output. * * @throws JDOMException if any error occurred. */ public void output(Element node) throws JDOMException { if (node == null) { return; } // contentHandler.setDocumentLocator() documentLocator(null); // contentHandler.startDocument() startDocument(); // Output node. elementContent(node, new NamespaceStack()); // contentHandler.endDocument() endDocument(); } /** * This will output a list of JDOM nodes as a fragment of an XML * document, firing off the SAX events that have been registered. * <p> * <strong>Warning</strong>: This method does not call the * {@link ContentHandler#setDocumentLocator}, * {@link ContentHandler#startDocument} and * {@link ContentHandler#endDocument} callbacks on the * {@link #setContentHandler ContentHandler}. The user shall * invoke these methods directly prior/after outputting the * document fragments.</p> * * @param nodes <code>List</code> of JDOM nodes to output. * * @throws JDOMException if any error occurred. * * @see #outputFragment(org.jdom.Content) */ public void outputFragment(List nodes) throws JDOMException { if ((nodes == null) || (nodes.size() == 0)) { return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -