Пример #1
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;
 }
Пример #2
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);
 }
Пример #3
0
  // -----------------------------------------------------
  // Description: Read the text from the file.
  // AHHGAYUU!
  // -----------------------------------------------------
  String interpretText(String destinationDirectory, String fileName_woext, String suffix) {

    String line = "";
    String accumulate = "";
    Scanner reader = null;

    int dataType = 1; // For current testing

    try {
      File file =
          new File(
              destinationDirectory
                  + File.separator
                  + fileName_woext
                  + File.separator
                  + fileName_woext
                  + "_"
                  + suffix
                  + ".txt");

      reader = new Scanner(new FileReader(file));

      if (dataType == 1) { // multiline
        while (reader.hasNextLine()) {
          accumulate += reader.nextLine().trim() + " ";
        }
        accumulate = accumulate.trim();
      } else if (dataType == 2) { // address
        if (reader.hasNextLine()) {
          accumulate = reader.nextLine().trim();
        }
        if (reader.hasNextLine()) {
          accumulate += "," + reader.nextLine().trim();
        }
        if (reader.hasNextLine()) {
          line = reader.nextLine().trim();
          int index = line.indexOf(",");
          String line31 = line.substring(0, index);

          int i = 0;
          int hi = line.length() - index;
          for (i = hi; i > 0; i--) {
            if (Character.isDigit(line.charAt(i))) break;
          }

          String line32 = line.substring(index + 1, i);
          String line33 = line.substring(i + 1, line.length() - 1);

          accumulate += "," + line31 + "," + line32 + "," + line33;
        }
      } else if (dataType == 3) { // single text
        accumulate = reader.nextLine();
      } else if (dataType == 4) { // numeric
        // coming soon
      }

      reader.close();
      return accumulate;

    } catch (IOException e) {
      e.printStackTrace();
    }
    return "";
  }