BrightSide Workbench Full Report + Source Code
org.turro.elephant.impl.util.Parser Class Reference
Inheritance diagram for org.turro.elephant.impl.util.Parser:
Collaboration diagram for org.turro.elephant.impl.util.Parser:

Public Member Functions

 Parser (String text)
 
 Parser (String text, String end)
 
void setResolver (ExternalResolver resolver)
 
String parse ()
 
String parse (IConstructor constructor)
 
String simpleParse ()
 
String parseThumb (String line)
 
String parseMacros (String line)
 
String resolve (String text)
 

Static Public Member Functions

static String toWiki (String text)
 
static void processMacros (IConstructor constructor, PrintWriter out, String text) throws ServletException, IOException
 
static String processMacroString (IConstructor constructor, String macro) throws ServletException, IOException
 
static void processMacro (IConstructor constructor, PrintWriter out, String macro) throws ServletException, IOException
 
static String escapeGrouping (String sequence)
 
static void executeExternalParsers (IConstructor constructor, PrintWriter out, String[] tokens)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 45 of file Parser.java.

Constructor & Destructor Documentation

◆ Parser() [1/2]

org.turro.elephant.impl.util.Parser.Parser ( String  text)

Creates a new instance of Parser

Parameters
text

Definition at line 53 of file Parser.java.

53  {
54  this(text, null);
55  }

◆ Parser() [2/2]

org.turro.elephant.impl.util.Parser.Parser ( String  text,
String  end 
)

Creates a new instance of Parser

Parameters
text
end

Definition at line 60 of file Parser.java.

60  {
61  int p = -1;
62  if(end != null) {
63  p = text.indexOf(end);
64  }
65  if(p > -1) {
66  buffer = new StringBuffer(text.substring(0, p));
67  }
68  else {
69  buffer = new StringBuffer(text);
70  }
71  // Correct lists
72  if(text.startsWith("$wiki\n * ") || text.startsWith("$wiki\n 1 ")) {
73  buffer.insert(6, "\n");
74  }
75  }

Member Function Documentation

◆ escapeGrouping()

static String org.turro.elephant.impl.util.Parser.escapeGrouping ( String  sequence)
static

Definition at line 241 of file Parser.java.

241  {
242  if(sequence == null || !sequence.contains("$")) return sequence;
243  StringBuilder sb = new StringBuilder(sequence);
244  int start = 0, p;
245  while((p = sb.indexOf("$", start)) > -1) {
246  sb.insert(p, '\\');
247  start = p + 2;
248  }
249  return sb.toString();
250  }
Here is the caller graph for this function:

◆ executeExternalParsers()

static void org.turro.elephant.impl.util.Parser.executeExternalParsers ( IConstructor  constructor,
PrintWriter  out,
String[]  tokens 
)
static

Definition at line 254 of file Parser.java.

254  {
255  for(IParser iParser : Instances.cached().byAnnotation(ExternalParser.class, IParser.class)) {
256  if(iParser.execute(constructor, out, tokens)) {
257  break;
258  }
259  }
260  }
Here is the caller graph for this function:

◆ parse() [1/2]

String org.turro.elephant.impl.util.Parser.parse ( )

Definition at line 86 of file Parser.java.

86  {
87  return parse(null);
88  }
Here is the caller graph for this function:

◆ parse() [2/2]

String org.turro.elephant.impl.util.Parser.parse ( IConstructor  constructor)

Definition at line 90 of file Parser.java.

90  {
91  this.constructor = constructor;
92  WikiDef wikiDef = new WikiDef();
93  if(resolver != null) wikiDef.addResolver(resolver);
94  wikiDef.addResolver(this);
95  return wikiDef.parseBuffer(buffer);
96  }

◆ parseMacros()

String org.turro.elephant.impl.util.Parser.parseMacros ( String  line)

Definition at line 132 of file Parser.java.

