예제 #1
0
  /**
   * This will output a single 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.
   *
   * @param node the <code>Content</code> node to output.
   * @throws JDOMException if any error occurred.
   * @see #outputFragment(java.util.List)
   */
  public void outputFragment(Content node) throws JDOMException {
    if (node == null) {
      return;
    }

    // Output single node as a document fragment.
    elementContent(node, new NamespaceStack());
  }
예제 #2
0
  /**
   * 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.
   *
   * @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;
    }

    // Output node list as a document fragment.
    elementContent(nodes, new NamespaceStack());
  }
예제 #3
0
  /**
   * 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();
  }
예제 #4
0
  /**
   * 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).
   *
   * @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();
  }
예제 #5
0
  /**
   * This will recursively invoke all of the callbacks for a particular element.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   */
  private void element(Element element, NamespaceStack namespaces) throws JDOMException {
    // used to check endPrefixMapping
    int previouslyDeclaredNamespaces = namespaces.size();

    // contentHandler.startPrefixMapping()
    Attributes nsAtts = startPrefixMapping(element, namespaces);

    // contentHandler.startElement()
    startElement(element, nsAtts);

    // handle content in the element
    elementContent(element.getContent(), namespaces);

    // update locator
    locator.setNode(element);

    // contentHandler.endElement()
    endElement(element);

    // contentHandler.endPrefixMapping()
    endPrefixMapping(namespaces, previouslyDeclaredNamespaces);
  }