示例#1
0
 /**
  * removes any tags from the validator's queue that match the given element
  *
  * @param element to remove from the queue
  */
 public void removeAll(String element) {
   for (HtmlTag h : tags) {
     if (h.toString().equals(element)) {
       tags.remove(h);
     }
   }
 }
示例#2
0
  /**
   * examines a sequence of HTML tags and determines if it represents a valid sequence of tags
   * prints an indented text representation of the HTML tags in the queue
   */
  public void validate() {
    int indent = 0;
    StackMP2 stack = new StackMP2();

    for (HtmlTag h : tags) {

      if (stack.isEmpty() & !h.isOpenTag()) {
        System.out.println("Error unexpected tag: " + h.toString());
        continue;
      }

      if (!h.isOpenTag()) {

        if (h.matches(stack.peek())) {
          for (int j = 0; j < indent - 1; j++) {
            System.out.print("    ");
          }
          System.out.println(h.toString());
          stack.pop();
          indent--;
        } else {
          System.out.println("Error unexpected tag: " + h.toString());
        }

      } else {

        for (int i = 0; i < indent; i++) {
          System.out.print("    ");
        }

        System.out.println(h.toString());
        if (!h.isSelfClosing()) {
          stack.push(h);
          indent++;
        }
      }
    }
    while (!stack.isEmpty()) {
      System.out.println("Error unclosed tag: " + stack.pop().toString());
    }
  }
示例#3
0
 // @Override default constructor
 public HtmlValidator() {
   tags = HtmlTag.tokenize("");
 }