예제 #1
0
  NodeList getElementsByTagNameNS(
      final Parent xshadow, final String namespaceURI, final String localName) {
    if (localName == null) {
      return EMPTYLIST;
    }
    if (namespaceURI == null) {
      return EMPTYLIST;
    }

    final boolean alluri = "*".equals(namespaceURI);
    final boolean allname = "*".equals(localName);

    final ArrayList<JElement> enodes = new ArrayList<JElement>();
    if (xshadow != null) {
      final Iterator<org.jdom2.Element> it = xshadow.getDescendants(Filters.element());

      org.jdom2.Element e = null;
      if (xshadow instanceof org.jdom2.Element) {
        e = (org.jdom2.Element) xshadow;
      } else {
        if (it.hasNext()) {
          e = it.next();
        }
      }
      while (e != null) {
        if ((allname || localName.equals(e.getName()))
            && (alluri || namespaceURI.equals(e.getNamespaceURI()))) {
          enodes.add(find(e));
        }
        e = it.hasNext() ? it.next() : null;
      }
    }
    return new JNodeList(enodes);
  }
예제 #2
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);
    }
  }
예제 #3
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);
    }
  }