View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-XML: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript-XML.
6   //
7   // MillScript-XML is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-XML is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-XML; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.commons.xml.tokenizer.wellformed;
22  
23  import org.millscript.commons.xml.api.token.CharDataToken;
24  import org.millscript.commons.xml.api.token.CommentToken;
25  import org.millscript.commons.xml.api.token.DTDToken;
26  import org.millscript.commons.xml.api.token.EmptyElementToken;
27  import org.millscript.commons.xml.api.token.EndTagToken;
28  import org.millscript.commons.xml.api.token.PIToken;
29  import org.millscript.commons.xml.api.token.StartTagToken;
30  import org.millscript.commons.xml.api.token.TokenVisitor;
31  
32  /**
33   * This class provides a token visitor the for first <code>Misc</code> section
34   * part of an XML document. This is the second token visitor in a chain that
35   * provides the well formedness checks required of an XML processor.
36   */
37  public class Misc1TokenVisitor extends AbsTokenVisitor {
38  
39      /**
40       * Constructs a new <code>Misc</code> section token visitor, with the
41       * specified token visitor.
42       *
43       * @param xt    the well-formed XML tokenizer our tokens come from
44       */
45      public Misc1TokenVisitor( final WellFormedXmlTokenizer xt ) {
46          super( xt, new DTDTokenVisitor( xt ) );
47      }
48  
49      /**
50       * Constructs a new <code>Misc</code> section token visitor, with the
51       * specified tokenizer and next-in-the-chain token visitor.
52       *
53       * @param xt    the well-formed XML tokenizer our tokens come from
54       * @param tv    the next token visitor in the well-formedness chain
55       */
56      Misc1TokenVisitor( final WellFormedXmlTokenizer xt, final TokenVisitor tv ) {
57          super( xt, tv );
58      }
59  
60      /**
61       * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.CharDataToken)
62       */
63      public void visit( final CharDataToken token ) {
64          // this token is only valid in this section if it is whitespace
65          if ( token.isIgnorableWhitespace() ) {
66              // this token is valid in this section
67              this.wellFormed.nextToken = token;
68          } else {
69              // not valid in this section, check it in the next one
70              this.wellFormed.tokenVisitor = this.nextTokenVisitor;
71              token.visit( this.nextTokenVisitor );
72          }
73      }
74  
75      /**
76       * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.CommentToken)
77       */
78      public void visit( final CommentToken token ) {
79          // this token is valid in this section
80          this.wellFormed.nextToken = token;
81      }
82  
83      /**
84       * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.DTDToken)
85       */
86      public void visit( final DTDToken token ) {
87          // not valid in this section, check it in the next one
88          this.wellFormed.tokenVisitor = this.nextTokenVisitor;
89          token.visit( this.nextTokenVisitor );
90      }
91  
92      /**
93       * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.EmptyElementToken)
94       */
95      public void visit( final EmptyElementToken token ) {
96          // not valid in this section, check it in the next one
97          this.wellFormed.tokenVisitor = this.nextTokenVisitor;
98          token.visit( this.nextTokenVisitor );
99      }
100 
101     /**
102      * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.EndTagToken)
103      */
104     public void visit( final EndTagToken token ) {
105         // not valid in this section, check it in the next one
106         this.wellFormed.tokenVisitor = this.nextTokenVisitor;
107         token.visit( this.nextTokenVisitor );
108     }
109 
110     /**
111      * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.PIToken)
112      */
113     public void visit( final PIToken token ) {
114         // this token is valid in this section
115         this.wellFormed.nextToken = token;
116     }
117 
118     /**
119      * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.StartTagToken)
120      */
121     public void visit( final StartTagToken token ) {
122         // not valid in this section, check it in the next one
123         this.wellFormed.tokenVisitor = this.nextTokenVisitor;
124         token.visit( this.nextTokenVisitor );
125     }
126 
127 }