[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/filter WikipediaFilter.java,1.6,1.7
Status: Pre-Alpha
Brought to you by:
jsurfer
|
From: Klaus H. <js...@us...> - 2004-04-14 20:06:34
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22664/WEB-INF/src/org/hartmath/server/filter Modified Files: WikipediaFilter.java Log Message: misc changes Index: WikipediaFilter.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/WikipediaFilter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WikipediaFilter.java 2 Apr 2004 18:12:13 -0000 1.6 --- WikipediaFilter.java 14 Apr 2004 20:06:24 -0000 1.7 *************** *** 61,67 **** public class WikipediaFilter extends FilterSupport implements CacheFilter, IWikipediaFilterConstants { - private FilterContext fContext; - private RenderEngine fWikiEngine; - private Snip fSnip; public class InvalidInputException extends Exception { --- 61,64 ---- *************** *** 77,80 **** --- 74,80 ---- public class Parser { + private FilterContext fContext; + private RenderEngine fWikiEngine; + private Snip fSnip; public static final String INVALID_CHAR_IN_PLUGIN_IDENTIFIER = "Invalid_Char_In_Plugin_Identifier"; *************** *** 110,114 **** // table of content private ArrayList fToC = null; ! public Parser(String stringSource, StringBuffer result, int recursionLevel) { fResult = result; fStringSource = stringSource; --- 110,122 ---- // table of content private ArrayList fToC = null; ! public Parser(String stringSource, StringBuffer result, FilterContext context, int recursionLevel) { ! fContext = context; ! fWikiEngine = context.getRenderContext().getRenderEngine(); ! try { ! SnipMacroParameter params = (SnipMacroParameter) fContext.getMacroParameter(); ! fSnip = params.getSnipRenderContext().getSnip(); ! } catch (ClassCastException e) { ! e.printStackTrace(); ! } fResult = result; fStringSource = stringSource; *************** *** 151,214 **** private void copyWhite(boolean whiteStart, final int whiteStartPosition, final int diff) { if (whiteStart) { ! final int len = fCurrentPosition - whiteStartPosition - diff; ! // char[] whiteChars = new char[len]; ! char ch; ! int indx = whiteStartPosition; ! while (indx < whiteStartPosition + len) { ! ch = fSource[indx++]; ! switch (ch) { ! // TODO activate if macros are integrated correctly case '<' : // special html escape character ! fResult.append(Encoder.toEntity('<')); break; case '>' : // special html escape character ! fResult.append(Encoder.toEntity('>')); break; case '&' : // special html escape character ! fResult.append(Encoder.toEntity('&')); break; case '\'' : // special html escape character ! fResult.append(Encoder.toEntity('\'')); break; case '\"' : // special html escape character ! fResult.append(Encoder.toEntity('\"')); break; - default : - fResult.append(ch); } } fWhiteStart = false; - // fResult.append(fSource, whiteStartPosition, currentPosition - whiteStartPosition - diff); } } private void copyWhite(String text) { ! char ch; ! for (int i = 0; i < text.length(); i++) { ! ch = text.charAt(i); ! switch (ch) { case '<' : // special html escape character ! fResult.append(Encoder.toEntity('<')); break; case '>' : // special html escape character ! fResult.append(Encoder.toEntity('>')); break; case '&' : // special html escape character ! fResult.append(Encoder.toEntity('&')); break; case '\'' : // special html escape character ! fResult.append(Encoder.toEntity('\'')); break; case '\"' : // special html escape character ! fResult.append(Encoder.toEntity('\"')); break; - default : - fResult.append(ch); } } } /** ! * Render the MTML token which are defined in the OPNE_TAGS and CLOSE_TAGS map * * @return --- 159,315 ---- private void copyWhite(boolean whiteStart, final int whiteStartPosition, final int diff) { if (whiteStart) { ! final int len = fCurrentPosition - diff; ! int currentIndex = whiteStartPosition; ! int lastIndex = currentIndex; ! while (currentIndex < len) { ! switch (fSource[currentIndex++]) { case '<' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(fSource, lastIndex, currentIndex - lastIndex - 1); ! lastIndex = currentIndex; ! } ! fResult.append("<"); break; case '>' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(fSource, lastIndex, currentIndex - lastIndex - 1); ! lastIndex = currentIndex; ! } ! fResult.append(">"); break; case '&' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(fSource, lastIndex, currentIndex - lastIndex - 1); ! lastIndex = currentIndex; ! } ! fResult.append("&"); break; case '\'' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(fSource, lastIndex, currentIndex - lastIndex - 1); ! lastIndex = currentIndex; ! } ! fResult.append("'"); break; case '\"' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(fSource, lastIndex, currentIndex - lastIndex - 1); ! lastIndex = currentIndex; ! } ! fResult.append("""); break; } } + if (lastIndex < (currentIndex)) { + fResult.append(fSource, lastIndex, currentIndex - lastIndex); + } fWhiteStart = false; } } private void copyWhite(String text) { ! final int len = text.length(); ! int currentIndex = 0; ! int lastIndex = currentIndex; ! while (currentIndex < len) { ! switch (text.charAt(currentIndex++)) { case '<' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); ! lastIndex = currentIndex; ! } ! fResult.append("<"); break; case '>' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); ! lastIndex = currentIndex; ! } ! fResult.append(">"); break; case '&' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); ! lastIndex = currentIndex; ! } ! fResult.append("&"); break; case '\'' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); ! lastIndex = currentIndex; ! } ! fResult.append("'"); break; case '\"' : // special html escape character ! if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); ! lastIndex = currentIndex; ! } ! fResult.append("""); break; } } + if (lastIndex < (currentIndex)) { + fResult.append(text.substring(lastIndex, currentIndex)); + } } + private void copyWhiteNewLine(String text) { + final int len = text.length(); + int currentIndex = 0; + int lastIndex = currentIndex; + while (currentIndex < len) { + switch (text.charAt(currentIndex++)) { + case '\n' : + if (lastIndex < (currentIndex - 1)) { + fResult.append(text.substring(lastIndex, currentIndex-1)); + lastIndex = currentIndex; + } + fResult.append("<br/>"); + break; + case '<' : // special html escape character + if (lastIndex < (currentIndex - 1)) { + fResult.append(text.substring(lastIndex, currentIndex-1)); + lastIndex = currentIndex; + } + fResult.append("<"); + break; + case '>' : // special html escape character + if (lastIndex < (currentIndex - 1)) { + fResult.append(text.substring(lastIndex, currentIndex-1)); + lastIndex = currentIndex; + } + fResult.append(">"); + break; + case '&' : // special html escape character + if (lastIndex < (currentIndex - 1)) { + fResult.append(text.substring(lastIndex, currentIndex-1)); + lastIndex = currentIndex; + } + fResult.append("&"); + break; + case '\'' : // special html escape character + if (lastIndex < (currentIndex - 1)) { + fResult.append(text.substring(lastIndex, currentIndex-1)); + lastIndex = currentIndex; + } + fResult.append("'"); + break; + case '\"' : // special html escape character + if (lastIndex < (currentIndex - 1)) { + fResult.append(text.substring(lastIndex, currentIndex-1)); + lastIndex = currentIndex; + } + fResult.append("""); + break; + } + } + if (lastIndex < (currentIndex)) { + fResult.append(text.substring(lastIndex, currentIndex)); + } + } /** ! * Render the MTML token which are defined in the OPEN_TAGS and CLOSE_TAGS map * * @return *************** *** 436,440 **** fWhiteStart = false; stopList(); ! fResult.append("<p class=\"paragraph\"/>"); } continue; --- 537,541 ---- fWhiteStart = false; stopList(); ! fResult.append("<p/>"); } continue; *************** *** 611,615 **** fResult.append("\">"); // System.out.println(heading); ! fResult.append(filter(heading, fRecursionLevel)); fResult.append("</h3>"); continue; --- 712,716 ---- fResult.append("\">"); // System.out.println(heading); ! fResult.append(filter(heading, fContext, fRecursionLevel)); fResult.append("</h3>"); continue; *************** *** 764,772 **** if (fSource[tempCurrPosition] == '\n') { fCurrentPosition = tempCurrPosition + 1; ! fResult.append("<hr class=\"line\"/>"); continue; } else if (fSource[tempCurrPosition++] == '\r' && fSource[tempCurrPosition++] == '\n') { fCurrentPosition = tempCurrPosition; ! fResult.append("<hr class=\"line\"/>"); continue; } --- 865,873 ---- if (fSource[tempCurrPosition] == '\n') { fCurrentPosition = tempCurrPosition + 1; ! fResult.append("<hr/>"); continue; } else if (fSource[tempCurrPosition++] == '\r' && fSource[tempCurrPosition++] == '\n') { fCurrentPosition = tempCurrPosition; ! fResult.append("<hr/>"); continue; } *************** *** 913,933 **** int htmlStartPosition = fCurrentPosition; try { ! String urlString = fStringSource.substring(fCurrentPosition - 1, fCurrentPosition + 5); ! if (urlString.equals("<math>")) { ! fCurrentPosition += 5; ! if (readUntilString("</math>")) { ! String mathContent = new String(fSource, htmlStartPosition + 5, fCurrentPosition - htmlStartPosition - 12); ! if (mathContent != null) { ! copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); ! fWhiteStart = false; ! if (startOfIndent) { ! startOfIndent = false; ! handleTeXMath(mathContent, false); ! } else { ! handleTeXMath(mathContent, true); } - continue; } ! } } } catch (IndexOutOfBoundsException e) { --- 1014,1055 ---- int htmlStartPosition = fCurrentPosition; try { ! switch (fStringSource.charAt(fCurrentPosition)) { ! case 'm' : // math ! String mathString = fStringSource.substring(fCurrentPosition - 1, fCurrentPosition + 5); ! ! if (mathString.equals("<math>")) { ! fCurrentPosition += 5; ! if (readUntilString("</math>")) { ! String mathContent = new String(fSource, htmlStartPosition + 5, fCurrentPosition - htmlStartPosition - 12); ! if (mathContent != null) { ! copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); ! fWhiteStart = false; ! if (startOfIndent) { ! startOfIndent = false; ! handleTeXMath(mathContent, false); ! } else { ! handleTeXMath(mathContent, true); ! } ! continue; ! } } } ! break; ! case 'n' : // nowiki ! String nowikiString = fStringSource.substring(fCurrentPosition - 1, fCurrentPosition + 7); ! ! if (nowikiString.equals("<nowiki>")) { ! fCurrentPosition += 7; ! if (readUntilString("</nowiki>")) { ! String nowikiContent = new String(fSource, htmlStartPosition + 7, fCurrentPosition - htmlStartPosition - 16); ! if (nowikiContent != null) { ! copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); ! fWhiteStart = false; ! copyWhiteNewLine(nowikiContent); ! continue; ! } ! } ! } ! break; } } catch (IndexOutOfBoundsException e) { *************** *** 1126,1130 **** public String createAnchor(String head) { ! StringBuffer result = new StringBuffer(); char ch; result.append('a'); --- 1248,1252 ---- public String createAnchor(String head) { ! StringBuffer result = new StringBuffer(head.length() + 1); char ch; result.append('a'); *************** *** 1173,1182 **** * @param headLevel */ ! private void addToC(ArrayList toc, String head, String anchor, int headLevel) { int level = 1; if (level == headLevel) { ! StringBuffer link = new StringBuffer(); link.append("<li>"); ! SnipLink.appendLink(link, fSnip.getName(), head, anchor); link.append("</li>"); toc.add(link.toString()); --- 1295,1309 ---- * @param headLevel */ ! private void addToTableOfContent(ArrayList toc, String head, String anchor, int headLevel) { int level = 1; if (level == headLevel) { ! String snipName = ""; ! if (fSnip!=null) { ! snipName = fSnip.getName(); ! } ! ! StringBuffer link = new StringBuffer(snipName.length() + 40 + head.length() + anchor.length()); link.append("<li>"); ! SnipLink.appendLink(link, snipName, head, anchor); link.append("</li>"); toc.add(link.toString()); *************** *** 1184,1188 **** if (toc.size() > 0) { if (toc.get(toc.size() - 1) instanceof ArrayList) { ! addToC((ArrayList) toc.get(toc.size() - 1), head, anchor, --headLevel); return; } --- 1311,1315 ---- if (toc.size() > 0) { if (toc.get(toc.size() - 1) instanceof ArrayList) { ! addToTableOfContent((ArrayList) toc.get(toc.size() - 1), head, anchor, --headLevel); return; } *************** *** 1190,1197 **** ArrayList list = new ArrayList(); toc.add(list); ! addToC(list, head, anchor, --headLevel); } } private void handleHead(String head, int headLevel) { if (head != null) { --- 1317,1330 ---- ArrayList list = new ArrayList(); toc.add(list); ! addToTableOfContent(list, head, anchor, --headLevel); } } + /** + * handle head for table of content + * + * @param head + * @param headLevel + */ private void handleHead(String head, int headLevel) { if (head != null) { *************** *** 1205,1209 **** fResult = new StringBuffer(fResult.capacity()); } ! addToC(fToC, head, anchor, headLevel); fResult.append("<h"); --- 1338,1342 ---- fResult = new StringBuffer(fResult.capacity()); } ! addToTableOfContent(fToC, head, anchor, headLevel); fResult.append("<h"); *************** *** 1345,1349 **** // recursively filter macros within macros if (null != mParams.getContent() && !(macro instanceof INoParserBodyFilterMacro)) { ! mParams.setContent(filter(mParams.getContent(), fRecursionLevel)); } StringBufferWriter writer = new StringBufferWriter(new StringBuffer(256)); --- 1478,1482 ---- // recursively filter macros within macros if (null != mParams.getContent() && !(macro instanceof INoParserBodyFilterMacro)) { ! mParams.setContent(filter(mParams.getContent(), fContext, fRecursionLevel)); } StringBufferWriter writer = new StringBufferWriter(new StringBuffer(256)); *************** *** 1351,1355 **** StringBuffer buffer = writer.getBuffer(); if (macro instanceof IRenderResultMacro) { ! fResult.append(filter(buffer.toString(), fRecursionLevel)); } else { fResult.append(buffer); --- 1484,1488 ---- StringBuffer buffer = writer.getBuffer(); if (macro instanceof IRenderResultMacro) { ! fResult.append(filter(buffer.toString(), fContext, fRecursionLevel)); } else { fResult.append(buffer); *************** *** 1364,1368 **** // Filter paramFilter = new ParamFilter(mParams); // included = paramFilter.filter(included, null); ! fResult.append(include); } else { fResult.append(command.substring(1) + " not found."); --- 1497,1502 ---- // Filter paramFilter = new ParamFilter(mParams); // included = paramFilter.filter(included, null); ! // fResult.append(include); ! fResult.append(filter(include, fContext, fRecursionLevel)); } else { fResult.append(command.substring(1) + " not found."); *************** *** 1410,1414 **** } else { fTokenStack.push(BOLD); ! fResult.append("<b class=\"bold\">"); } break; --- 1544,1548 ---- } else { fTokenStack.push(BOLD); ! fResult.append("<b>"); } break; *************** *** 1419,1423 **** } else { fTokenStack.push(ITALIC); ! fResult.append("<i class=\"italic\">"); } break; --- 1553,1557 ---- } else { fTokenStack.push(ITALIC); ! fResult.append("<i>"); } break; *************** *** 1446,1450 **** } else { fTokenStack.push(STRIKETHROUGH); ! fResult.append("<strike class=\"strike\">"); } break; --- 1580,1584 ---- } else { fTokenStack.push(STRIKETHROUGH); ! fResult.append("<strike>"); } break; *************** *** 1585,1588 **** --- 1719,1752 ---- fResult.append("<div class=\"error\">Unexpected end for tag: <" + tag + "></div>"); } + + /** + * @return Returns the context. + */ + public FilterContext getContext() { + return fContext; + } + + /** + * @param context + * The context to set. + */ + public void setContext(FilterContext context) { + fContext = context; + } + + /** + * @return Returns the wikiEngine. + */ + public RenderEngine getWikiEngine() { + return fWikiEngine; + } + + /** + * @param wikiEngine + * The wikiEngine to set. + */ + public void setWikiEngine(RenderEngine wikiEngine) { + fWikiEngine = wikiEngine; + } } *************** *** 1776,1818 **** final static Token HTML_BR_OPEN = new SpecialTagToken(TokenHTML_BR_OPEN, "br", "<br/>"); ! final static Token HTML_HR_OPEN = new SpecialTagToken(TokenHTML_HR_OPEN, "hr", "<hr class=\"line\"/>"); final static Token HTML_EM_CLOSE = new CloseTagToken(TokenHTML_EM_CLOSE, "em", "</i>"); ! final static Token HTML_EM_OPEN = new OpenTagToken(TokenHTML_EM_OPEN, "em", "<i class=\"italic\">"); final static Token HTML_H1_CLOSE = new CloseTagToken(TokenHTML_H1_CLOSE, "h1", "</h1>"); ! final static Token HTML_H1_OPEN = new OpenTagToken(TokenHTML_H1_OPEN, "h1", "<h1 class=\"h1\">"); final static Token HTML_H2_CLOSE = new CloseTagToken(TokenHTML_H2_CLOSE, "h2", "</h2>"); ! final static Token HTML_H2_OPEN = new OpenTagToken(TokenHTML_H2_OPEN, "h2", "<h2 class=\"h2\">"); final static Token HTML_H3_CLOSE = new CloseTagToken(TokenHTML_H3_CLOSE, "h3", "</h3>"); ! final static Token HTML_H3_OPEN = new OpenTagToken(TokenHTML_H3_OPEN, "h3", "<h3 class=\"h3\">"); final static Token HTML_H4_CLOSE = new CloseTagToken(TokenHTML_H4_CLOSE, "h4", "</h4>"); ! final static Token HTML_H4_OPEN = new OpenTagToken(TokenHTML_H4_OPEN, "h4", "<h4 class=\"h4\">"); final static Token HTML_H5_CLOSE = new CloseTagToken(TokenHTML_H5_CLOSE, "h5", "</h5>"); ! final static Token HTML_H5_OPEN = new OpenTagToken(TokenHTML_H5_OPEN, "h5", "<h5 class=\"h5\">"); final static Token HTML_H6_CLOSE = new CloseTagToken(TokenHTML_H6_CLOSE, "h6", "</h6>"); ! final static Token HTML_H6_OPEN = new OpenTagToken(TokenHTML_H6_OPEN, "h6", "<h6 class=\"h6\">"); final static Token HTML_ITALIC_CLOSE = new CloseTagToken(TokenHTML_ITALIC_CLOSE, "i", "</i>"); ! final static Token HTML_ITALIC_OPEN = new OpenTagToken(TokenHTML_ITALIC_OPEN, "i", "<i class=\"italic\">"); final static Token HTML_BOLD_CLOSE = new CloseTagToken(TokenHTML_BOLD_CLOSE, "b", "</b>"); ! final static Token HTML_BOLD_OPEN = new OpenTagToken(TokenHTML_BOLD_OPEN, "b", "<b class=\"bold\">"); // final static Token HTML_PARAGRAPH_CLOSE = new CloseTagToken(TokenHTML_PARAGRAPH_CLOSE, "p", "</p>"); ! final static Token HTML_PARAGRAPH_OPEN = new OpenTagToken(TokenHTML_PARAGRAPH_OPEN, "p", "<p class=\"paragraph\">"); final static Token HTML_PRE_CLOSE = new CloseTagToken(TokenHTML_PRE_CLOSE, "pre", "</pre>"); final static Token HTML_PRE_OPEN = new OpenTagToken(TokenHTML_PRE_OPEN, "pre", "<pre class=\"pre\">"); final static Token HTML_BLOCKQUOTE_CLOSE = new CloseTagToken(TokenHTML_BLOCKQUOTE_CLOSE, "blockquote", "</blockquote>"); ! final static Token HTML_BLOCKQUOTE_OPEN = ! new OpenTagToken(TokenHTML_BLOCKQUOTE_OPEN, "blockquote", "<blockquote class=\"blockquote\">"); final static Token HTML_STRIKE_CLOSE = new CloseTagToken(TokenHTML_STRIKE_CLOSE, "strike", "</strike>"); ! final static Token HTML_STRIKE_OPEN = new OpenTagToken(TokenHTML_STRIKE_OPEN, "strike", "<strike class=\"strike\">"); final static Token HTML_STRONG_CLOSE = new CloseTagToken(TokenHTML_STRONG_CLOSE, "strong", "</b>"); ! final static Token HTML_STRONG_OPEN = new OpenTagToken(TokenHTML_STRONG_OPEN, "strong", "<b class=\"bold\">"); final static Token HTML_UNDERLINE_CLOSE = new CloseTagToken(TokenHTML_UNDERLINE_CLOSE, "u", "</u>"); ! final static Token HTML_UNDERLINE_OPEN = new OpenTagToken(TokenHTML_UNDERLINE_OPEN, "u", "<u class=\"underline\">"); final static Token HTML_SUB_CLOSE = new CloseTagToken(TokenHTML_SUB_CLOSE, "sub", "</sub>"); ! final static Token HTML_SUB_OPEN = new OpenTagToken(TokenHTML_SUB_OPEN, "sub", "<sub class=\"sub\">"); final static Token HTML_SUP_CLOSE = new CloseTagToken(TokenHTML_SUP_CLOSE, "sup", "</sup>"); ! final static Token HTML_SUP_OPEN = new OpenTagToken(TokenHTML_SUP_OPEN, "sup", "<sup class=\"sup\">"); final static Token HTML_MATH_OPEN = new OpenTagToken(TokenHTML_MATH_CLOSE, "math", "<math>"); --- 1940,1981 ---- final static Token HTML_BR_OPEN = new SpecialTagToken(TokenHTML_BR_OPEN, "br", "<br/>"); ! final static Token HTML_HR_OPEN = new SpecialTagToken(TokenHTML_HR_OPEN, "hr", "<hr/>"); final static Token HTML_EM_CLOSE = new CloseTagToken(TokenHTML_EM_CLOSE, "em", "</i>"); ! final static Token HTML_EM_OPEN = new OpenTagToken(TokenHTML_EM_OPEN, "em", "<i>"); final static Token HTML_H1_CLOSE = new CloseTagToken(TokenHTML_H1_CLOSE, "h1", "</h1>"); ! final static Token HTML_H1_OPEN = new OpenTagToken(TokenHTML_H1_OPEN, "h1", "<h1>"); final static Token HTML_H2_CLOSE = new CloseTagToken(TokenHTML_H2_CLOSE, "h2", "</h2>"); ! final static Token HTML_H2_OPEN = new OpenTagToken(TokenHTML_H2_OPEN, "h2", "<h2>"); final static Token HTML_H3_CLOSE = new CloseTagToken(TokenHTML_H3_CLOSE, "h3", "</h3>"); ! final static Token HTML_H3_OPEN = new OpenTagToken(TokenHTML_H3_OPEN, "h3", "<h3>"); final static Token HTML_H4_CLOSE = new CloseTagToken(TokenHTML_H4_CLOSE, "h4", "</h4>"); ! final static Token HTML_H4_OPEN = new OpenTagToken(TokenHTML_H4_OPEN, "h4", "<h4>"); final static Token HTML_H5_CLOSE = new CloseTagToken(TokenHTML_H5_CLOSE, "h5", "</h5>"); ! final static Token HTML_H5_OPEN = new OpenTagToken(TokenHTML_H5_OPEN, "h5", "<h5>"); final static Token HTML_H6_CLOSE = new CloseTagToken(TokenHTML_H6_CLOSE, "h6", "</h6>"); ! final static Token HTML_H6_OPEN = new OpenTagToken(TokenHTML_H6_OPEN, "h6", "<h6>"); final static Token HTML_ITALIC_CLOSE = new CloseTagToken(TokenHTML_ITALIC_CLOSE, "i", "</i>"); ! final static Token HTML_ITALIC_OPEN = new OpenTagToken(TokenHTML_ITALIC_OPEN, "i", "<i>"); final static Token HTML_BOLD_CLOSE = new CloseTagToken(TokenHTML_BOLD_CLOSE, "b", "</b>"); ! final static Token HTML_BOLD_OPEN = new OpenTagToken(TokenHTML_BOLD_OPEN, "b", "<b>"); // final static Token HTML_PARAGRAPH_CLOSE = new CloseTagToken(TokenHTML_PARAGRAPH_CLOSE, "p", "</p>"); ! final static Token HTML_PARAGRAPH_OPEN = new OpenTagToken(TokenHTML_PARAGRAPH_OPEN, "p", "<p>"); final static Token HTML_PRE_CLOSE = new CloseTagToken(TokenHTML_PRE_CLOSE, "pre", "</pre>"); final static Token HTML_PRE_OPEN = new OpenTagToken(TokenHTML_PRE_OPEN, "pre", "<pre class=\"pre\">"); final static Token HTML_BLOCKQUOTE_CLOSE = new CloseTagToken(TokenHTML_BLOCKQUOTE_CLOSE, "blockquote", "</blockquote>"); ! final static Token HTML_BLOCKQUOTE_OPEN = new OpenTagToken(TokenHTML_BLOCKQUOTE_OPEN, "blockquote", "<blockquote>"); final static Token HTML_STRIKE_CLOSE = new CloseTagToken(TokenHTML_STRIKE_CLOSE, "strike", "</strike>"); ! final static Token HTML_STRIKE_OPEN = new OpenTagToken(TokenHTML_STRIKE_OPEN, "strike", "<strike>"); final static Token HTML_STRONG_CLOSE = new CloseTagToken(TokenHTML_STRONG_CLOSE, "strong", "</b>"); ! final static Token HTML_STRONG_OPEN = new OpenTagToken(TokenHTML_STRONG_OPEN, "strong", "<b>"); final static Token HTML_UNDERLINE_CLOSE = new CloseTagToken(TokenHTML_UNDERLINE_CLOSE, "u", "</u>"); ! final static Token HTML_UNDERLINE_OPEN = new OpenTagToken(TokenHTML_UNDERLINE_OPEN, "u", "<u>"); final static Token HTML_SUB_CLOSE = new CloseTagToken(TokenHTML_SUB_CLOSE, "sub", "</sub>"); ! final static Token HTML_SUB_OPEN = new OpenTagToken(TokenHTML_SUB_OPEN, "sub", "<sub>"); final static Token HTML_SUP_CLOSE = new CloseTagToken(TokenHTML_SUP_CLOSE, "sup", "</sup>"); ! final static Token HTML_SUP_OPEN = new OpenTagToken(TokenHTML_SUP_OPEN, "sup", "<sup>"); final static Token HTML_MATH_OPEN = new OpenTagToken(TokenHTML_MATH_CLOSE, "math", "<math>"); *************** *** 1943,1958 **** public String filter(String input, FilterContext context) { ! fContext = context; ! fWikiEngine = context.getRenderContext().getRenderEngine(); ! try { ! SnipMacroParameter params = (SnipMacroParameter) fContext.getMacroParameter(); ! fSnip = params.getSnipRenderContext().getSnip(); ! } catch (ClassCastException e) { ! e.printStackTrace(); ! } ! return filter(input, 0); } ! protected String filter(String input, int recursionLevel) { try { if (++recursionLevel > RECURSION_LIMIT) { --- 2106,2121 ---- public String filter(String input, FilterContext context) { ! // fContext = context; ! // fWikiEngine = context.getRenderContext().getRenderEngine(); ! // try { ! // SnipMacroParameter params = (SnipMacroParameter) fContext.getMacroParameter(); ! // fSnip = params.getSnipRenderContext().getSnip(); ! // } catch (ClassCastException e) { ! // e.printStackTrace(); ! // } ! return filter(input, context, 0); } ! public String filter(String input, FilterContext context, int recursionLevel) { try { if (++recursionLevel > RECURSION_LIMIT) { *************** *** 1961,1965 **** StringBuffer result = new StringBuffer(input.length() + input.length() / 10); // instantiate inner Parser class ! Parser parser = new Parser(input, result, recursionLevel); parser.parse(); return result.toString(); --- 2124,2128 ---- StringBuffer result = new StringBuffer(input.length() + input.length() / 10); // instantiate inner Parser class ! Parser parser = new Parser(input, result, context, recursionLevel); parser.parse(); return result.toString(); *************** *** 1968,1971 **** --- 2131,2135 ---- //log.warn("<span class=\"error\">Exception</span>: " + this + ": " + e); log.warn("Exception for: " + this +" " + e); + e.printStackTrace(); } catch (Error err) { //log.warn("<span class=\"error\">Error</span>: " + this + ": " + err); *************** *** 1977,2026 **** } ! private void filterParams(StringBuffer buffer, String name) { ! Map param = fContext.getRenderContext().getParameters(); ! if (param != null) { ! if (param.containsKey(name)) { ! Object value = param.get(name); ! if (value instanceof String[]) { ! buffer.append(((String[]) value)[0]); ! } else { ! buffer.append(value); ! } ! } else { ! buffer.append("<"); ! buffer.append(name); ! buffer.append(">"); ! } ! } else { ! buffer.append("<"); ! buffer.append(name); ! buffer.append(">"); ! } ! } ! public String parseParameters(String unsplittedMacroParameters) { ! int currPos = 0; ! int currEndPos = 0; ! int len = unsplittedMacroParameters.length(); ! StringBuffer buffer = new StringBuffer(len); ! char ch; ! while (currPos < len) { ! ch = unsplittedMacroParameters.charAt(currPos++); ! if (ch != '$') { ! buffer.append(ch); ! } else { ! if ((currEndPos = unsplittedMacroParameters.indexOf('|', currPos)) >= 1) { ! filterParams(buffer, unsplittedMacroParameters.substring(currPos, currEndPos)); ! currPos = currEndPos + 1; ! buffer.append('|'); ! } else { ! if (currPos < len) { ! filterParams(buffer, unsplittedMacroParameters.substring(currPos, len)); ! } ! } ! } ! } ! return buffer.toString(); ! } protected Repository getMacroRepository() { --- 2141,2190 ---- } ! // private void filterParams(StringBuffer buffer, String name) { ! // Map param = fContext.getRenderContext().getParameters(); ! // if (param != null) { ! // if (param.containsKey(name)) { ! // Object value = param.get(name); ! // if (value instanceof String[]) { ! // buffer.append(((String[]) value)[0]); ! // } else { ! // buffer.append(value); ! // } ! // } else { ! // buffer.append("<"); ! // buffer.append(name); ! // buffer.append(">"); ! // } ! // } else { ! // buffer.append("<"); ! // buffer.append(name); ! // buffer.append(">"); ! // } ! // } ! // public String parseParameters(String unsplittedMacroParameters) { ! // int currPos = 0; ! // int currEndPos = 0; ! // int len = unsplittedMacroParameters.length(); ! // StringBuffer buffer = new StringBuffer(len); ! // char ch; ! // while (currPos < len) { ! // ch = unsplittedMacroParameters.charAt(currPos++); ! // if (ch != '$') { ! // buffer.append(ch); ! // } else { ! // if ((currEndPos = unsplittedMacroParameters.indexOf('|', currPos)) >= 1) { ! // filterParams(buffer, unsplittedMacroParameters.substring(currPos, currEndPos)); ! // currPos = currEndPos + 1; ! // buffer.append('|'); ! // } else { ! // if (currPos < len) { ! // filterParams(buffer, unsplittedMacroParameters.substring(currPos, len)); ! // } ! // } ! // } ! // } ! // return buffer.toString(); ! // } protected Repository getMacroRepository() { *************** *** 2033,2065 **** } - /** - * @return Returns the context. - */ - public FilterContext getContext() { - return fContext; - } - - /** - * @param context - * The context to set. - */ - public void setContext(FilterContext context) { - fContext = context; - } - - /** - * @return Returns the wikiEngine. - */ - public RenderEngine getWikiEngine() { - return fWikiEngine; - } - - /** - * @param wikiEngine - * The wikiEngine to set. - */ - public void setWikiEngine(RenderEngine wikiEngine) { - fWikiEngine = wikiEngine; - } - } --- 2197,2199 ---- |