Esempio n. 1
0
  /**
   * Appends a namespace declaration in the form of a xmlns attribute to an attribute list,
   * crerating this latter if needed.
   *
   * @param atts <code>AttributeImpl</code> where to add the attribute.
   * @param ns <code>Namespace</code> the namespace to declare.
   * @return <code>AttributeImpl</code> the updated attribute list.
   */
  private AttributesImpl addNsAttribute(AttributesImpl atts, Namespace ns) {
    if (this.declareNamespaces) {
      if (atts == null) {
        atts = new AttributesImpl();
      }

      String prefix = ns.getPrefix();
      if (prefix.equals("")) {
        atts.addAttribute(
            "", // namespace
            "", // local name
            "xmlns", // qualified name
            "CDATA", // type
            ns.getURI()); // value
      } else {
        atts.addAttribute(
            "", // namespace
            "", // local name
            "xmlns:" + ns.getPrefix(), // qualified name
            "CDATA", // type
            ns.getURI()); // value
      }
    }
    return atts;
  }
Esempio n. 2
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);
    }
  }