1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.xml.tokenizer.wellformed;
22
23 import org.millscript.commons.xml.alerts.XmlWellFormednessAlert;
24 import org.millscript.commons.xml.api.token.CharDataToken;
25 import org.millscript.commons.xml.api.token.EmptyElementToken;
26 import org.millscript.commons.xml.api.token.EndTagToken;
27 import org.millscript.commons.xml.api.token.StartTagToken;
28
29 /**
30 * This class provides a token visitor the for third <code>Misc</code> section
31 * part of an XML document. This is the sixth token visitor in a chain that
32 * provides the well formedness checks required of an XML processor.
33 */
34 public class Misc3TokenVisitor extends Misc2TokenVisitor {
35
36 /**
37 * Constructs a new <code>Misc</code> section token visitor, with the
38 * specified token visitor.
39 *
40 * @param xt the well-formed XML tokenizer our tokens come from
41 */
42 public Misc3TokenVisitor( final WellFormedXmlTokenizer xt ) {
43
44
45
46 super( xt, null );
47 }
48
49 /**
50 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.CharDataToken)
51 */
52 @Override
53 public void visit( final CharDataToken token ) {
54
55 if ( token.isIgnorableWhitespace() ) {
56
57 this.wellFormed.nextToken = token;
58 } else {
59
60 throw new XmlWellFormednessAlert(
61 "Character data must not appear after the document element"
62 ).decorate( token ).mishap();
63 }
64 }
65
66 /**
67 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.EmptyElementToken)
68 */
69 @Override
70 public void visit( final EmptyElementToken token ) {
71 throw new XmlWellFormednessAlert(
72 "An XML document can only have a single document element"
73 ).decorate( token ).mishap();
74 }
75
76 /**
77 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.EndTagToken)
78 */
79 @Override
80 public void visit( final EndTagToken token ) {
81 throw new XmlWellFormednessAlert(
82 "An XML document can only have a single document element"
83 ).decorate( token ).mishap();
84 }
85
86 /**
87 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.StartTagToken)
88 */
89 @Override
90 public void visit( final StartTagToken token ) {
91 throw new XmlWellFormednessAlert(
92 "An XML document can only have a single document element"
93 ).decorate( token ).mishap();
94 }
95
96 }