Ejemplo n.º 1
0
  /** @nowebref */
  protected XML(XML parent, Node node) {
    this.node = node;
    this.parent = parent;

    for (String attr : parent.listAttributes()) {
      if (attr.startsWith("xmlns")) {
        // Copy namespace attributes to the kids, otherwise this XML
        // can no longer be printed (or manipulated in most ways).
        // Only do this when it's an Element, otherwise it's trying to set
        // attributes on text notes (interstitial content).
        if (node instanceof Element) {
          setString(attr, parent.getString(attr));
        }
      }
    }
  }
Ejemplo n.º 2
0
 /**
  * Get a child by its name or path.
  *
  * @param name element name or path/to/element
  * @return the first matching element or null if no match
  */
 public XML getChild(String name) {
   if (name.length() > 0 && name.charAt(0) == '/') {
     throw new IllegalArgumentException("getChild() should not begin with a slash");
   }
   if (name.indexOf('/') != -1) {
     return getChildRecursive(PApplet.split(name, '/'), 0);
   }
   int childCount = getChildCount();
   for (int i = 0; i < childCount; i++) {
     XML kid = getChild(i);
     String kidName = kid.getName();
     if (kidName != null && kidName.equals(name)) {
       return kid;
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 public void testXML() throws Exception {
   QueryElement q1 = new QueryElement("a", "1");
   Document doc = XML.createDocument();
   Node root = q1.toXML(doc);
   assertEquals("queryElement", root.getNodeName());
   NodeList children = root.getChildNodes();
   for (int i = 0; i < children.getLength(); ++i) {
     Node child = children.item(i);
     if ("tokenRole".equals(child.getNodeName())) {
       assertEquals("a", XML.text(child));
     } else if ("tokenValue".equals(child.getNodeName())) {
       assertEquals("1", XML.text(child));
     } else fail("Unknown node \"" + child.getNodeName() + "\" in XML result");
   }
   QueryElement q2 = new QueryElement(root);
   assertEquals(q1, q2);
 }
Ejemplo n.º 4
0
 /**
  * Get any children that match this name or path. Similar to getChild(), but will grab multiple
  * matches rather than only the first.
  *
  * @param name element name or path/to/element
  * @return array of child elements that match
  * @author processing.org
  */
 public XML[] getChildren(String name) {
   if (name.length() > 0 && name.charAt(0) == '/') {
     throw new IllegalArgumentException("getChildren() should not begin with a slash");
   }
   if (name.indexOf('/') != -1) {
     return getChildrenRecursive(PApplet.split(name, '/'), 0);
   }
   // if it's a number, do an index instead
   // (returns a single element array, since this will be a single match
   if (Character.isDigit(name.charAt(0))) {
     return new XML[] {getChild(Integer.parseInt(name))};
   }
   int childCount = getChildCount();
   XML[] matches = new XML[childCount];
   int matchCount = 0;
   for (int i = 0; i < childCount; i++) {
     XML kid = getChild(i);
     String kidName = kid.getName();
     if (kidName != null && kidName.equals(name)) {
       matches[matchCount++] = kid;
     }
   }
   return (XML[]) PApplet.subset(matches, 0, matchCount);
 }
Ejemplo n.º 5
0
 /**
  * Internal helper function for getChild(String).
  *
  * @param items result of splitting the query on slashes
  * @param offset where in the items[] array we're currently looking
  * @return matching element or null if no match
  * @author processing.org
  */
 protected XML getChildRecursive(String[] items, int offset) {
   // if it's a number, do an index instead
   if (Character.isDigit(items[offset].charAt(0))) {
     XML kid = getChild(Integer.parseInt(items[offset]));
     if (offset == items.length - 1) {
       return kid;
     } else {
       return kid.getChildRecursive(items, offset + 1);
     }
   }
   int childCount = getChildCount();
   for (int i = 0; i < childCount; i++) {
     XML kid = getChild(i);
     String kidName = kid.getName();
     if (kidName != null && kidName.equals(items[offset])) {
       if (offset == items.length - 1) {
         return kid;
       } else {
         return kid.getChildRecursive(items, offset + 1);
       }
     }
   }
   return null;
 }
Ejemplo n.º 6
0
  /** @see gov.nih.gov.nih.nci.cagrid.opensaml.SAMLObject#fromDOM(org.w3c.dom.Element) */
  public void fromDOM(Element e) throws SAMLException {
    super.fromDOM(e);

    // Extract subject.
    subject = (SAMLSubject) new SAMLSubject(XML.getFirstChildElement(e)).setParent(this);
  }
Ejemplo n.º 7
0
 public XML addChild(XML child) {
   Document document = node.getOwnerDocument();
   Node newChild = document.importNode((Node) child.getNative(), true);
   return appendChild(newChild);
 }
Ejemplo n.º 8
0
 /**
  * @webref xml:method
  * @brief Converts String content to an XML object
  * @param data the content to be parsed as XML
  * @return an XML object, or null
  * @throws SAXException
  * @throws ParserConfigurationException
  * @throws IOException
  * @nowebref
  */
 public static XML parse(String data)
     throws IOException, ParserConfigurationException, SAXException {
   return XML.parse(data, null);
 }
Ejemplo n.º 9
0
 /** @deprecated */
 void add(XML xml) {
   _add(xml.getAnnotation());
 }