132  {
133  if(constructor == null || line.indexOf("macro") == -1) return line;
134  Pattern pat = Pattern.compile("macro ?\\((.*?)\\)");
135  Matcher mat = pat.matcher(line);
136  StringBuffer result = new StringBuffer();
137  String tmp;
138  while(mat.find()) {
139  tmp = I_.get(mat.group(1));
140  if(tmp == null) tmp = mat.group(1);
141  mat.appendReplacement(result, tmp);
142  }
143  mat.appendTail(result);
144  return result.toString();
145  }
Here is the call graph for this function:

◆ parseThumb()

String org.turro.elephant.impl.util.Parser.parseThumb ( String  line)

Definition at line 103 of file Parser.java.

103  {
104  if(constructor == null || line.indexOf("[thumb") == -1) return line;
105  Pattern pat = Pattern.compile("\\[thumb (.+?)\\:([0-9]+?)(\\:[RL])?\\]");
106  Matcher mat = pat.matcher(line);
107  StringBuffer result = new StringBuffer();
108  int dim = 0;
109  while(mat.find()) {
110  try {
111  dim = Integer.parseInt(mat.group(2));
112  } catch(Exception ex) {}
113  mat.appendReplacement(
114  result,
115  "<a target=\"_blank\" href=\"" + mat.group(1) + "\">" +
116  "<img border=\"0\" src=\"" +
118  new Thumbs(constructor.getRequest()).getThumb(
119  mat.group(1),
120  dim,
121  mat.group(3)
122  )
123  ) +
124  "\"/>" +
125  "</a>"
126  );
127  }
128  mat.appendTail(result);
129  return result.toString();
130  }
static String escapeGrouping(String sequence)
Definition: Parser.java:241
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processMacro()

static void org.turro.elephant.impl.util.Parser.processMacro ( IConstructor  constructor,
PrintWriter  out,
String  macro 
) throws ServletException, IOException
static

Definition at line 236 of file Parser.java.

236  {
237  String tokens[] = macro.split("(?<!\\/)(\\:)");
238  executeExternalParsers(constructor, out, tokens);
239  }
static void executeExternalParsers(IConstructor constructor, PrintWriter out, String[] tokens)
Definition: Parser.java:254
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processMacros()

static void org.turro.elephant.impl.util.Parser.processMacros ( IConstructor  constructor,
PrintWriter  out,
String  text 
) throws ServletException, IOException
static

Definition at line 200 of file Parser.java.

