1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.loaders;
22
23 import org.millscript.commons.alert.alerts.Fault;
24 import org.millscript.commons.xml.api.token.CharDataToken;
25 import org.millscript.commons.xml.api.token.CommentToken;
26 import org.millscript.commons.xml.api.token.EndTagToken;
27 import org.millscript.commons.xml.api.token.StartTagToken;
28 import org.millscript.millscript.datatypes.XmlComment;
29 import org.millscript.millscript.expr.ApplyExpr;
30 import org.millscript.millscript.expr.CommaExpr;
31 import org.millscript.millscript.expr.ConstantExpr;
32 import org.millscript.millscript.expr.ExplodeExpr;
33 import org.millscript.millscript.expr.NameExpr;
34
35 /**
36 * This class is used when visiting an XML element inside a basic template and
37 * it handles the tokens visited in the elements content.
38 */
39 public class BasicTemplateLoaderElementTokenVisitor extends BasicTemplateLoaderTokenVisitor {
40
41 /**
42 * Constructs a new element token visitor, with the specified
43 * controlling loader, parent token visitor and start tag.
44 *
45 * @param btl the controlling loader
46 * @param ptv the parent token visitor
47 * @param stt the start tag token
48 */
49 public BasicTemplateLoaderElementTokenVisitor( final BasicTemplateLoader btl, final BasicTemplateLoaderTokenVisitor ptv, final StartTagToken stt ) {
50 super( btl, ptv, stt );
51 }
52
53 /**
54 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.CharDataToken)
55 */
56 @Override
57 public void visit( final CharDataToken token ) {
58 if ( token.getCharData().length() == 0 ) {
59
60 throw new Fault(
61 "Appending empty character data"
62 ).mishap();
63 }
64
65 this.pushChildElement(
66 new ConstantExpr(
67 token.getCharData()
68 )
69 );
70 }
71
72 /**
73 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.CommentToken)
74 */
75 @Override
76 public void visit( final CommentToken token ) {
77 if ( token.getCommentText().length() == 0 ) {
78
79
80 throw new Fault(
81 "Appending empty comment"
82 ).mishap();
83 }
84
85
86 this.pushChildElement(
87 new ApplyExpr(
88 new NameExpr( "format" ),
89 new CommaExpr(
90 new ConstantExpr(
91 new XmlComment(
92 token.getCommentText()
93 )
94 ),
95 new ExplodeExpr(
96 new NameExpr( "arg" )
97 )
98 )
99 )
100 );
101 }
102
103 /**
104 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.EndTagToken)
105 */
106 @Override
107 public void visit( final EndTagToken token ) {
108 this.basicTemplateLoader.compileEndTag( token );
109 }
110
111 }