View Javadoc

1   /*
2    * HtmlVisitor.java
3    * Copyright (C) 1999 Quiotix Corporation.  
4    *
5    * This program is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License, version 2, as 
7    * published by the Free Software Foundation.  
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License (http://www.gnu.org/copyleft/gpl.txt)
13   * for more details.
14   */
15  
16  package com.quiotix.html.parser;
17  
18  import java.util.Iterator;
19  
20  /**
21   * Abstract class implementing Visitor pattern for HtmlDocument objects.
22   *
23   * @author Brian Goetz, Quiotix
24   */
25  
26  public abstract class HtmlVisitor {
27      /** Visit a Tag. */
28      public void visit(HtmlDocument.Tag t) {
29      }
30  
31      /** Visit an EndTag. */
32      public void visit(HtmlDocument.EndTag t) {
33      }
34  
35      /** Visit a Comment. */
36      public void visit(HtmlDocument.Comment c) {
37      }
38  
39      /** Visit Text. */
40      public void visit(HtmlDocument.Text t) {
41      }
42  
43      /** Visit a Newline. */
44      public void visit(HtmlDocument.Newline n) {
45      }
46  
47      /** Visit an Annotation. */
48      public void visit(HtmlDocument.Annotation a) {
49      }
50  
51      /** Visit a TagBlock. */
52      public void visit(HtmlDocument.TagBlock bl) {
53          bl.startTag.accept(this);
54          visit(bl.body);
55          bl.endTag.accept(this);
56      }
57  
58      /** Visit an ElementSequence. */
59      public void visit(HtmlDocument.ElementSequence s) {
60          for (Iterator iterator = s.iterator(); iterator.hasNext();) {
61              HtmlDocument.HtmlElement htmlElement = (HtmlDocument.HtmlElement) iterator.next();
62              htmlElement.accept(this);
63          }
64      }
65  
66      /** Visit an HtmlDocument. */
67      public void visit(HtmlDocument d) {
68          start();
69          visit(d.elements);
70          finish();
71      }
72  
73  
74      /** Start. */
75      public void start() {
76      }
77  
78      /** Finish. */
79      public void finish() {
80      }
81  }
82