Example #1
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 namespace Namespace leaving scope.
  */
 private void endPrefixMapping(Namespace namespace) throws JDOMException {
   try {
     contentHandler.endPrefixMapping(namespace.getPrefix());
   } catch (SAXException se) {
     throw new JDOMException("Exception in endPrefixMapping", se);
   }
 }
Example #2
0
 /**
  * This method is always the second method of all callbacks in all handlers to be invoked
  * (setDocumentLocator is always first).
  */
 private void startDocument() throws JDOMException {
   try {
     contentHandler.startDocument();
   } catch (SAXException se) {
     throw new JDOMException("Exception in startDocument", se);
   }
 }
Example #3
0
 /**
  * This will be called for each chunk of character data encountered.
  *
  * @param elementText all text in an element, including whitespace.
  */
 private void characters(String elementText) throws JDOMException {
   char[] c = elementText.toCharArray();
   try {
     contentHandler.characters(c, 0, c.length);
   } catch (SAXException se) {
     throw new JDOMException("Exception in characters", se);
   }
 }
Example #4
0
  /** Always the last method of all callbacks in all handlers to be invoked. */
  private void endDocument() throws JDOMException {
    try {
      contentHandler.endDocument();

      // reset locator
      locator = null;
    } catch (SAXException se) {
      throw new JDOMException("Exception in endDocument", se);
    }
  }
Example #5
0
 /**
  * This will invoke the <code>ContentHandler.skippedEntity</code> callback when an entity
  * reference is encountered.
  *
  * @param entity <code>EntityRef</code>.
  */
 private void entityRef(EntityRef entity) throws JDOMException {
   if (entity != null) {
     try {
       // No need to worry about appending a '%' character as
       // we do not support parameter entities
       contentHandler.skippedEntity(entity.getName());
     } catch (SAXException se) {
       throw new JDOMException("Exception in entityRef", se);
     }
   }
 }
Example #6
0
  /**
   * This will invoke the <code>endElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   */
  private void endElement(Element element) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    try {
      contentHandler.endElement(namespaceURI, localName, rawName);
    } catch (SAXException se) {
      throw new JDOMException("Exception in endElement", se);
    }
  }
Example #7
0
 /**
  * This will invoke the <code>ContentHandler.processingInstruction</code> callback when a
  * processing instruction is encountered.
  *
  * @param pi <code>ProcessingInstruction</code> containing target and data.
  */
 private void processingInstruction(ProcessingInstruction pi) throws JDOMException {
   if (pi != null) {
     String target = pi.getTarget();
     String data = pi.getData();
     try {
       contentHandler.processingInstruction(target, data);
     } catch (SAXException se) {
       throw new JDOMException("Exception in processingInstruction", se);
     }
   }
 }
Example #8
0
  /**
   * This method tells you the line of the XML file being parsed. For an in-memory document, it's
   * meaningless. The location is only valid for the current parsing lifecycle, but the document has
   * already been parsed. Therefore, it returns -1 for both line and column numbers.
   *
   * @param document JDOM <code>Document</code>.
   */
  private void documentLocator(Document document) {
    locator = new JDOMLocator();
    String publicID = null;
    String systemID = null;

    if (document != null) {
      DocType docType = document.getDocType();
      if (docType != null) {
        publicID = docType.getPublicID();
        systemID = docType.getSystemID();
      }
    }
    locator.setPublicId(publicID);
    locator.setSystemId(systemID);
    locator.setLineNumber(-1);
    locator.setColumnNumber(-1);

    contentHandler.setDocumentLocator(locator);
  }
Example #9
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    for (Attribute a : element.getAttributes()) {
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }