annotate src/goodjava/bbcode/BBCode.java @ 1711:05d14db623b6

add bbcodes
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2022 21:50:41 -0600
parents a6e27c8e7ef4
children 36c28be6d432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
1 package goodjava.bbcode;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
3 import java.util.List;
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
4 import java.util.ArrayList;
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
5 import java.util.Map;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
6 import java.util.LinkedHashMap;
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
7 import java.util.regex.Matcher;
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
8 import java.util.regex.Pattern;
1402
27efb1fcbcb5 move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents: 1335
diff changeset
9 import goodjava.parser.Parser;
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
10
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 public final class BBCode {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
14 public final class Element {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
15 public final String name;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
16 public final String param;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
17 public final Object contents; // String, Element, or List
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
18 public final Map<String,String> extra;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
19
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
20 private Element(String name,Object contents) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
21 this(name,null,contents);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
22 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
24 private Element(String name,String param,Object contents) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
25 this(name,param,contents,null);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
26 }
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
27
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
28 private Element(String name,String param,Object contents,Map<String,String> extra) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
29 this.name = name.toLowerCase();
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
30 this.param = param;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
31 this.contents = contents;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
32 this.extra = extra;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
33 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
36 public static Object parse(String text) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
37 if( text.indexOf('[') == -1 )
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
38 return text;
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
39 return new BBCode(text).parse();
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
40 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
42 private final Parser parser;
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
43
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
44 private BBCode(String text) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 this.parser = new Parser(text);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
48 private Object parse() {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
49 List list = new ArrayList();
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
50 StringBuilder text = new StringBuilder();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 while( !parser.endOfInput() ) {
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
52 Element block = parseBlock(false);
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
53 if( block != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
54 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
55 list.add( block );
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
56 } else {
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
57 text.append( parser.currentChar() );
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 parser.anyChar();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 }
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
61 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
62 return list.size()==1 ? list.get(0) : list;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
65 private Object parseUntil(String end) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
66 return parseUntil(end,false);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
67 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
68
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
69 private Object parseUntil(String end,boolean inList) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
70 List list = new ArrayList();
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
71 StringBuilder text = new StringBuilder();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
72 while( !parser.matchIgnoreCase(end) ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
73 if( parser.endOfInput() )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
74 return null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
75 Element block = parseBlock(inList);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 if( block != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
77 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
78 list.add( block );
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
79 } else {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
80 text.append( parser.currentChar() );
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
81 parser.anyChar();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 }
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
84 add(list,text);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
85 return list.size()==1 ? list.get(0) : list;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
88 private void add(List list,StringBuilder text) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
89 if( text.length() > 0 ) {
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
90 list.add( text.toString() );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
91 text.setLength(0);
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
92 }
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
93 }
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
94
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
95 private Element parseBlock(boolean inList) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 if( parser.currentChar() != '[' )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 return null;
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
98 Element s;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 s = parseB(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 s = parseI(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 s = parseU(); if(s!=null) return s;
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
102 s = parseS(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
103 s = parseSup(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
104 s = parseBrackets(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
105 s = parseUrl(); if(s!=null) return s;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 s = parseCode(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 s = parseImg(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 s = parseColor(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 s = parseSize(); if(s!=null) return s;
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
110 s = parseVideo(); if(s!=null) return s;
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
111 s = parseQuote(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
112 s = parseUl(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
113 s = parseOl(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
114 if( inList ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
115 s = parseLi(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
116 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 return null;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
120 private Element parseB() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 if( !parser.matchIgnoreCase("[b]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
124 Object content = parseUntil("[/b]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
125 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
127 Element rtn = new Element("b",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
131 private Element parseI() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 if( !parser.matchIgnoreCase("[i]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
135 Object content = parseUntil("[/i]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
136 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
138 Element rtn = new Element("i",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
142 private Element parseU() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 if( !parser.matchIgnoreCase("[u]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
146 Object content = parseUntil("[/u]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
147 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
149 Element rtn = new Element("u",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
153 private Element parseS() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
155 if( !parser.matchIgnoreCase("[s]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
156 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
157 Object content = parseUntil("[/s]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
158 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
160 Element rtn = new Element("s",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
161 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
162 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
163
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
164 private Element parseSup() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
165 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
166 if( !parser.matchIgnoreCase("[sup]") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
168 Object content = parseUntil("[/sup]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
169 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
170 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
171 Element rtn = new Element("sup",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
175 private Element parseBrackets() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
177 if( !parser.matchIgnoreCase("[brackets]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
178 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
179 Object content = parseUntil("[/brackets]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
180 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
181 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
182 Element rtn = new Element("brackets",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
183 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
184 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
185
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
186 private Element parseUrl() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
187 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
188 if( !parser.matchIgnoreCase("[url") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
190 String url;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
191 Object content;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
192 if( parser.match(']') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
193 url = parseRealUrl();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
194 content = null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
195 if( !parser.matchIgnoreCase("[/url]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
196 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
197 } else if( parser.match('=') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
198 url = parseRealUrl();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
199 if( !parser.match(']') )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
200 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
201 content = parseUntil("[/url]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
202 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
203 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
204 } else
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
206 Element rtn = new Element("url",url,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210 private String parseRealUrl() {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
211 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
212 while( parser.match(' ') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
214 if( !parser.matchIgnoreCase("http") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
215 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
216 parser.matchIgnoreCase("s");
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217 if( !parser.matchIgnoreCase("://") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219 while( parser.noneOf(" []'") );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220 String url = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
221 while( parser.match(' ') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
222 return parser.success(url);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
225 private Element parseCode() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
227 String param;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
228 String end;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
229 if( !parser.matchIgnoreCase("[code") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
230 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
231 if( parser.match(']') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
232 param = null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
233 end = "[/code]";
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
234 } else if( parser.match('=') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
235 int start = parser.currentIndex();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
236 while( parser.noneOf("[]") );
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
237 param = parser.textFrom(start);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
238 if( !parser.match(']') )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
239 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
240 end = "[/code=" + param + "]";
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
241 } else
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
242 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
243 int start = parser.currentIndex();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
244 while( !parser.testIgnoreCase(end) ) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
245 if( !parser.anyChar() )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
247 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
248 String content = parser.textFrom(start);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
249 if( !parser.matchIgnoreCase(end) ) throw new RuntimeException();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
250 Element rtn = new Element("code",param,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
251 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
252 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
253
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
254 private Element parseImg() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256 if( !parser.matchIgnoreCase("[img]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
257 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
258 String url = parseRealUrl();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259 if( !parser.matchIgnoreCase("[/img]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
261 Element rtn = new Element("img",url);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
265 private Element parseColor() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
266 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267 if( !parser.matchIgnoreCase("[color=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
269 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270 parser.match('#');
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
271 while( parser.inCharRange('0','9')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
272 || parser.inCharRange('a','z')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273 || parser.inCharRange('A','Z')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274 );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
275 String color = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
278 Object content = parseUntil("[/color]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
279 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
280 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
281 Element rtn = new Element("color",color,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
283 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
284
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
285 private Element parseSize() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
286 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
287 if( !parser.matchIgnoreCase("[size=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
289 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290 while( parser.match('.') || parser.inCharRange('0','9') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
291 String size = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
293 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
294 Object content = parseUntil("[/size]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
295 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
296 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
297 Element rtn = new Element("size",size,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
298 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
299 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
300
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
301 private static final Pattern youtubePtn1 = Pattern.compile("https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?");
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
302 private static final Pattern youtubePtn2 = Pattern.compile("https://www.youtube.com/watch?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?");
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
303 private static final Pattern bitchutePtn = Pattern.compile("https://www.bitchute.com/video/([a-zA-Z0-9]+)/");
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
304
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
305 private static Matcher find(Pattern ptn,String s) {
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
306 Matcher m = ptn.matcher(s);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
307 return m.find() ? m : null;
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
308 }
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
309
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
310 private Element parseVideo() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
311 parser.begin();
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
312 if( !parser.matchIgnoreCase("[video]") )
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
313 return parser.failure(null);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
314 String url = parseRealUrl();
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
315 if( !parser.matchIgnoreCase("[/video]") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
316 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
317 Map<String,String> extra = new LinkedHashMap<String,String>();
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
318 Element rtn = new Element("video",null,url,extra);
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
319 Matcher m;
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
320 m = find(youtubePtn1,url);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
321 if( m == null )
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
322 m = find(youtubePtn2,url);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
323 if( m != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
324 extra.put( "site", "youtube" );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
325 extra.put( "id", m.group(1) );
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
326 String t = m.group(2);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
327 if( t != null )
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
328 extra.put( "start", t );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
329 return parser.success(rtn);
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
330 }
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
331 m = find(bitchutePtn,url);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
332 if( m != null ) {
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
333 extra.put( "site", "bitchute" );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
334 extra.put( "id", m.group(1) );
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
335 return parser.success(rtn);
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
336 }
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
337 return parser.success(rtn);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
338 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
339
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
340
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
341 private Element parseQuote() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
342 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
343 if( !parser.matchIgnoreCase("[quote") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
345 String name;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
346 if( parser.match(']') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
347 name = null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
348 } else if( parser.match('=') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
349 int start = parser.currentIndex();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
350 while( parser.noneOf("[]") );
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
351 name = parser.textFrom(start).trim();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
352 if( !parser.match(']') )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
353 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
354 } else
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
355 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
356 Object content = parseUntil("[/quote]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
357 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
358 return parser.failure(null);
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
359 Element rtn = new Element("quote",name,content);
637
6ea90dc10375 bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents: 588
diff changeset
360 return parser.success(rtn);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
361 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
362
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
363
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
364 private Element parseUl() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
365 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
366 if( !parser.matchIgnoreCase("[ul]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
367 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
368 Object content = parseUntil("[/ul]",true);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
369 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
370 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
371 Element rtn = new Element("ul",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
372 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
373 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
374
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
375 private Element parseOl() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
376 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
377 if( !parser.matchIgnoreCase("[ol]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
378 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
379 Object content = parseUntil("[/ol]",true);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
380 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
381 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
382 Element rtn = new Element("ol",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
383 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
384 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
385
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
386 private Element parseLi() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
387 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
388 if( !parser.matchIgnoreCase("[li]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
389 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
390 Object content = parseUntil("[/li]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
391 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
392 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
393 Element rtn = new Element("li",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
394 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
395 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
396
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
397 }