コード例 #1
0
  /**
   * 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
    for (Content obj : document.getContent()) {

      // 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();
  }