Mercurial Hosting > luan
annotate core/src/luan/modules/HtmlLuan.java @ 427:dae264ad6a7b
fix LuanTable.put() to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 19:29:07 -0600 |
parents | 23a93c118042 |
children | d9df6d6cb927 |
rev | line source |
---|---|
167
4c0131c2b650
merge luan/lib into modules
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
142
diff
changeset
|
1 package luan.modules; |
49
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2 |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
3 import java.util.List; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
4 import java.util.ArrayList; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
5 import java.util.Arrays; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
6 import java.util.Set; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
7 import java.util.HashSet; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
8 import java.util.Map; |
221
ec016471c6eb
make LuanTable an interface
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
171
diff
changeset
|
9 import luan.Luan; |
49
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10 import luan.LuanState; |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
11 import luan.LuanTable; |
124
f537ff5e511d
minor cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
112
diff
changeset
|
12 import luan.LuanException; |
49
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
13 |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
14 |
168
ebe9db183eb7
rename *Lib.java to *Luan.java
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
167
diff
changeset
|
15 public final class HtmlLuan { |
49
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
16 |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
17 public static String encode(LuanState luan,String s) throws LuanException { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
18 Utils.checkNotNull(luan,s); |
49
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
19 char[] a = s.toCharArray(); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
20 StringBuilder buf = new StringBuilder(); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
21 for( int i=0; i<a.length; i++ ) { |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
22 char c = a[i]; |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
23 switch(c) { |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
24 case '&': |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
25 buf.append("&"); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
26 break; |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
27 case '<': |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
28 buf.append("<"); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
29 break; |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
30 case '>': |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
31 buf.append(">"); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
32 break; |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
33 case '"': |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
34 buf.append("""); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
35 break; |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
36 default: |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
37 buf.append(c); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
38 } |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
39 } |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
40 return buf.toString(); |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
41 } |
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
42 |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
43 /* |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
44 // public static final String TEXTAREA = "textarea"; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
45 public static final String SCRIPT = "script"; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
46 public static final String STYLE = "style"; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
47 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
48 public static Set<String> containerTags = new HashSet<String>(Arrays.asList(SCRIPT,STYLE)); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
49 */ |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
50 public static LuanTable parse(LuanState luan,String text,LuanTable containerTagsTbl) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
51 throws LuanException |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
52 { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
53 Utils.checkNotNull(luan,text); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
54 Utils.checkNotNull(luan,containerTagsTbl); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
55 Set<String> containerTags = new HashSet<String>(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
56 for( Object v : containerTagsTbl.asList() ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
57 containerTags.add((String)v); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
58 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
59 List<Object> html = new ArrayList<Object>(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
60 int len = text.length(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
61 int i = 0; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
62 outer: |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
63 while( i < len ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
64 int i2 = text.indexOf('<',i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
65 while( i2 != -1 && i2+1 < len ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
66 char c = text.charAt(i2+1); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
67 if( Character.isLetter(c) || c=='/' || c=='!' ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
68 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
69 i2 = text.indexOf('<',i2+1); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
70 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
71 if( i2 == -1 ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
72 html.add( text.substring(i) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
73 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
74 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
75 if( i < i2 ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
76 html.add( text.substring(i,i2) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
77 if( text.startsWith("<!--",i2) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
78 i = text.indexOf("-->",i2+4); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
79 if( i == -1 ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
80 html.add( text.substring(i2) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
81 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
82 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
83 html.add( comment( text.substring(i2+4,i) ) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
84 i += 3; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
85 } else if( text.startsWith("<![CDATA[",i2) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
86 i = text.indexOf("]]>",i2+9); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
87 if( i == -1 ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
88 html.add( text.substring(i2) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
89 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
90 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
91 html.add( cdata( text.substring(i2+9,i) ) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
92 i += 3; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
93 } else { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
94 i = text.indexOf('>',i2); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
95 if( i == -1 ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
96 html.add( text.substring(i2) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
97 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
98 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
99 String tagText = text.substring(i2+1,i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
100 try { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
101 LuanTable tag = parseTag(tagText); |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
102 String tagName = (String)tag.rawGet("name"); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
103 if( containerTags.contains(tagName) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
104 i2 = i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
105 String endTagName = '/' + tagName; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
106 while(true) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
107 i2 = text.indexOf('<',i2+1); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
108 if( i2 == -1 ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
109 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
110 int i3 = text.indexOf('>',i2); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
111 if( i3 == -1 ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
112 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
113 int j = i2+1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
114 while( j<i3 && !Character.isWhitespace(text.charAt(j)) ) j++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
115 String s = text.substring(i2+1,j); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
116 if( s.equalsIgnoreCase(endTagName) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
117 String text2 = text.substring(i+1,i2); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
118 LuanTable textContainer = textContainer(tag,text2); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
119 html.add( textContainer ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
120 i = i3 + 1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
121 continue outer; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
122 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
123 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
124 // logger.warn("unclosed "+tagName); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
125 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
126 i += 1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
127 html.add( tag ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
128 } catch(BadTag e) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
129 // logger.debug("bad tag",e); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
130 i += 1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
131 // if( !removeBadTags ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
132 html.add( "<" ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
133 html.add( encode(luan,tagText) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
134 html.add( ">" ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
135 // } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
136 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
137 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
138 } |
411
23b99a5039b5
remove Luan.newTable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
318
diff
changeset
|
139 return new LuanTable(html); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
140 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
141 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
142 static LuanTable comment(String text) { |
411
23b99a5039b5
remove Luan.newTable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
318
diff
changeset
|
143 LuanTable tbl = new LuanTable(); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
144 tbl.rawPut("type","comment"); |
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
145 tbl.rawPut("text",text); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
146 return tbl; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
147 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
148 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
149 static LuanTable cdata(String text) { |
411
23b99a5039b5
remove Luan.newTable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
318
diff
changeset
|
150 LuanTable tbl = new LuanTable(); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
151 tbl.rawPut("type","cdata"); |
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
152 tbl.rawPut("text",text); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
153 return tbl; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
154 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
155 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
156 static LuanTable textContainer(LuanTable tag,String text) { |
411
23b99a5039b5
remove Luan.newTable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
318
diff
changeset
|
157 LuanTable tbl = new LuanTable(); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
158 tbl.rawPut("type","container"); |
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
159 tbl.rawPut("tag",tag); |
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
160 tbl.rawPut("text",text); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
161 return tbl; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
162 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
163 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
164 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
165 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
166 static final class BadTag extends RuntimeException { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
167 private BadTag(String msg) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
168 super(msg); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
169 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
170 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
171 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
172 static LuanTable parseTag(String text) { |
411
23b99a5039b5
remove Luan.newTable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
318
diff
changeset
|
173 LuanTable tbl = new LuanTable(); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
174 tbl.rawPut("type","tag"); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
175 if( text.endsWith("/") ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
176 text = text.substring(0,text.length()-1); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
177 tbl.rawPut("is_empty",true); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
178 } else { |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
179 tbl.rawPut("is_empty",false); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
180 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
181 int len = text.length(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
182 int i = 0; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
183 int i2 = i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
184 if( i2<len && text.charAt(i2)=='/' ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
185 i2++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
186 while( i2<len ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
187 char c = text.charAt(i2); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
188 if( Character.isWhitespace(c) ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
189 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
190 if( !( Character.isLetterOrDigit(c) || c=='_' || c=='.' || c=='-' || c==':' ) ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
191 throw new BadTag("invalid tag name for <"+text+">"); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
192 i2++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
193 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
194 String name = text.substring(i,i2).toLowerCase(); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
195 tbl.rawPut("name",name); |
411
23b99a5039b5
remove Luan.newTable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
318
diff
changeset
|
196 LuanTable attributes = new LuanTable(); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
197 tbl.rawPut("attributes",attributes); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
198 i = i2; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
199 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
200 while( i<len ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
201 i2 = toEndName(text,i,len); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
202 String attrName = unquote(text.substring(i,i2).toLowerCase()); |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
203 if( attributes.rawGet(attrName) != null ) |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
204 throw new BadTag("duplicate attribute: "+attrName); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
205 i = i2; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
206 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
207 if( i<len && text.charAt(i) == '=' ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
208 i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
209 i2 = i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
210 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
211 i2 = toEndValue(text,i,len); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
212 String attrValue = text.substring(i,i2); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
213 if( attrValue.indexOf('<') != -1 || attrValue.indexOf('>') != -1 ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
214 throw new BadTag("invalid attribute value: "+attrValue); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
215 attrValue = unquote(attrValue); |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
216 attributes.rawPut(attrName,attrValue); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
217 i = i2; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
218 while( i<len && Character.isWhitespace(text.charAt(i)) ) i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
219 } else { |
427
dae264ad6a7b
fix LuanTable.put() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
426
diff
changeset
|
220 attributes.rawPut(attrName,true); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
221 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
222 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
223 return tbl; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
224 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
225 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
226 private static int toEndName(String text,int i,int len) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
227 if( i==len ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
228 return i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
229 char c = text.charAt(i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
230 switch(c) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
231 case '"': |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
232 case '\'': |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
233 i = text.indexOf(c,i+1); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
234 return i==-1 ? len : i+1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
235 default: |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
236 if( Character.isWhitespace(c) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
237 throw new RuntimeException("text="+text+" i="+i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
238 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
239 do { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
240 i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
241 } while( i<len && (c=text.charAt(i))!='=' && !Character.isWhitespace(c) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
242 return i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
243 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
244 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
245 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
246 private static int toEndValue(String text,int i,int len) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
247 if( i==len ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
248 return i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
249 char c = text.charAt(i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
250 switch(c) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
251 case '"': |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
252 case '\'': |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
253 i = text.indexOf(c,i+1); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
254 return i==-1 ? len : i+1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
255 default: |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
256 if( Character.isWhitespace(c) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
257 throw new RuntimeException("text="+text+" i="+i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
258 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
259 do { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
260 i++; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
261 } while( i<len && !Character.isWhitespace(text.charAt(i)) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
262 return i; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
263 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
264 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
265 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
266 public static String unquote(String s) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
267 if( s==null || s.length()<=1 ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
268 return s; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
269 char c = s.charAt(0); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
270 return (c=='"' || c=='\'') && s.charAt(s.length()-1)==c |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
271 ? s.substring(1,s.length()-1) : s; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
272 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
273 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
274 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
275 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
276 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
277 public static String to_string(LuanState luan,LuanTable tbl) throws LuanException { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
278 List<Object> html = tbl.asList(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
279 StringBuilder buf = new StringBuilder(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
280 for( Object o : html ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
281 if( o instanceof String ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
282 buf.append( o ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
283 } else if( o instanceof LuanTable ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
284 LuanTable t = (LuanTable)o; |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
285 String type = (String)t.get(luan,"type"); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
286 if( type==null ) |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
287 throw luan.exception( "no type in element of table for 'Html.to_string'" ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
288 if( type.equals("comment") ) { |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
289 buf.append( "<!--" ).append( t.get(luan,"text") ).append( "-->" ); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
290 } else if( type.equals("cdata") ) { |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
291 buf.append( "<![CDATA[" ).append( t.get(luan,"text") ).append( "]]" ); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
292 } else if( type.equals("tag") ) { |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
293 buf.append( tagToString(luan,t) ); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
294 } else if( type.equals("container") ) { |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
295 LuanTable tag = (LuanTable)t.get(luan,"tag"); |
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
296 buf.append( tagToString(luan,tag) ); |
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
297 buf.append( t.get(luan,"text") ); |
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
298 buf.append( "</" ).append( tag.get(luan,"name") ).append( ">" ); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
299 } else { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
300 throw luan.exception( "invalid element type for 'Html.to_string'" ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
301 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
302 } else |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
303 throw luan.exception( "invalid value ("+Luan.type(o)+") in table for 'Html.to_string'" ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
304 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
305 return buf.toString(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
306 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
307 |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
308 private static String tagToString(LuanState luan,LuanTable tbl) throws LuanException { |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
309 StringBuilder buf = new StringBuilder(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
310 buf.append('<'); |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
311 buf.append(tbl.get(luan,"name")); |
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
312 LuanTable attributes = (LuanTable)tbl.get(luan,"attributes"); |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
313 for( Map.Entry<Object,Object> attr : attributes ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
314 buf.append( ' ' ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
315 buf.append( attr.getKey() ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
316 Object val = attr.getValue(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
317 if( !val.equals(Boolean.TRUE) ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
318 buf.append( '=' ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
319 buf.append( quote((String)val) ); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
320 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
321 } |
426
23a93c118042
fix LuanTable.get() to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents:
411
diff
changeset
|
322 if( tbl.get(luan,"is_empty").equals(Boolean.TRUE) ) |
318
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
323 buf.append('/'); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
324 buf.append('>'); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
325 return buf.toString(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
326 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
327 |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
328 public static String quote(String s) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
329 StringBuilder buf = new StringBuilder(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
330 buf.append('"'); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
331 int i = 0; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
332 while(true) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
333 int i2 = s.indexOf('"',i); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
334 if( i2 == -1 ) { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
335 buf.append(s.substring(i)); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
336 break; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
337 } else { |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
338 buf.append(s.substring(i,i2)); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
339 buf.append("""); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
340 i = i2 + 1; |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
341 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
342 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
343 buf.append('"'); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
344 return buf.toString(); |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
345 } |
4fe6c9fed486
add html processing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
302
diff
changeset
|
346 |
49
8ede219cd111
add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
347 } |