[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/filter WikipediaFilter.java,1.1,1.2
Status: Pre-Alpha
Brought to you by:
jsurfer
|
From: Klaus H. <js...@us...> - 2004-03-20 10:20:30
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8583/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.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WikipediaFilter.java 9 Mar 2004 20:13:03 -0000 1.1 --- WikipediaFilter.java 20 Mar 2004 10:10:34 -0000 1.2 *************** *** 29,34 **** --- 29,37 ---- import java.util.StringTokenizer; + import javax.servlet.http.HttpServletRequest; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.hartmath.server.taglib.BrowserSniffer; import org.hartmath.tex2mml.TeXParser; import org.radeox.api.engine.ImageRenderEngine; *************** *** 47,50 **** --- 50,54 ---- import org.radeox.util.Encoder; import org.radeox.util.StringBufferWriter; + import org.snipsnap.app.Application; import org.snipsnap.render.macro.parameter.SnipMacroParameter; import org.snipsnap.snip.Snip; *************** *** 412,417 **** } } - protected int getNextToken() throws InvalidInputException { fWhiteStartPosition = 0; fWhiteStart = false; --- 416,421 ---- } } + protected int getNextToken() throws InvalidInputException { fWhiteStartPosition = 0; fWhiteStart = false; *************** *** 455,474 **** } continue; ! case '$' : // detect ascii and tex math ! copyWhite(fWhiteStart, fWhiteStartPosition, 1); ! fWhiteStart = false; ! int startMathPosition = fCurrentPosition; ! if (readUntilChar('$')) { ! String mathContent = new String(fSource, startMathPosition, fCurrentPosition - startMathPosition - 1); ! if (mathContent != null) { ! fResult.append("<m:math><m:mstyle mathcolor=\"Black\" displaystyle=\"true\">"); ! fTeXParser.initialize(mathContent); ! fTeXParser.start(fResult); ! fResult.append("</m:mstyle></m:math>"); ! continue; ! } ! } ! break; case '{' : // detect macros copyWhite(fWhiteStart, fWhiteStartPosition, 1); --- 459,475 ---- } continue; ! case '$' : // detect tex math ! copyWhite(fWhiteStart, fWhiteStartPosition, 1); ! fWhiteStart = false; ! int startMathPosition = fCurrentPosition; ! if (readUntilChar('$')) { ! String mathContent = new String(fSource, startMathPosition, fCurrentPosition - startMathPosition - 1); ! if (mathContent != null) { ! handleTeXMath(mathContent); ! continue; ! } ! } ! break; case '{' : // detect macros copyWhite(fWhiteStart, fWhiteStartPosition, 1); *************** *** 661,727 **** } break; ! case 'a' : // <ol> list ! if (getList('a', "<ol class=\"alpha\">", "</ol>")) { ! continue; ! } ! break; ! case 'A' : // <ol> list ! if (getList('A', "<ol class=\"ALPHA\">", "</ol>")) { ! continue; ! } ! break; ! case 'g' : // <ol> list ! if (getList('g', "<ol class=\"greek\">", "</ol>")) { ! continue; ! } ! break; ! case 'H' : // <ol> list ! if (getList('H', "<ol class=\"HIRAGANA\">", "</ol>")) { ! continue; ! } ! break; ! case 'k' : // <ol> list ! if (getList('k', "<ol class=\"katakana\">", "</ol>")) { ! continue; ! } ! break; ! case 'K' : // <ol> list ! if (getList('K', "<ol class=\"KATAKANA\">", "</ol>")) { ! continue; ! } ! break; ! case 'j' : // <ol> list ! if (getList('j', "<ol class=\"HEBREW\">", "</ol>")) { ! continue; ! } ! break; ! // int levelROMAN = getNumberOfChar('I') + 1; ! // if (getNextChar('.') && getNextChar(' ')) { ! // copyWhite(fWhiteStart, fWhiteStartPosition, 1 + levelROMAN); ! // fWhiteStart = false; ! // Token tok = (Token) fTokenStack.peek(); ! // if (tok instanceof ListToken) { ! // ListToken listToken = (ListToken) tok; ! // int topLevel = listToken.getLevel(); ! // if (listToken.getToken() == TokenLIST_OL_START) { ! // if (levelROMAN > topLevel) { ! // fTokenStack.push(new ListToken(TokenLIST_OL_START, topLevel + 1)); ! // fResult.append("<ol class=\"ROMAN\"><li>"); ! // } else if (levelROMAN < topLevel) { ! // fResult.append("</ol></li><li>"); ! // } else { ! // fResult.append("</li><li>"); ! // } ! // } else { ! // fTokenStack.push(new ListToken(TokenLIST_OL_START, levelROMAN)); ! // fResult.append("<ol class=\"ROMAN\"><li>"); ! // } ! // } else { ! // fTokenStack.push(new ListToken(TokenLIST_OL_START, 1)); ! // fResult.append("\n<ol class=\"ROMAN\"><li>"); ! // } // continue; // } // break; case '\'' : if (getNextChar('\'')) { --- 662,701 ---- } break; ! // case 'a' : // <ol> list ! // if (getList('a', "<ol class=\"alpha\">", "</ol>")) { // continue; // } // break; + // case 'A' : // <ol> list + // if (getList('A', "<ol class=\"ALPHA\">", "</ol>")) { + // continue; + // } + // break; + // case 'g' : // <ol> list + // if (getList('g', "<ol class=\"greek\">", "</ol>")) { + // continue; + // } + // break; + // case 'H' : // <ol> list + // if (getList('H', "<ol class=\"HIRAGANA\">", "</ol>")) { + // continue; + // } + // break; + // case 'k' : // <ol> list + // if (getList('k', "<ol class=\"katakana\">", "</ol>")) { + // continue; + // } + // break; + // case 'K' : // <ol> list + // if (getList('K', "<ol class=\"KATAKANA\">", "</ol>")) { + // continue; + // } + // break; + // case 'j' : // <ol> list + // if (getList('j', "<ol class=\"HEBREW\">", "</ol>")) { + // continue; + // } + // break; + case '\'' : if (getNextChar('\'')) { *************** *** 769,787 **** } ! // tempCurrPosition = fCurrentPosition; ! // try { ! // if (fSource[tempCurrPosition++] == '-') { ! // ! // if (tempCurrPosition >= fSource.length || fSource[tempCurrPosition] != '-') { ! // fCurrentPosition++; ! // copyWhite(fWhiteStart, fWhiteStartPosition, 2); ! // fWhiteStart = false; ! // return TokenSTRIKETHROUGH; ! // } ! // ! // } ! // } catch (IndexOutOfBoundsException e) { ! // ! // } int levelMinus = getNumberOfChar('-') + 1; if (getNextChar(' ')) { --- 743,747 ---- } ! int levelMinus = getNumberOfChar('-') + 1; if (getNextChar(' ')) { *************** *** 817,823 **** break; case 'h' : // http(s):// - if (getList('h', "<ol class=\"hiragana\">", "</ol>")) { - continue; - } int urlStartPosition = fCurrentPosition; boolean foundUrl = false; --- 777,780 ---- *************** *** 863,901 **** } break; - // case 'ä' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("ä"); - // continue; - // case 'ö' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("ö"); - // continue; - // case 'ü' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("ü"); - // continue; - // case 'Ä' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("Ä"); - // continue; - // case 'Ö' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("Ö"); - // continue; - // case 'Ü' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("Ü"); - // continue; - // case 'ß' : // escape german umlauts - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // fResult.append("ß"); - // continue; case '&' : int ampersandStart = fCurrentPosition - 1; --- 820,823 ---- *************** *** 945,950 **** } break; ! case '<' : // detect special html tags int htmlStartPosition = fCurrentPosition; int htmlToken = getHTMLToken(); if (htmlToken == TokenIgnore) { --- 867,892 ---- } break; ! case '<' : // detect the <math> tag first 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; + handleTeXMath(mathContent); + continue; + } + } + } + } catch (IndexOutOfBoundsException e) { + + } + fCurrentPosition = htmlStartPosition; + // detect special html tags + htmlStartPosition = fCurrentPosition; int htmlToken = getHTMLToken(); if (htmlToken == TokenIgnore) { *************** *** 991,994 **** --- 933,961 ---- } + private void handleTeXMath(String mathContent) { + // TODO clean this up + Map map = Application.get().getParameters(); + HttpServletRequest request = (HttpServletRequest) map.get("request"); + BrowserSniffer sniffy = BrowserSniffer.getBrowserDetection(request); + + switch (sniffy.getBrowserId()) { + case BrowserSniffer.MOZILLAID : + case BrowserSniffer.MSIEID : + case BrowserSniffer.MATHPLAYERID : + fResult.append("<m:math><m:mstyle mathcolor=\"Black\" displaystyle=\"true\">"); + fTeXParser.initialize(mathContent); + fTeXParser.parse2MML(fResult); + fResult.append("</m:mstyle></m:math>"); + break; + case BrowserSniffer.NETSCAPEID ://older netscape newer are detected as Gecko + fResult.append(fResult); + break; + default : + fResult.append("<m>"); + fTeXParser.initialize(mathContent); + fTeXParser.parse2CSS(fResult); + fResult.append("</m>"); + } + } private void handleSnipLink(String name) { if (name != null) { *************** *** 1106,1110 **** StringBuffer link = new StringBuffer(); link.append("<li>"); ! SnipLink.appendLink(link, fSnip.getName(),head, anchor); link.append("</li>"); toc.add(link.toString()); --- 1073,1077 ---- StringBuffer link = new StringBuffer(); link.append("<li>"); ! SnipLink.appendLink(link, fSnip.getName(), head, anchor); link.append("</li>"); toc.add(link.toString()); *************** *** 1305,1311 **** } catch (IllegalArgumentException e) { fResult.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>"); ! e.printStackTrace(); ! } catch (Throwable e) { log.warn("MacroFilter: unable to format macro: " + command, e); --- 1272,1278 ---- } catch (IllegalArgumentException e) { fResult.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>"); ! e.printStackTrace(); ! } catch (Throwable e) { log.warn("MacroFilter: unable to format macro: " + command, e); *************** *** 1969,1973 **** fContext = context; fWikiEngine = context.getRenderContext().getRenderEngine(); ! SnipMacroParameter params = (SnipMacroParameter)fContext.getMacroParameter(); fSnip = params.getSnipRenderContext().getSnip(); return filter(input, 0); --- 1936,1940 ---- fContext = context; fWikiEngine = context.getRenderContext().getRenderEngine(); ! SnipMacroParameter params = (SnipMacroParameter) fContext.getMacroParameter(); fSnip = params.getSnipRenderContext().getSnip(); return filter(input, 0); |