Exemple #1
0
  /**
   * This will invoke the callbacks for the content of an element.
   *
   * @param node a <code>Content</code> node.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   */
  private void elementContent(Content node, NamespaceStack namespaces) throws JDOMException {
    // update locator
    locator.setNode(node);

    if (node instanceof Element) {
      element((Element) node, namespaces);
    } else if (node instanceof CDATA) {
      cdata(((CDATA) node).getText());
    } else if (node instanceof Text) {
      // contentHandler.characters()
      characters(((Text) node).getText());
    } else if (node instanceof ProcessingInstruction) {
      // contentHandler.processingInstruction()
      processingInstruction((ProcessingInstruction) node);
    } else if (node instanceof Comment) {
      // lexicalHandler.comment()
      comment(((Comment) node).getText());
    } else if (node instanceof EntityRef) {
      // contentHandler.skippedEntity()
      entityRef((EntityRef) node);
    } else {
      // Not a valid element child. This could happen with
      // application-provided lists which may contain non
      // JDOM objects.
      handleError(new JDOMException("Invalid element content: " + node));
    }
  }
Exemple #2
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
    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();
  }
Exemple #3
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);
  }