Example #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));
        }
      }
    }
  }
Example #2
0
 /**
  * Gets a simple class name for the specified class type.
  *
  * @param type the class
  * @return the simple class name
  */
 public static String getSimpleClassName(Class type) {
   String name = type.getName();
   // trim trailing semicolon, if any
   int i = name.indexOf(";"); // $NON-NLS-1$
   if (i > -1) {
     name = name.substring(0, i);
   }
   // add brackets for arrays
   while (name.startsWith("[")) { // $NON-NLS-1$
     name = name.substring(1);
     name = name + "[]"; // $NON-NLS-1$
   }
   // eliminate leading package name, if any
   String ext = XML.getExtension(name);
   if (ext != null) {
     name = ext;
   }
   // substitute int for I and double for D arrays
   i = name.indexOf("["); // $NON-NLS-1$
   if (i > -1) {
     String s = name.substring(0, i);
     if (s.equals("I")) { // $NON-NLS-1$
       s = "int"; // $NON-NLS-1$
     } else if (s.equals("D")) { // $NON-NLS-1$
       s = "double"; // $NON-NLS-1$
     } else if (s.equals("Z")) { // $NON-NLS-1$
       s = "boolean"; // $NON-NLS-1$
     }
     name = s + name.substring(i);
   }
   return name;
 }
Example #3
0
 /**
  * Gets the absolute path.
  *
  * @return the absolute path
  */
 public String getAbsolutePath() {
   if (getFile() != null) {
     try {
       return XML.forwardSlash(getFile().getCanonicalPath());
     } catch (IOException ex) {
       ex.printStackTrace();
     }
     return getFile().getAbsolutePath();
   }
   if (getURL() != null) {
     URL url = getURL();
     String path = url.getPath();
     // remove file protocol, if any
     if (path.startsWith("file:")) { // $NON-NLS-1$
       path = path.substring(5);
     }
     // remove leading slash if drive is specified
     if (path.startsWith("/") && path.indexOf(":") > -1) { // $NON-NLS-1$ //$NON-NLS-2$
       path = path.substring(1);
     }
     // replace "%20" with space
     int i = path.indexOf("%20"); // $NON-NLS-1$
     while (i > -1) {
       String s = path.substring(0, i);
       path = s + " " + path.substring(i + 3); // $NON-NLS-1$
       i = path.indexOf("%20"); // $NON-NLS-1$
     }
     return path;
   }
   return null;
 }
Example #4
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;
 }
Example #5
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);
 }
Example #6
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;
 }
Example #7
0
  public int putxml(IBitstream _F_bs, boolean bAttr) throws IOException {
    int _F_ret = 0;
    MapResult _F_mr;
    int _F_parse = 0;
    _F_parse = 16;
    program_number = _F_bs.getbits(_F_parse);
    if (bAttr) {
      XML.WriteXmlElement(
          "<program_number type=\"flUInt\" bitLen=\""
              + _F_parse
              + "\">"
              + program_number
              + "</program_number>");
    } else {
      XML.WriteXmlElement(
          "<program_number bitLen=\"" + _F_parse + "\">" + program_number + "</program_number>");
    }
    _F_bs.skipbits(3);
    if (program_number == 0) {
      _F_parse = 13;
      network_PID = _F_bs.getbits(_F_parse);
      if (bAttr) {
        XML.WriteXmlElement(
            "<network_PID type=\"flUInt\" bitLen=\""
                + _F_parse
                + "\">"
                + network_PID
                + "</network_PID>");
      } else {
        XML.WriteXmlElement(
            "<network_PID bitLen=\"" + _F_parse + "\">" + network_PID + "</network_PID>");
      }
    } else {
      _F_parse = 13;
      program_map_PID = _F_bs.getbits(_F_parse);
      if (bAttr) {
        XML.WriteXmlElement(
            "<program_map_PID type=\"flUInt\" bitLen=\""
                + _F_parse
                + "\">"
                + program_map_PID
                + "</program_map_PID>");
      } else {
        XML.WriteXmlElement(
            "<program_map_PID bitLen=\""
                + _F_parse
                + "\">"
                + program_map_PID
                + "</program_map_PID>");
      }
    }

    return _F_ret;
  }
Example #8
0
 public XML addChild(XML child) {
   Document document = node.getOwnerDocument();
   Node newChild = document.importNode((Node) child.getNative(), true);
   return appendChild(newChild);
 }
Example #9
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);
 }