Exemple #1
0
  public Element parseFromString(String text) throws IOException {
    if (showRaw) System.out.println("Raw ODL=\n" + text);

    Element rootElem = new Element("odl");
    doc = new Document(rootElem);

    Element current = rootElem;
    StringTokenizer lineFinder = new StringTokenizer(text, "\t\n\r\f");
    while (lineFinder.hasMoreTokens()) {
      String line = lineFinder.nextToken();
      if (line.startsWith("GROUP")) {
        current = startGroup(current, line);

      } else if (line.startsWith("OBJECT")) {
        current = startObject(current, line);

      } else if (line.startsWith("END_OBJECT")) {
        endObject(current, line);
        current = current.getParentElement();

      } else if (line.startsWith("END_GROUP")) {
        endGroup(current, line);
        current = current.getParentElement();

      } else {
        addField(current, line);
      }
    }

    if (show) showDoc(System.out);
    return rootElem;
  }