Package sunlabs.brazil.util

Examples of sunlabs.brazil.util.LexML


       hr.request.props, hr.prefix, init);
        } catch (IOException e) {
     hr.request.log(Server.LOG_WARNING, hr.prefix,
       "Can't find macro init file: " + init);
        }
        LexML lex = new LexML(src);
        while (lex.nextToken()) {
      if (lex.getType()==LexML.TAG &&
        lex.getTag().equals("definemacro")) {
    String name=lex.getAttributes().get("name");
    boolean doSubst = (lex.getAttributes().get("subst") != null);
    String value = snarfTillClose(lex, "definemacro").trim();
    if (doSubst) {
        value = Format.subst(hr.server.props, value);
    }
    if (!value.equals("")) {
View Full Code Here


  nodes = 0;
  root = new Node("ROOT", false, null, null, Node.ROOT, 0);// dummy root
        Stack stack = new Stack();    // parent stack
  stack.push(new StackInfo(root, 0));
  Node parent = root;
  LexML lex = new LexML(src);
  Node current = root;
  IllegalXmlException ex = null;

  while(lex.nextToken()) {
      switch (lex.getType()) {
      case LexML.COMMENT:
    // System.out.println("Got comment: " + lex.getBody());
    break;
      case LexML.STRING:
    current.appendCdata(lex.getBody());
    break;
      case LexML.TAG:
    String name = lex.getTag().toLowerCase();
    if (name.startsWith("/")) {  // pop stack if proper nesting
        name = name.substring(1);
        if (tags != null && !tags.containsKey(name)) {
      // System.out.println("Skipping /" + name);
      continue;
        }

        // parse error, what should we do?

        if (!name.equals(parent.getTag())) {
      int sl = line(lex.getString(),
        ((StackInfo)stack.peek()).position);
      ex = IllegalXmlException.getEx(ex,  ident, sl,
          parent.getTag(), line(lex), "</" + name + ">");

      /*
       * if matching tag is on the stack, pop until we
       * get there.  Otherwise ignore the closing tag
       */

      for (int i=stack.size()-2;i>0;i--) {
          Node node=((StackInfo)stack.elementAt(i)).parent;
          String tag = node.getTag();
          if (tag.equals(name)) {
        while (++i <= stack.size()) {
            /*
            System.out.println("popping " +
              stack.peek());
            */
            stack.pop();
        }
              stack.pop();
              current=parent=((StackInfo)stack.peek()).parent;
              break;
          }
      }
      continue; // ignore it?
        } else {
            stack.pop();
      current = parent = ((StackInfo) stack.peek()).parent;
        }
    } else {
        boolean single = lex.isSingleton();
        if (!single && tags != null && !tags.containsKey(name)) {
      // System.out.println(name + ": setting to single");
      single=true;
        }
        int count = ((StackInfo) stack.peek()).getCount(name);
                    Node n = new Node(name, single,
          lex.getAttributes(), parent, Node.TAG, count);
        current = n;
        nodes++;
              parent.addChild(n);
        if (!single) {
            stack.push(new StackInfo(n, lex.getLocation()));
            parent = n;
        }
    }
    break;
      default:
    System.out.println("Oops, invalid type!");
    break;
      }
  }
  /*
   * if we still have stuff on the stack, add an error for each tag
   */

  stack.pop();
  while (stack.size() > 2) {
      stack.pop();
      parent = ((StackInfo) stack.peek()).parent;
      int sl = line(lex.getString(), ((StackInfo)stack.peek()).position);
      ex = IllegalXmlException.getEx(ex,  ident, sl, parent.getTag(),
        1+line(lex.getString(), lex.getLocation()), "eof");
  }
  if (ex != null) {
      throw ex;
  }
    }
View Full Code Here

TOP

Related Classes of sunlabs.brazil.util.LexML

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.