annotate src/luan/modules/parsers/Html.java @ 1330:f41919741100

fix security
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 11 Feb 2019 01:38:55 -0700
parents 8d54bcc0b6d3
children 25746915a241
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package luan.modules.parsers;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.util.List;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.util.ArrayList;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import java.util.Set;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import java.util.HashSet;
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
7 import luan.LuanState;
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 import luan.LuanTable;
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
9 import luan.LuanException;
1111
88b5b81cad4a move Parser to luan.lib.parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
10 import luan.lib.parser.Parser;
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 public final class Html {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
1289
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
15 public static LuanTable toList(LuanState luan,String text,LuanTable containerTagsTbl) {
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
16 try {
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
17 return new Html(luan,text,containerTagsTbl).parse();
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
18 } catch(LuanException e) {
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
19 throw new RuntimeException(e);
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
20 }
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
23 private final LuanState luan;
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 private final Parser parser;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 private final Set<String> containerTags = new HashSet<String>();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
27 private Html(LuanState luan,String text,LuanTable containerTagsTbl) {
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
28 this.luan = luan;
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 this.parser = new Parser(text);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 for( Object v : containerTagsTbl.asList() ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 containerTags.add((String)v);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
35 private LuanTable parse() throws LuanException {
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 List list = new ArrayList();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 StringBuilder sb = new StringBuilder();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 while( !parser.endOfInput() ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 if( parser.test('<') ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 LuanTable tbl = parseTag();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 if( tbl != null ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 String tagName = (String)tbl.rawGet("name");
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 if( containerTags.contains(tagName) ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 LuanTable container = parseContainer(tbl);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 if( container != null )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 tbl = container;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 if( tbl != null
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 || (tbl = parseComment()) != null
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 || (tbl = parseCdata()) != null
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 if( sb.length() > 0 ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 list.add(sb.toString());
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 sb.setLength(0);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 list.add(tbl);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 continue;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 sb.append( parser.currentChar() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 parser.anyChar();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 if( sb.length() > 0 )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 list.add(sb.toString());
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
66 return new LuanTable(luan,list);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
69 private LuanTable parseComment() throws LuanException {
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 parser.begin();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 if( !parser.match("<!--") )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 int start = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 while( !parser.test("-->") ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 if( !parser.anyChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 String text = parser.textFrom(start);
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
79 LuanTable tbl = new LuanTable(luan);
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
80 tbl.put("type","comment");
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
81 tbl.put("text",text);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 return parser.success(tbl);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
85 private LuanTable parseCdata() throws LuanException {
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 parser.begin();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 if( !parser.match("<![CDATA[") )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 int start = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 while( !parser.test("]]>") ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 if( !parser.anyChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 String text = parser.textFrom(start);
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
95 LuanTable tbl = new LuanTable(luan);
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
96 tbl.put("type","cdata");
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
97 tbl.put("text",text);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 return parser.success(tbl);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
101 private LuanTable parseContainer(LuanTable tag) throws LuanException {
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102 String endTagName = '/' + (String)tag.rawGet("name");
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 int start = parser.begin();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 int end;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 while(true) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 if( parser.test('<') ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 end = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 LuanTable tag2 = parseTag();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 String s = (String)tag2.rawGet("name");
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 if( s.equals(endTagName) )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111 break;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 if( !parser.anyChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 String text = parser.text.substring(start,end);
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
117 LuanTable tbl = new LuanTable(luan);
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
118 tbl.put("type","container");
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
119 tbl.put("tag",tag);
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
120 tbl.put("text",text);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 return parser.success(tbl);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
124 private LuanTable parseTag() throws LuanException {
1289
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
125 LuanTable tbl = new LuanTable(luan);
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
126 tbl.put("type","tag");
1279
323743a7f317 add html tag.raw
Franklin Schmidt <fschmidt@gmail.com>
parents: 1267
diff changeset
127 int tagStart = parser.begin();
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 if( !parser.match('<') )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 int start = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 parser.match('/');
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 if( !matchNameChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 while( matchNameChar() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 String name = parser.textFrom(start).toLowerCase();
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
136 tbl.put("name",name);
1267
9fa8b8389578 add LuanTable.luan;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
137 LuanTable attributes = new LuanTable(luan);
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
138 tbl.put("attributes",attributes);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 String attrName;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 while( (attrName = parseAttrName()) != null ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 String attrValue = parseAttrValue();
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
142 attributes.put( attrName, attrValue!=null ? attrValue : true );
1289
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
143 if( attrName.equals("style") && attrValue!=null ) {
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
144 LuanTable style = Css.style(luan,attrValue);
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
145 if( style!=null )
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
146 tbl.put("style",style);
1289
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
147 }
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 while( matchSpace() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 boolean isEmpty = parser.match('/');
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
151 tbl.put("is_empty",isEmpty);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 if( !parser.match('>') )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 return parser.failure(null);
1279
323743a7f317 add html tag.raw
Franklin Schmidt <fschmidt@gmail.com>
parents: 1267
diff changeset
154 String raw = parser.textFrom(tagStart);
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1289
diff changeset
155 tbl.put("raw",raw);
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 return parser.success(tbl);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 private String parseAttrName() {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 parser.begin();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 if( !matchSpace() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 while( matchSpace() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 int start = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 if( !matchNameChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 while( matchNameChar() );
1289
8d54bcc0b6d3 add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 1279
diff changeset
168 String name = parser.textFrom(start).toLowerCase();
625
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 return parser.success(name);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 private String parseAttrValue() {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 parser.begin();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 while( matchSpace() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 if( !parser.match('=') )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 while( matchSpace() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178 if( parser.anyOf("\"'") ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 char quote = parser.lastChar();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 int start = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 while( !parser.test(quote) ) {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 if( !parser.anyChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 String value = parser.textFrom(start);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186 parser.match(quote);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187 return parser.success(value);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189 int start = parser.currentIndex();
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 if( !matchValueChar() )
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191 return parser.failure(null);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192 while( matchValueChar() );
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193 String value = parser.textFrom(start);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 return parser.success(value);
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 private boolean matchNameChar() {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198 return parser.inCharRange('a','z')
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 || parser.inCharRange('A','Z')
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200 || parser.inCharRange('0','9')
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201 || parser.anyOf("_.-:")
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202 ;
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205 private boolean matchValueChar() {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206 return parser.noneOf(" \t\r\n\"'>/=");
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209 private boolean matchSpace() {
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210 return parser.anyOf(" \t\r\n");
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
211 }
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
212
a3c1e11fb6aa rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213 }