Esempio n. 1
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 stack) throws JDOMException {

    AttributesImpl nsAtts = null; // The namespaces as xmlns attributes

    // contentHandler.startPrefixMapping()
    stack.push(element);
    try {
      for (Namespace ns : stack.addedForward()) {
        startPrefixMapping(ns);
        nsAtts = this.addNsAttribute(nsAtts, ns);
      }

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

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

      // update locator
      if (locator != null) {
        locator.setNode(element);
      }

      // contentHandler.endElement()
      endElement(element);
    } finally {
      stack.pop();
    }

    // contentHandler.endPrefixMapping()
    // de-map in reverse order to the mapping.
    for (Namespace ns : stack.addedReverse()) {
      endPrefixMapping(ns);
    }
  }
Esempio n. 2
0
 /**
  * This will invoke the <code>endPrefixMapping</code> callback in the <code>ContentHandler</code>
  * when a namespace is goes out of scope in the <code>Document</code>.
  *
  * @param namespaces <code>List</code> stack of Namespaces in scope.
  * @param previouslyDeclaredNamespaces number of previously declared namespaces
  */
 private void endPrefixMapping(NamespaceStack namespaces, int previouslyDeclaredNamespaces)
     throws JDOMException {
   while (namespaces.size() > previouslyDeclaredNamespaces) {
     String prefix = namespaces.pop();
     try {
       contentHandler.endPrefixMapping(prefix);
     } catch (SAXException se) {
       throw new JDOMException("Exception in endPrefixMapping", se);
     }
   }
 }