200  {
201  text = MacroProcessors.full().constructor(constructor).process(text);
202  if(text.indexOf("{@") > -1) {
203  text = processNestedMacros(constructor, text);
204  int p = 0, e = 0;
205  String tmp;
206  while((p = text.indexOf("{@")) > -1) {
207  e = text.indexOf('}', p + 2);
208  if(e > -1) {
209  tmp = text.substring(p + 2, e);
210  out.write(text.substring(0, p));
211  Parser.processMacro(constructor, out, tmp);
212  text = text.substring(e + 1);
213  }
214  }
215  }
216  out.write(text);
217  out.flush();
218  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processMacroString()

static String org.turro.elephant.impl.util.Parser.processMacroString ( IConstructor  constructor,
String  macro 
) throws ServletException, IOException
static

Definition at line 229 of file Parser.java.

229  {
230  StringWriter sw = new StringWriter();
231  PrintWriter pw = new PrintWriter(sw);
232  processMacro(constructor, pw, macro);
233  return sw.toString();
234  }
static void processMacro(IConstructor constructor, PrintWriter out, String macro)
Definition: Parser.java:236
Here is the call graph for this function:

◆ resolve()

String org.turro.elephant.impl.util.Parser.resolve ( String  text)

Definition at line 148 of file Parser.java.

148  {
149  if(!constructor.isInRole("inc:new")) {
150  text = text.replaceAll("\\{\\@inc", "{@---");
151  }
152  text = text.replaceAll(
153  "grepository ?\\((.*?)\\)",
154  ElephantContext.getRootResourcePath() +
155  "/_internal/repository$1"
156  );
157  if(constructor.getParameter("context") != null) {
158  text = text.replaceAll(
159  "repository ?\\((.*?)\\)",
160  ElephantContext.getRootResourcePath() +
161  constructor.getParameter("context") +
162  "/_internal/repository$1"
163  );
164  }
165  text = text.replaceAll(
166  "pubimage ?\\((.*?)\\)",
167  ElephantContext.getRootResourcePath() +
168  "/_internal/UserFiles/Image$1"
169  );
170  text = text.replaceAll(
171  "pubflash ?\\((.*?)\\)",
172  ElephantContext.getRootResourcePath() +
173  "/_internal/UserFiles/Flash$1"
174  );
175  text = text.replaceAll(
176  "download ?\\((.*?)\\)",
177  ElephantContext.getRootWebPath() + "/Download?down_path=$1"
178  );
179  text = text.replaceAll("<verbatim>", "<pre>");
180  text = text.replaceAll("</verbatim>", "</pre>");
181 // text = text.replaceAll("\\[download \\[(.*?)\\]\\[(.*?)\\]\\]", "<a href='" + context + "/Download?path=$1'>$2</a>");
182 // text = text.replaceAll("\\[download \\[(.*?)\\](.*?)\\]", "<a href='" + context + "/Download?path=$1'>$2</a>");
183  text = text.replaceAll("\\[\\[(.*?)\\]\\[(.*?)\\]\\]", "<a href='$1'>$2</a>");
184  text = text.replaceAll("\\[new\\[(.*?)\\]\\[(.*?)\\]\\]", "<a class='newwindow' target='_blank' href='$1'>$2</a>");
185  text = text.replaceAll("\\[ext\\[(.*?)\\]\\[(.*?)\\]\\]", "<a class='externallink' target='_blank' href='$1'>$2</a>");
186  text = text.replaceAll("\\[\\[(.*?)\\]\\]", "<a href='$1'>$1</a>");
187  text = text.replaceAll("\\[\\[(.*?)\\](.*?)\\]", "<a href='$1'>$2</a>");
188  text = text.replaceAll("\\[new\\[(.*?)\\](.*?)\\]", "<a class='newwindow' target='_blank' href='$1'>$2</a>");
189  text = text.replaceAll("\\[new\\[(.*?)\\]\\]", "<a class='newwindow' target='_blank' href='$1'>$1</a>");
190  text = text.replaceAll("\\[ext\\[(.*?)\\](.*?)\\]", "<a class='externallink' target='_blank' href='$1'>$2</a>");
191  text = text.replaceAll("\\[ext\\[(.*?)\\]\\]", "<a class='externallink' target='_blank' href='$1'>$1</a>");
192  text = text.replaceAll("\\[color\\((.*?)\\) (.*?)\\]", "<span style='color:$1'>$2</span>");
193  text = parseThumb(text);
194  text = text.replaceAll("\\[frame ([^,]*?),([^,]*?),(.*?)\\]", "<iframe src='$1' style='width:$2;height:$3;border:0px solid gray'></iframe>");
195  text = text.replaceAll("\\%BR\\%", "<br/>\n");
196  text = Emoticons.replaceEmoticons(constructor, text);
197  return text;
198  }
String parseThumb(String line)
Definition: Parser.java:103
Here is the call graph for this function:

◆ setResolver()

void org.turro.elephant.impl.util.Parser.setResolver ( ExternalResolver  resolver)

Definition at line 82 of file Parser.java.

82  {
83  this.resolver = resolver;
84  }
Here is the caller graph for this function:

◆ simpleParse()

String org.turro.elephant.impl.util.Parser.simpleParse ( )

Definition at line 98 of file Parser.java.

98  {
99  WikiDef wikiDef = new WikiDef();
100  return wikiDef.parseBuffer(buffer);
101  }
Here is the caller graph for this function:

◆ toWiki()

static String org.turro.elephant.impl.util.Parser.toWiki ( String  text)
static

Definition at line 77 of file Parser.java.

77  {
78  text = Jsoup.clean(text, HtmlWhitelist.wikiSafe());
79  return new HtmlParser(text).parse();
80  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: