hmath-commits Mailing List for HMath - MathML Wiki/BLOG
Status: Pre-Alpha
Brought to you by:
jsurfer
You can subscribe to this list here.
2004 |
Jan
|
Feb
(28) |
Mar
(121) |
Apr
(49) |
May
(11) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: Klaus H. <js...@us...> - 2004-06-11 19:25:58
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6372/WEB-INF/src/org/hartmath/server/render Modified Files: HMathRenderEngine.java Log Message: misc changes Index: HMathRenderEngine.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/HMathRenderEngine.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HMathRenderEngine.java 2 May 2004 17:34:10 -0000 1.3 --- HMathRenderEngine.java 11 Jun 2004 19:25:48 -0000 1.4 *************** *** 142,145 **** --- 142,148 ---- SnipMacroParameter params = (SnipMacroParameter) filterContext.getMacroParameter(); Snip snip = params.getSnipRenderContext().getSnip(); + if (snip==null) { + return ""; + } String name = snip.getName(); String parent = snip.getParentName(); |
From: Klaus H. <js...@us...> - 2004-06-11 19:25:35
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6006/WEB-INF/src/org/hartmath/server/cache Modified Files: CachedPage.java Log Message: misc changes Index: CachedPage.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/CachedPage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CachedPage.java 12 May 2004 21:20:13 -0000 1.4 --- CachedPage.java 11 Jun 2004 19:25:24 -0000 1.5 *************** *** 19,28 **** --- 19,33 ---- import java.util.ArrayList; + import java.util.Map; + + import javax.servlet.http.HttpServletRequest; import org.hartmath.server.filter.CachedWikipediaFilter; + import org.hartmath.server.taglib.MathSniffer; import org.hartmath.tex2mml.TeXParser; import org.radeox.api.engine.RenderEngine; import org.radeox.filter.context.FilterContext; import org.radeox.macro.MacroRepository; + import org.snipsnap.app.Application; /** *************** *** 56,60 **** protected void addMathToBuffer(String[] mathStrings) { ! CachedWikipediaFilter.handleTeXMath(fResult, mathStrings); } --- 61,68 ---- protected void addMathToBuffer(String[] mathStrings) { ! Map map = Application.get().getParameters(); ! HttpServletRequest request = (HttpServletRequest) map.get("request"); ! MathSniffer sniffy = MathSniffer.getBrowserDetection(request); ! CachedWikipediaFilter.handleTeXMath(sniffy, fResult, mathStrings); } |
From: Klaus H. <js...@us...> - 2004-06-11 19:24:16
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4865/WEB-INF/src/org/hartmath/server/filter Modified Files: CachedWikipediaParser.java CachedWikipediaFilter.java Log Message: misc changes Index: CachedWikipediaFilter.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CachedWikipediaFilter.java 12 May 2004 21:20:14 -0000 1.3 --- CachedWikipediaFilter.java 11 Jun 2004 19:24:05 -0000 1.4 *************** *** 23,27 **** import java.util.HashMap; import java.util.HashSet; - import java.util.Map; import javax.servlet.http.HttpServletRequest; --- 23,26 ---- *************** *** 45,49 **** import org.radeox.util.Encoder; import org.radeox.util.StringBufferWriter; ! import org.snipsnap.app.Application; /** --- 44,48 ---- import org.radeox.util.Encoder; import org.radeox.util.StringBufferWriter; ! //import org.snipsnap.app.Application; /** *************** *** 929,936 **** } ! public static void handleTeXMath(StringBuffer result, String[] mathStrings) { ! Map map = Application.get().getParameters(); ! HttpServletRequest request = (HttpServletRequest) map.get("request"); ! MathSniffer sniffy = MathSniffer.getBrowserDetection(request); switch (sniffy.getBrowserId()) { --- 928,935 ---- } ! public static void handleTeXMath(MathSniffer sniffy, StringBuffer result, String[] mathStrings) { ! // Map map = Application.get().getParameters(); ! // HttpServletRequest request = (HttpServletRequest) map.get("request"); ! // MathSniffer sniffy = MathSniffer.getBrowserDetection(request); switch (sniffy.getBrowserId()) { Index: CachedWikipediaParser.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaParser.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CachedWikipediaParser.java 12 May 2004 21:20:14 -0000 1.5 --- CachedWikipediaParser.java 11 Jun 2004 19:24:05 -0000 1.6 *************** *** 42,45 **** --- 42,46 ---- import org.hartmath.server.filter.CachedWikipediaFilter.SpecialTagToken; import org.hartmath.server.filter.CachedWikipediaFilter.Token; + //import org.hartmath.server.macro.table.Table; import org.hartmath.server.taglib.MathSniffer; import org.hartmath.tex2mml.TeXParser; *************** *** 623,627 **** break; case ':' : - if (fCurrentPosition >= 2) { char beforeChar = fSource[fCurrentPosition - 2]; --- 624,627 ---- *************** *** 685,703 **** } break; ! case '{' : // detect macros copyWhite(fWhiteStart, fWhiteStartPosition, 1); fWhiteStart = false; // boolean scanBody = true; int startMacroPosition = fCurrentPosition; ! if (readUntilChar('}')) { ! String macroStartTag; ! ! macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1); ! if (macroStartTag != null) { ! createMacro(startMacroPosition, macroStartTag); ! continue; } ! } break; case '[' : --- 685,707 ---- } break; ! case '{' : ! // detect macros copyWhite(fWhiteStart, fWhiteStartPosition, 1); fWhiteStart = false; // boolean scanBody = true; int startMacroPosition = fCurrentPosition; + // if (getNextChar('|') && handleWikipediaTable()) { // Wikipedia table syntax + // continue; + // } else { + if (readUntilChar('}')) { + String macroStartTag; ! macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1); ! if (macroStartTag != null) { ! createMacro(startMacroPosition, macroStartTag); ! continue; ! } } ! // } break; case '[' : *************** *** 715,722 **** while (true) { fCurrentCharacter = fSource[fCurrentPosition++]; ! if (! Character.isLetterOrDigit(fCurrentCharacter)) { fCurrentPosition--; break; ! } suffixBuffer.append(fCurrentCharacter); } --- 719,726 ---- while (true) { fCurrentCharacter = fSource[fCurrentPosition++]; ! if (!Character.isLetterOrDigit(fCurrentCharacter)) { fCurrentPosition--; break; ! } suffixBuffer.append(fCurrentCharacter); } *************** *** 1096,1100 **** // insert html comment for visual checks only: /* ! * fResultBuffer.append(" <!--"); copyWhite(htmlCommentContent); fResultBuffer.append("-->"); */ continue; --- 1100,1104 ---- // insert html comment for visual checks only: /* ! * fResultBuffer.append(" <!--"); copyWhite(htmlCommentContent); fResultBuffer.append("--> "); */ continue; *************** *** 1374,1378 **** new Attachment(longImageName, "image/gif", imageFile.length(), new Date(), snipname + "/" + longImageName, true); // fSnip.getAttachments().addAttachment(longImageName, "image/gif", imageFile.length(), snipname + "/" + longImageName, ! // true); fSnip.getAttachments().addAttachment(attachment); StringWriter writer = new StringWriter(); --- 1378,1382 ---- new Attachment(longImageName, "image/gif", imageFile.length(), new Date(), snipname + "/" + longImageName, true); // fSnip.getAttachments().addAttachment(longImageName, "image/gif", imageFile.length(), snipname + "/" + longImageName, ! // true); fSnip.getAttachments().addAttachment(attachment); StringWriter writer = new StringWriter(); *************** *** 1518,1521 **** --- 1522,1641 ---- } + // private boolean handleWikipediaTable() { + // // example + // // {| border=1 + // // |Zelle 1 + // // | + // // {| border=2 + // // |Zelle A + // // |- + // // |Zelle B + // // |} + // // |Zelle 3 + // // |} + // + // int temp = fCurrentPosition; + // // StringBuffer suffixBuffer = new StringBuffer(); + // Table table = new Table(fContext.getRenderContext()); + // // char currentChar = ' '; + // char lastChar = ' '; + // // int startPosition = 0; + // // int currentPosition = 0; + // StringBuffer buffer = new StringBuffer(); + // int thStartPosition = 0; + // + // try { // read first line + // fCurrentCharacter = fSource[fCurrentPosition++]; + // // TODO improve this for different table attributes + // while (fCurrentCharacter != '\n' ) { + // fCurrentCharacter = fSource[fCurrentPosition++]; + // // System.out.println(fCurrentCharacter); + // } + // table.newRow(); + // lastChar = fCurrentCharacter; + // fCurrentCharacter = fSource[fCurrentPosition++]; + // while (true) { + // + // switch (fCurrentCharacter) { + // // case '{' : // start of nested table ? + // // if (getNextChar('|') && handleWikipediaTable()) { // Wikipedia table end reached + // // return true; + // // } + // // break; + // case '!' : + // if (lastChar == '\n') { + // table.addCell(buffer.toString()); + // // System.out.println(buffer.toString()); + // buffer.setLength(0); + // thStartPosition = fCurrentPosition; + // while (true) { + // lastChar = fCurrentCharacter; + // fCurrentCharacter = fSource[fCurrentPosition++]; + // if (fCurrentCharacter == '|') { + // break; + // } + // if (fCurrentCharacter == '\n') { + // lastChar = '\n'; + // fCurrentPosition = thStartPosition; + // break; + // } + // } + // } else { + // buffer.append(fCurrentCharacter); + // } + // break; + // case '|' : + // if (lastChar == '\n') { + // if (getNextChar('}')) { // Wikipedia table end reached + // table.addCell(buffer.toString()); + // StringWriter writer = new StringWriter(); + // try { + // table.appendTo(writer); + // fResultBuffer.append(writer.getBuffer()); + // } catch (IOException e1) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // return false; + // } + // return true; + // } else if (getNextChar('-')) { + // table.addCell(buffer.toString()); + // buffer.setLength(0); + // table.newRow(); + // while (true) { + // lastChar = fCurrentCharacter; + // fCurrentCharacter = fSource[fCurrentPosition++]; + // if (fCurrentCharacter == '|' || fCurrentCharacter == '!') { + // break; + // } + // } + // // continue; + // } else { + // if (buffer.length()>0) { + // table.addCell(buffer.toString()); + // buffer.setLength(0); + // } + // } + // } else if (getNextChar('|')) { + // table.addCell(buffer.toString()); + // // System.out.println(buffer.toString()); + // buffer.setLength(0); + // } else { + // buffer.append(fCurrentCharacter); + // } + // break; + // default : + // buffer.append(fCurrentCharacter); + // } + // lastChar = fCurrentCharacter; + // fCurrentCharacter = fSource[fCurrentPosition++]; + // } + // + // } catch (IndexOutOfBoundsException e) { + // + // } + // fCurrentPosition = temp - 1; + // return false; + // } private void handleWikipediaLink(String linkText, String suffix) { String name = linkText; *************** *** 1563,1567 **** Writer writer = new StringBufferWriter(fResultBuffer); try { ! if (-1 != hashIndex) { interWiki.expand(writer, extSpace, name, hash); } else { --- 1683,1687 ---- Writer writer = new StringBufferWriter(fResultBuffer); try { ! if (-1 != hashIndex) { interWiki.expand(writer, extSpace, name, hash); } else { |
From: Klaus H. <js...@us...> - 2004-05-12 21:20:26
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15572/WEB-INF/src/org/hartmath/server/filter Modified Files: CachedWikipediaParser.java CachedWikipediaFilter.java Log Message: Improved wikipedi syntax for internal/external links Index: CachedWikipediaFilter.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CachedWikipediaFilter.java 2 May 2004 12:43:07 -0000 1.2 --- CachedWikipediaFilter.java 12 May 2004 21:20:14 -0000 1.3 *************** *** 818,821 **** --- 818,932 ---- } + public static void handleWikipediaLink(StringBuffer result, RenderEngine wikiEngine, String name, String suffix) { + if (name != null) { + int index = name.indexOf("http://"); + // User probably wrote [http://radeox.org] instead of http://radeox.org + if (index != -1) { + // createExternalLink(result, wikiEngine, name.substring(index)); + String urlString = name.substring(index); + // Wikipedia like style: + int pipeIndex = urlString.indexOf(' '); + String alias = ""; + if (-1 != pipeIndex) { + alias = urlString.substring(pipeIndex + 1); + urlString = urlString.substring(0, pipeIndex); + } else { + alias = urlString; + } + + if (wikiEngine instanceof ImageRenderEngine) { + result.append(((ImageRenderEngine) wikiEngine).getExternalImageLink()); + } + result.append("<span class=\"nobr\">"); + result.append("<a href=\""); + result.append(Encoder.escape(urlString)); + result.append("\">"); + result.append(Encoder.toEntity(alias.charAt(0)) + alias.substring(1)); + result.append("</a></span>"); + } else { + if (suffix==null) { + suffix=""; + } + // trim the name and unescape it + name = Encoder.unescape(name.trim()); + // Is there an alias like [alias|link] ? + int pipeIndex = name.indexOf('|'); + String alias = ""; + if (-1 != pipeIndex) { + alias = name.substring(pipeIndex + 1); + name = name.substring(0, pipeIndex); + } + + int hashIndex = name.lastIndexOf('#'); + + String hash = ""; + if (-1 != hashIndex && hashIndex != name.length() - 1) { + hash = name.substring(hashIndex + 1); + name = name.substring(0, hashIndex); + } + + int colonIndex = name.indexOf(':'); + // typed link ? + if (-1 != colonIndex) { + // for now throw away the type information + name = name.substring(colonIndex + 1); + } + + int atIndex = name.lastIndexOf('@'); + // InterWiki link ? + if (-1 != atIndex) { + String extSpace = name.substring(atIndex + 1); + // known external space ? + InterWiki interWiki = InterWiki.getInstance(); + if (interWiki.contains(extSpace)) { + name = name.substring(0, atIndex); + Writer writer = new StringBufferWriter(result); + try { + if (-1 != hashIndex) { + interWiki.expand(writer, extSpace, name, hash); + } else { + interWiki.expand(writer, extSpace, name, ""); + } + } catch (IOException e) { + log.debug("InterWiki " + extSpace + " not found."); + } + } else { + result.append("[<span class=\"error\">"); + result.append(name); + result.append("?</span>]"); + } + } else { + // internal link + if (wikiEngine != null && wikiEngine instanceof WikiRenderEngine) { + if (((WikiRenderEngine) wikiEngine).exists(name)) { + String view = name+suffix; + if (-1 != pipeIndex) { + view = alias+suffix; + } + // Do not add hash if an alias was given + if (-1 != hashIndex) { + ((WikiRenderEngine) wikiEngine).appendLink(result, name, view, hash); + } else { + ((WikiRenderEngine) wikiEngine).appendLink(result, name, view); + } + } else if (((WikiRenderEngine) wikiEngine).showCreate()) { + ((WikiRenderEngine) wikiEngine).appendCreateLink(result, name, name+suffix); + // links with "create" are not cacheable because + // a missing wiki could be created + // TODO is this ok? + // fContext.getRenderContext().setCacheable(false); + } else { + // cannot display/create wiki, so just display the text + result.append(name); + } + } else { + // cannot display/create wiki, so just display the text + result.append(name); + } + } + } + } + } + public static void handleTeXMath(StringBuffer result, String[] mathStrings) { Map map = Application.get().getParameters(); Index: CachedWikipediaParser.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CachedWikipediaParser.java 11 May 2004 20:55:10 -0000 1.4 --- CachedWikipediaParser.java 12 May 2004 21:20:14 -0000 1.5 *************** *** 44,47 **** --- 44,48 ---- import org.hartmath.server.taglib.MathSniffer; import org.hartmath.tex2mml.TeXParser; + import org.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.IncludeRenderEngine; import org.radeox.api.engine.RenderEngine; *************** *** 708,712 **** if (readUntilString("]]")) { String name = new String(fSource, startLinkPosition, fCurrentPosition - startLinkPosition - 2); ! handleSnipLink(name); continue; } --- 709,731 ---- if (readUntilString("]]")) { String name = new String(fSource, startLinkPosition, fCurrentPosition - startLinkPosition - 2); ! // test for suffix string ! int temp = fCurrentPosition; ! StringBuffer suffixBuffer = new StringBuffer(); ! try { ! while (true) { ! fCurrentCharacter = fSource[fCurrentPosition++]; ! if (! Character.isLetterOrDigit(fCurrentCharacter)) { ! fCurrentPosition--; ! break; ! } ! suffixBuffer.append(fCurrentCharacter); ! } ! handleWikipediaLink(name, suffixBuffer.toString()); ! continue; ! } catch (IndexOutOfBoundsException e) { ! fCurrentPosition = temp; ! } ! ! handleWikipediaLink(name, ""); continue; } *************** *** 1070,1082 **** fCurrentPosition += 3; if (readUntilString("-->")) { ! String htmlCommentContent = new String(fSource, htmlStartPosition + 3, fCurrentPosition - htmlStartPosition - 6); if (htmlCommentContent != null) { copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); fWhiteStart = false; // insert html comment for visual checks only: ! /* fResultBuffer.append("<!--"); ! copyWhite(htmlCommentContent); ! fResultBuffer.append("-->"); ! */ continue; } --- 1089,1101 ---- fCurrentPosition += 3; if (readUntilString("-->")) { ! String htmlCommentContent = ! new String(fSource, htmlStartPosition + 3, fCurrentPosition - htmlStartPosition - 6); if (htmlCommentContent != null) { copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); fWhiteStart = false; // insert html comment for visual checks only: ! /* ! * fResultBuffer.append(" <!--"); copyWhite(htmlCommentContent); fResultBuffer.append("-->"); ! */ continue; } *************** *** 1316,1320 **** String encodedMathContent = Encoder.escape(mathContent); StringBuffer mathmlBuffer = new StringBuffer(); ! String shortImageName = "____tex_" + (fImageCounter++); String longImageName = shortImageName + ".gif"; mathmlBuffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); --- 1335,1339 ---- String encodedMathContent = Encoder.escape(mathContent); StringBuffer mathmlBuffer = new StringBuffer(); ! String shortImageName = "____tex_" + (fImageCounter++); String longImageName = shortImageName + ".gif"; mathmlBuffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); *************** *** 1348,1357 **** // String test = // "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math ! // mode=\"display\"><mrow><munderover><mo>∫</mo><mn>1</mn><mi>x</mi></munderover><mfrac><mi>dt</mi><mi>t</mi></mfrac></mrow></math>"; try { File imageFile = conv.convert(mathmlBuffer.toString(), gifFilename); if (imageFile != null) { ! Attachment attachment = new Attachment(longImageName, "image/gif", imageFile.length(), new Date(), snipname + "/" + longImageName, true); ! // fSnip.getAttachments().addAttachment(longImageName, "image/gif", imageFile.length(), snipname + "/" + longImageName, true); fSnip.getAttachments().addAttachment(attachment); StringWriter writer = new StringWriter(); --- 1367,1378 ---- // String test = // "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math ! // mode=\"display\"><mrow><munderover><mo>∫</mo><mn>1</mn><mi>x</mi></munderover><mfrac><mi>dt</mi><mi>t</mi></mfrac></mrow></math>"; try { File imageFile = conv.convert(mathmlBuffer.toString(), gifFilename); if (imageFile != null) { ! Attachment attachment = ! new Attachment(longImageName, "image/gif", imageFile.length(), new Date(), snipname + "/" + longImageName, true); ! // fSnip.getAttachments().addAttachment(longImageName, "image/gif", imageFile.length(), snipname + "/" + longImageName, ! // true); fSnip.getAttachments().addAttachment(attachment); StringWriter writer = new StringWriter(); *************** *** 1384,1390 **** // User probably wrote [http://radeox.org] instead of http://radeox.org if (index != -1) { ! CachedWikipediaFilter.createExternalLink(fResultBuffer, fWikiEngine, name.substring(index)); ! // show error ! // fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>"); } else { // trim the name and unescape it --- 1405,1429 ---- // User probably wrote [http://radeox.org] instead of http://radeox.org if (index != -1) { ! // CachedWikipediaFilter.createExternalLink(fResultBuffer, fWikiEngine, name.substring(index)); ! String urlString = name.substring(index); ! // Wikipedia like style: ! int pipeIndex = urlString.indexOf(' '); ! String alias = ""; ! if (-1 != pipeIndex) { ! alias = urlString.substring(pipeIndex + 1); ! urlString = urlString.substring(0, pipeIndex); ! } else { ! alias = urlString; ! } ! ! if (fWikiEngine instanceof ImageRenderEngine) { ! fResultBuffer.append(((ImageRenderEngine) fWikiEngine).getExternalImageLink()); ! } ! fResultBuffer.append("<span class=\"nobr\">"); ! fResultBuffer.append("<a href=\""); ! fResultBuffer.append(Encoder.escape(urlString)); ! fResultBuffer.append("\">"); ! fResultBuffer.append(Encoder.toEntity(alias.charAt(0)) + alias.substring(1)); ! fResultBuffer.append("</a></span>"); } else { // trim the name and unescape it *************** *** 1443,1450 **** fCacheStaticBlockActive = false; } ! fCachedPage.addLink(name); if (fCachedPage == CachedWikipediaFilter.DUMMY_CACHED_PAGE) { if (((WikiRenderEngine) fWikiEngine).exists(name)) { ! String view = getWikiView(name); if (-1 != pipeIndex) { view = alias; --- 1482,1489 ---- fCacheStaticBlockActive = false; } ! fCachedPage.addSnipLink(name); if (fCachedPage == CachedWikipediaFilter.DUMMY_CACHED_PAGE) { if (((WikiRenderEngine) fWikiEngine).exists(name)) { ! String view = name; if (-1 != pipeIndex) { view = alias; *************** *** 1457,1461 **** } } else if (((WikiRenderEngine) fWikiEngine).showCreate()) { ! ((WikiRenderEngine) fWikiEngine).appendCreateLink(fResultBuffer, name, getWikiView(name)); // links with "create" are not cacheable because // a missing wiki could be created --- 1496,1601 ---- } } else if (((WikiRenderEngine) fWikiEngine).showCreate()) { ! ((WikiRenderEngine) fWikiEngine).appendCreateLink(fResultBuffer, name, name); ! // links with "create" are not cacheable because ! // a missing wiki could be created ! fContext.getRenderContext().setCacheable(false); ! } else { ! // cannot display/create wiki, so just display the text ! fResultBuffer.append(name); ! } ! } ! if (!fCacheStaticBlockActive) { ! fCacheStaticBlockActive = true; ! fCacheStaticBlockStartPosition = fResultBuffer.length(); ! } ! } else { ! // cannot display/create wiki, so just display the text ! fResultBuffer.append(name); ! } ! } ! } ! } ! } ! ! private void handleWikipediaLink(String linkText, String suffix) { ! String name = linkText; ! if (name != null) { ! int index = name.indexOf("http://"); ! // User probably wrote [http://radeox.org] instead of http://radeox.org ! if (index != -1) { ! CachedWikipediaFilter.createExternalLink(fResultBuffer, fWikiEngine, name.substring(index)); ! // show error ! // fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>"); ! } else { ! // trim the name and unescape it ! name = Encoder.unescape(name.trim()); ! // Is there an alias like [alias|link] ? ! int pipeIndex = name.indexOf('|'); ! String alias = ""; ! if (-1 != pipeIndex) { ! alias = name.substring(pipeIndex + 1); ! name = name.substring(0, pipeIndex); ! } ! ! int hashIndex = name.lastIndexOf('#'); ! ! String hash = ""; ! if (-1 != hashIndex && hashIndex != name.length() - 1) { ! hash = name.substring(hashIndex + 1); ! name = name.substring(0, hashIndex); ! } ! ! int colonIndex = name.indexOf(':'); ! // typed link ? ! if (-1 != colonIndex) { ! // for now throw away the type information ! name = name.substring(colonIndex + 1); ! } ! ! int atIndex = name.lastIndexOf('@'); ! // InterWiki link ? ! if (-1 != atIndex) { ! String extSpace = name.substring(atIndex + 1); ! // known extarnal space ? ! InterWiki interWiki = InterWiki.getInstance(); ! if (interWiki.contains(extSpace)) { ! name = name.substring(0, atIndex); ! Writer writer = new StringBufferWriter(fResultBuffer); ! try { ! if (-1 != hashIndex) { ! interWiki.expand(writer, extSpace, name, hash); ! } else { ! interWiki.expand(writer, extSpace, name, ""); ! } ! } catch (IOException e) { ! log.debug("InterWiki " + extSpace + " not found."); ! } ! } else { ! fResultBuffer.append("[<span class=\"error\">"); ! fResultBuffer.append(name); ! fResultBuffer.append("?</span>]"); ! } ! } else { ! // internal link ! if (fWikiEngine != null && fWikiEngine instanceof WikiRenderEngine) { ! if (fCacheStaticBlockActive) { ! fCachedPage.addHTML(fResultBuffer.substring(fCacheStaticBlockStartPosition, fResultBuffer.length())); ! fCacheStaticBlockActive = false; ! } ! fCachedPage.addWikipediaLink(linkText, suffix); ! if (fCachedPage == CachedWikipediaFilter.DUMMY_CACHED_PAGE) { ! if (((WikiRenderEngine) fWikiEngine).exists(name)) { ! String view = name + suffix; ! if (-1 != pipeIndex) { ! view = alias + suffix; ! } ! // Do not add hash if an alias was given ! if (-1 != hashIndex) { ! ((WikiRenderEngine) fWikiEngine).appendLink(fResultBuffer, name, view, hash); ! } else { ! ((WikiRenderEngine) fWikiEngine).appendLink(fResultBuffer, name, view); ! } ! } else if (((WikiRenderEngine) fWikiEngine).showCreate()) { ! ((WikiRenderEngine) fWikiEngine).appendCreateLink(fResultBuffer, name, name + suffix); // links with "create" are not cacheable because // a missing wiki could be created *************** *** 1690,1696 **** * @return view The view of the wiki name */ ! protected String getWikiView(String name) { ! return name; ! } private void handleMacro(String completeMacroSubString, String command, String unsplittedMacroParameters, String group3) { --- 1830,1836 ---- * @return view The view of the wiki name */ ! // protected String getWikiView(String name) { ! // return name; ! // } private void handleMacro(String completeMacroSubString, String command, String unsplittedMacroParameters, String group3) { |
From: Klaus H. <js...@us...> - 2004-05-12 21:20:24
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15572/WEB-INF/src/org/hartmath/server/cache Modified Files: DummyCachedPageGenerator.java CachedPage.java CachedPageGenerator.java ICachedPageGenerator.java Log Message: Improved wikipedi syntax for internal/external links Index: ICachedPageGenerator.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/ICachedPageGenerator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ICachedPageGenerator.java 2 May 2004 17:34:10 -0000 1.2 --- ICachedPageGenerator.java 12 May 2004 21:20:14 -0000 1.3 *************** *** 25,29 **** public void addHTML(String text); ! public void addLink(String text); public void addMacro(String text); public void addMath(String[] mathStrings); --- 25,30 ---- public void addHTML(String text); ! public void addSnipLink(String text); ! public void addWikipediaLink(String text, String suffix); public void addMacro(String text); public void addMath(String[] mathStrings); Index: DummyCachedPageGenerator.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/DummyCachedPageGenerator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DummyCachedPageGenerator.java 2 May 2004 17:34:10 -0000 1.2 --- DummyCachedPageGenerator.java 12 May 2004 21:20:13 -0000 1.3 *************** *** 29,35 **** } ! public void addLink(String text) { } public void addMacro(String text) { --- 29,40 ---- } ! public void addSnipLink(String text) { } + + public void addWikipediaLink(String text, String suffix) { + + } + public void addMacro(String text) { Index: CachedPage.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/CachedPage.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CachedPage.java 2 May 2004 17:34:10 -0000 1.3 --- CachedPage.java 12 May 2004 21:20:13 -0000 1.4 *************** *** 43,50 **** } ! protected void addLinkToBuffer(String text) { CachedWikipediaFilter.handleSnipLink(fResult, fWikiEngine, text); } protected void addMacroToBuffer(String text) { CachedWikipediaFilter.createMacro(fResult, text, fContext, fMacros); --- 43,54 ---- } ! protected void addSnipLinkToBuffer(String text) { CachedWikipediaFilter.handleSnipLink(fResult, fWikiEngine, text); } + protected void addWikipediaLinkToBuffer(String[] pair) { + CachedWikipediaFilter.handleWikipediaLink(fResult, fWikiEngine, pair[0], pair[1]); + } + protected void addMacroToBuffer(String text) { CachedWikipediaFilter.createMacro(fResult, text, fContext, fMacros); *************** *** 68,74 **** addTextToBuffer(text); break; ! case CachedPageGenerator.LINK : text = (String) fTextList.get(i); ! addLinkToBuffer(text); break; case CachedPageGenerator.MACRO : --- 72,78 ---- addTextToBuffer(text); break; ! case CachedPageGenerator.SNIP_LINK : text = (String) fTextList.get(i); ! addSnipLinkToBuffer(text); break; case CachedPageGenerator.MACRO : *************** *** 80,83 **** --- 84,91 ---- addMathToBuffer(mathStrings); break; + case CachedPageGenerator.WIKIPEDIA_LINK : + String [] pair = (String []) fTextList.get(i); + addWikipediaLinkToBuffer(pair); + break; } } Index: CachedPageGenerator.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/CachedPageGenerator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CachedPageGenerator.java 2 May 2004 17:34:10 -0000 1.2 --- CachedPageGenerator.java 12 May 2004 21:20:14 -0000 1.3 *************** *** 25,34 **** public final static int HTML = 1; public final static Integer HTML_TEXT = new Integer(HTML); ! public final static int LINK = 2; ! public final static Integer LINK_TEXT = new Integer(LINK); public final static int MACRO = 3; public final static Integer MACRO_TEXT = new Integer(MACRO); public final static int MATH = 4; public final static Integer MATH_TEXT = new Integer(MATH); String fClassName; --- 25,36 ---- public final static int HTML = 1; public final static Integer HTML_TEXT = new Integer(HTML); ! public final static int SNIP_LINK = 2; ! public final static Integer SNIP_LINK_TEXT = new Integer(SNIP_LINK); public final static int MACRO = 3; public final static Integer MACRO_TEXT = new Integer(MACRO); public final static int MATH = 4; public final static Integer MATH_TEXT = new Integer(MATH); + public final static int WIKIPEDIA_LINK = 5; + public final static Integer WIKIPEDIA_LINK_TEXT = new Integer(WIKIPEDIA_LINK); String fClassName; *************** *** 56,76 **** fCurrentIndex++; } ! public void addLink(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitLink", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { ! fTypeList.add(LINK_TEXT); fTextList.add(text); } else { ! fTypeList.add(fCurrentIndex, LINK_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void addMacro(String text) { - // fCodeVisitor.visitVarInsn(ALOAD, 0); - // fCodeVisitor.visitLdcInsn(text); - // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitMacro", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(MACRO_TEXT); --- 58,88 ---- fCurrentIndex++; } ! public void addSnipLink(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitLink", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { ! fTypeList.add(SNIP_LINK_TEXT); fTextList.add(text); } else { ! fTypeList.add(fCurrentIndex, SNIP_LINK_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } + public void addWikipediaLink(String text, String suffix) { + String pair[] = new String[2]; + pair[0] = text; + pair[1] = suffix; + if (fCurrentIndex == fTypeList.size()) { + fTypeList.add(WIKIPEDIA_LINK_TEXT); + fTextList.add(pair); + } else { + fTypeList.add(fCurrentIndex, WIKIPEDIA_LINK_TEXT); + fTextList.add(fCurrentIndex, pair); + } + fCurrentIndex++; + } public void addMacro(String text) { if (fCurrentIndex == fTypeList.size()) { fTypeList.add(MACRO_TEXT); |
From: Klaus H. <js...@us...> - 2004-05-11 20:55:25
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5933/WEB-INF/src/org/hartmath/server/macro Modified Files: WeblogMacro.java CodeMacro.java Log Message: Improved wikipedi syntax Improved code:none macro for special characters <>"' Index: CodeMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/CodeMacro.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CodeMacro.java 25 Apr 2004 18:55:54 -0000 1.4 --- CodeMacro.java 11 May 2004 20:55:10 -0000 1.5 *************** *** 129,133 **** } else { formatter = (SourceCodeFormatter) formatters.get(params.get("0")); ! result = formatter.filter(params.getContent(), nullContext); } --- 129,137 ---- } else { formatter = (SourceCodeFormatter) formatters.get(params.get("0")); ! if (formatter instanceof AbstractCPPBasedCodeFilter) { ! result = formatter.filter(params.getContent(), nullContext); ! } else { ! result = formatter.filter(Encoder.escape(params.getContent()), nullContext); ! } } Index: WeblogMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/WeblogMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WeblogMacro.java 9 Mar 2004 20:13:06 -0000 1.1 --- WeblogMacro.java 11 May 2004 20:55:09 -0000 1.2 *************** *** 31,34 **** --- 31,37 ---- import java.util.List; + import org.snipsnap.app.Application; + import org.snipsnap.config.Configuration; + import org.snipsnap.render.filter.links.BackLinks; import org.snipsnap.render.macro.SnipMacro; import org.snipsnap.render.macro.parameter.SnipMacroParameter; *************** *** 127,130 **** --- 130,135 ---- } + Configuration conf = Application.get().getConfiguration(); + writer.write(entry.getXMLContent()); writer.write(" <a href=\""); *************** *** 141,147 **** writer.write(entry.getComments().getPostString()); writer.write("</div>\n\n"); ! // writer.write("<div class=\"snip-backlinks\">"); ! // BackLinks.appendTo(writer, entry.getAccess().getBackLinks(), 5); ! // writer.write("</div>"); } } else { --- 146,155 ---- writer.write(entry.getComments().getPostString()); writer.write("</div>\n\n"); ! ! if ("true".equals(conf.getFeatureReferrerShow())) { ! writer.write("<div class=\"snip-backlinks\">"); ! BackLinks.appendTo(writer, entry.getAccess().getBackLinks(), 5); ! writer.write("</div>"); ! } } } else { |
From: Klaus H. <js...@us...> - 2004-05-11 20:55:25
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5933/WEB-INF/src/org/hartmath/server/filter Modified Files: CachedWikipediaParser.java Log Message: Improved wikipedi syntax Improved code:none macro for special characters <>"' Index: CachedWikipediaParser.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CachedWikipediaParser.java 2 May 2004 17:34:10 -0000 1.3 --- CachedWikipediaParser.java 11 May 2004 20:55:10 -0000 1.4 *************** *** 18,24 **** --- 18,27 ---- package org.hartmath.server.filter; + import java.io.File; import java.io.IOException; + import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; + import java.util.Date; import java.util.Map; import java.util.NoSuchElementException; *************** *** 28,31 **** --- 31,36 ---- import javax.servlet.http.HttpServletRequest; + import net.sourceforge.jeuclid.gif.MathMLToGIFConverter; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; *************** *** 53,56 **** --- 58,62 ---- import org.snipsnap.snip.Snip; import org.snipsnap.snip.SnipLink; + import org.snipsnap.snip.attachment.Attachment; /** *************** *** 65,68 **** --- 71,76 ---- private FilterContext fContext; private RenderEngine fWikiEngine; + // TODO check, if this counter is correct in recursions: + private int fImageCounter; /** * The current snip *************** *** 122,126 **** private int fWhiteStartPosition = 0; private TeXParser fTeXParser; ! /** * --- 130,134 ---- private int fWhiteStartPosition = 0; private TeXParser fTeXParser; ! private TeXParser fTeXImageParser; /** * *************** *** 153,157 **** fRecursionLevel = recursionLevel; fTokenStack = new Stack(); ! fTeXParser = new TeXParser(""); } /** --- 161,167 ---- fRecursionLevel = recursionLevel; fTokenStack = new Stack(); ! fTeXParser = new TeXParser("", "m:"); ! fTeXImageParser = new TeXParser("", ""); ! fImageCounter = 1; } /** *************** *** 184,188 **** } /** ! * copy the content in the resulting buffer and escape special html characters (< > " & ') */ private void copyWhite(boolean whiteStart, final int whiteStartPosition, final int diff) { --- 194,198 ---- } /** ! * copy the content in the resulting buffer and escape special html characters (< > " & ') */ private void copyWhite(boolean whiteStart, final int whiteStartPosition, final int diff) { *************** *** 252,256 **** /** ! * copy the text in the resulting buffer and escape special html characters (< > " & ') */ private void copyWhite(String text) { --- 262,266 ---- /** ! * copy the text in the resulting buffer and escape special html characters (< > " & ') */ private void copyWhite(String text) { *************** *** 311,316 **** /** ! * Copy the text in the resulting buffer and escape special html characters (< > " & ') ! * Additionally every newline will be replaced by <br/> */ private void copyWhiteNewLine(String text) { --- 321,326 ---- /** ! * Copy the text in the resulting buffer and escape special html characters (< > " & ') Additionally every ! * newline will be replaced by <br/> */ private void copyWhiteNewLine(String text) { *************** *** 1054,1057 **** --- 1064,1087 ---- try { switch (fStringSource.charAt(fCurrentPosition)) { + case '!' : // <!-- html comment --> + String htmlCommentString = fStringSource.substring(fCurrentPosition - 1, fCurrentPosition + 3); + + if (htmlCommentString.equals("<!--")) { + fCurrentPosition += 3; + if (readUntilString("-->")) { + String htmlCommentContent = new String(fSource, htmlStartPosition + 3, fCurrentPosition - htmlStartPosition - 6); + if (htmlCommentContent != null) { + copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); + fWhiteStart = false; + // insert html comment for visual checks only: + /* fResultBuffer.append("<!--"); + copyWhite(htmlCommentContent); + fResultBuffer.append("-->"); + */ + continue; + } + } + } + break; case 'm' : // math String mathString = fStringSource.substring(fCurrentPosition - 1, fCurrentPosition + 5); *************** *** 1270,1287 **** mathStrings[0] = mathBuffer.toString(); mathBuffer.setLength(0); if (inlineExpression) { ! // css inline ! mathBuffer.append("<m>"); ! fTeXParser.initialize(mathContent); ! fTeXParser.parse2CSS(mathBuffer, true); ! mathBuffer.append("</m>"); } else { ! // css block mode ! mathBuffer.append("<e>"); ! fTeXParser.initialize(mathContent); ! fTeXParser.parse2CSS(mathBuffer, true); ! mathBuffer.append("</e>"); } - mathStrings[1] = mathBuffer.toString(); mathBuffer.setLength(0); CachedWikipediaFilter.copyWhite(mathBuffer, mathContent); --- 1300,1372 ---- mathStrings[0] = mathBuffer.toString(); mathBuffer.setLength(0); + // if (inlineExpression) { + // // css inline + // mathBuffer.append("<m>"); + // fTeXParser.initialize(mathContent); + // fTeXParser.parse2CSS(mathBuffer, true); + // mathBuffer.append("</m>"); + // } else { + // // css block mode + // mathBuffer.append("<e>"); + // fTeXParser.initialize(mathContent); + // fTeXParser.parse2CSS(mathBuffer, true); + // mathBuffer.append("</e>"); + // } + + String encodedMathContent = Encoder.escape(mathContent); + StringBuffer mathmlBuffer = new StringBuffer(); + String shortImageName = "____tex_" + (fImageCounter++); + String longImageName = shortImageName + ".gif"; + mathmlBuffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); if (inlineExpression) { ! mathmlBuffer.append("<math><mstyle mathcolor=\"Black\" displaystyle=\"true\">"); ! fTeXImageParser.initialize(mathContent); ! fTeXImageParser.parse2MML(mathmlBuffer); ! mathmlBuffer.append("</mstyle></math>"); } else { ! mathmlBuffer.append("<math><mstyle mathcolor=\"Black\" displaystyle=\"true\">"); ! fTeXImageParser.initialize(mathContent); ! fTeXImageParser.parse2MML(mathmlBuffer); ! mathmlBuffer.append("</mstyle></math>"); ! } ! ! String snipname = fSnip.getName(); ! String SnipSnapSpacePath = Application.get().getConfiguration().getFilePath().getAbsolutePath(); ! // Remove old image ! fSnip.getAttachments().removeAttachment(longImageName + ".gif"); ! ! String directoryName = SnipSnapSpacePath + "/" + snipname; ! File directory = new File(directoryName); ! if (!directory.exists()) { ! directory.mkdirs(); ! } ! String gifFilename = directoryName + "/" + longImageName; ! // File file = new File(); ! // Get the number of bytes in the file ! // long length = file.length(); ! MathMLToGIFConverter conv = new MathMLToGIFConverter(); ! // String test = ! // "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math ! // mode=\"display\"><mrow><munderover><mo>∫</mo><mn>1</mn><mi>x</mi></munderover><mfrac><mi>dt</mi><mi>t</mi></mfrac></mrow></math>"; ! try { ! File imageFile = conv.convert(mathmlBuffer.toString(), gifFilename); ! if (imageFile != null) { ! Attachment attachment = new Attachment(longImageName, "image/gif", imageFile.length(), new Date(), snipname + "/" + longImageName, true); ! // fSnip.getAttachments().addAttachment(longImageName, "image/gif", imageFile.length(), snipname + "/" + longImageName, true); ! fSnip.getAttachments().addAttachment(attachment); ! StringWriter writer = new StringWriter(); ! ! SnipLink.appendImage(writer, fSnip, shortImageName, encodedMathContent, "gif", null); ! ! mathBuffer = writer.getBuffer(); ! mathStrings[1] = mathBuffer.toString(); ! } else { ! mathStrings[1] = encodedMathContent; ! } ! } catch (IOException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! mathStrings[1] = encodedMathContent; } mathBuffer.setLength(0); CachedWikipediaFilter.copyWhite(mathBuffer, mathContent); |
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25118/WEB-INF/src/org/hartmath/server/cache Modified Files: DummyCachedPageGenerator.java CachedPage.java CachedPageGenerator.java ICachedPageGenerator.java Added Files: LRUCache.java Log Message: Improved cache; fixed "table of content" bug Index: ICachedPageGenerator.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/ICachedPageGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ICachedPageGenerator.java 2 May 2004 12:43:06 -0000 1.1 --- ICachedPageGenerator.java 2 May 2004 17:34:10 -0000 1.2 *************** *** 1,2 **** --- 1,19 ---- + /* + * This file is part of the "HMath MathML BLOG/Wiki Engine". + * + * Copyright (c) 2004 Klaus Hartlage All Rights Reserved. + * + * Please visit http://www.hmath.org/ for updates and contact. + * + * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser + * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- + */ package org.hartmath.server.cache; Index: DummyCachedPageGenerator.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/DummyCachedPageGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DummyCachedPageGenerator.java 2 May 2004 12:43:06 -0000 1.1 --- DummyCachedPageGenerator.java 2 May 2004 17:34:10 -0000 1.2 *************** *** 1,2 **** --- 1,19 ---- + /* + * This file is part of the "HMath MathML BLOG/Wiki Engine". + * + * Copyright (c) 2004 Klaus Hartlage All Rights Reserved. + * + * Please visit http://www.hmath.org/ for updates and contact. + * + * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser + * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- + */ package org.hartmath.server.cache; Index: CachedPage.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/CachedPage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CachedPage.java 2 May 2004 12:43:06 -0000 1.2 --- CachedPage.java 2 May 2004 17:34:10 -0000 1.3 *************** *** 1,2 **** --- 1,19 ---- + /* + * This file is part of the "HMath MathML BLOG/Wiki Engine". + * + * Copyright (c) 2004 Klaus Hartlage All Rights Reserved. + * + * Please visit http://www.hmath.org/ for updates and contact. + * + * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser + * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- + */ package org.hartmath.server.cache; --- NEW FILE: LRUCache.java --- /* * This file is part of the "HMath MathML BLOG/Wiki Engine". * * Copyright (c) 2004 Klaus Hartlage All Rights Reserved. * * Please visit http://www.hmath.org/ for updates and contact. * * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any * later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- */ package org.hartmath.server.cache; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; /** * Least recently used cache for CachedPages * * Ref.: JDCTechTips July 2002 */ public class LRUCache { private final int MAX_NUMBER_OF_PAGES = 1000; private Map cache; public LRUCache() { cache = new LinkedHashMap(MAX_NUMBER_OF_PAGES+1, .75F) { public boolean removeEldestEntry(Map.Entry eldest) { return size() > MAX_NUMBER_OF_PAGES; } }; // the cache must be thread-safe: cache = (Map)Collections.synchronizedMap(cache); } /** * @param key * @return */ public boolean containsKey(String key) { return cache.containsKey(key); } /** * @param value * @return */ public boolean containsValue(CachedPage value) { return cache.containsValue(value); } /** * @param key * @return */ public CachedPage get(String key) { return (CachedPage)cache.get(key); } /** * @param key * @param value * @return */ public CachedPage put(String key, CachedPage value) { return (CachedPage)cache.put(key, value); } /** * @param key * @return */ public Object remove(String key) { return cache.remove(key); } } Index: CachedPageGenerator.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/CachedPageGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CachedPageGenerator.java 2 May 2004 12:43:06 -0000 1.1 --- CachedPageGenerator.java 2 May 2004 17:34:10 -0000 1.2 *************** *** 1,10 **** package org.hartmath.server.cache; import java.util.ArrayList; - import java.util.HashMap; public class CachedPageGenerator extends ClassLoader implements ICachedPageGenerator { public static long CLASS_COUNTER = 0; ! public static HashMap PAGE_MAP = new HashMap(); public final static int HTML = 1; public final static Integer HTML_TEXT = new Integer(HTML); --- 1,26 ---- + /* + * This file is part of the "HMath MathML BLOG/Wiki Engine". + * + * Copyright (c) 2004 Klaus Hartlage All Rights Reserved. + * + * Please visit http://www.hmath.org/ for updates and contact. + * + * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser + * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- + */ package org.hartmath.server.cache; import java.util.ArrayList; public class CachedPageGenerator extends ClassLoader implements ICachedPageGenerator { public static long CLASS_COUNTER = 0; ! public static LRUCache LRU_CACHED_PAGE_MAP = new LRUCache(); public final static int HTML = 1; public final static Integer HTML_TEXT = new Integer(HTML); |
From: Klaus H. <js...@us...> - 2004-05-02 17:34:20
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25118/WEB-INF/src/org/hartmath/server/render Modified Files: HMathRenderEngine.java Log Message: Improved cache; fixed "table of content" bug Index: HMathRenderEngine.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/HMathRenderEngine.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HMathRenderEngine.java 2 May 2004 12:43:07 -0000 1.2 --- HMathRenderEngine.java 2 May 2004 17:34:10 -0000 1.3 *************** *** 126,130 **** filterContext.setRenderContext(context); context.setRenderEngine(this); ! Map map = Application.get().getParameters(); HttpServletRequest request = (HttpServletRequest) map.get("request"); if (request.getAttribute("previewMode") != null) { --- 126,130 ---- filterContext.setRenderContext(context); context.setRenderEngine(this); ! Map map = Application.get().getParameters(); HttpServletRequest request = (HttpServletRequest) map.get("request"); if (request.getAttribute("previewMode") != null) { *************** *** 135,139 **** return f.filter(content, filterContext, macros, CachedWikipediaFilter.DUMMY_CACHED_PAGE, 1); } ! CachedWikipediaFilter f = new CachedWikipediaFilter(); MacroRepository macros = MacroRepository.getInstance(); --- 135,139 ---- return f.filter(content, filterContext, macros, CachedWikipediaFilter.DUMMY_CACHED_PAGE, 1); } ! CachedWikipediaFilter f = new CachedWikipediaFilter(); MacroRepository macros = MacroRepository.getInstance(); *************** *** 148,168 **** } name = ((String) Application.get().getObject(Application.OID)) + name; ! String versionName = name+ snip.getVersion(); ! ! CachedPage cachedPage = (CachedPage) CachedPageGenerator.PAGE_MAP.get(versionName); if (cachedPage == null) { ! versionName = name+ (snip.getVersion()-1); ! cachedPage = (CachedPage) CachedPageGenerator.PAGE_MAP.get(versionName); if (cachedPage != null) { // delete previous version ! // System.out.println("remove:"+versionName); ! synchronized (CachedPageGenerator.PAGE_MAP){ ! CachedPageGenerator.PAGE_MAP.remove(versionName); ! } } } else { try { ! // System.out.println("found:"+versionName); ! return ((CachedPage)cachedPage.clone()).filter(filterContext, macros); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block --- 148,166 ---- } name = ((String) Application.get().getObject(Application.OID)) + name; ! String versionName = name + snip.getVersion(); ! ! CachedPage cachedPage = (CachedPage) CachedPageGenerator.LRU_CACHED_PAGE_MAP.get(versionName); if (cachedPage == null) { ! versionName = name + (snip.getVersion() - 1); ! cachedPage = (CachedPage) CachedPageGenerator.LRU_CACHED_PAGE_MAP.get(versionName); if (cachedPage != null) { // delete previous version ! // System.out.println("remove:"+versionName); ! CachedPageGenerator.LRU_CACHED_PAGE_MAP.remove(versionName); } } else { try { ! // System.out.println("found:"+versionName); ! return ((CachedPage) cachedPage.clone()).filter(filterContext, macros); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block *************** *** 177,190 **** cachedPage = compiler.getCachedPage(); if (cachedPage != null && name != null) { ! versionName = name+ snip.getVersion(); ! // System.out.println("put:"+versionName); ! synchronized (CachedPageGenerator.PAGE_MAP){ ! CachedPageGenerator.PAGE_MAP.put(versionName, cachedPage); ! } return cachedPage.filter(filterContext, macros); } return result; } ! public String renderSnippet(String content, RenderContext context) { init(); --- 175,186 ---- cachedPage = compiler.getCachedPage(); if (cachedPage != null && name != null) { ! versionName = name + snip.getVersion(); ! // System.out.println("put:"+versionName); ! CachedPageGenerator.LRU_CACHED_PAGE_MAP.put(versionName, cachedPage); return cachedPage.filter(filterContext, macros); } return result; } ! public String renderSnippet(String content, RenderContext context) { init(); *************** *** 192,196 **** filterContext.setRenderContext(context); context.setRenderEngine(this); ! CachedWikipediaFilter f = new CachedWikipediaFilter(); // f.setInitialContext(new BaseInitialRenderContext()); --- 188,192 ---- filterContext.setRenderContext(context); context.setRenderEngine(this); ! CachedWikipediaFilter f = new CachedWikipediaFilter(); // f.setInitialContext(new BaseInitialRenderContext()); |
From: Klaus H. <js...@us...> - 2004-05-02 17:34:20
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25118/WEB-INF/src/org/hartmath/server/filter Modified Files: CachedWikipediaParser.java Log Message: Improved cache; fixed "table of content" bug Index: CachedWikipediaParser.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CachedWikipediaParser.java 2 May 2004 12:43:07 -0000 1.2 --- CachedWikipediaParser.java 2 May 2004 17:34:10 -0000 1.3 *************** *** 1483,1487 **** // copy fResult and new initialization: - fCurrentCachedPageArrayIndex = fCachedPage.getCurrentIndex(); fResultBufferHeader = fResultBuffer; if (fCacheStaticBlockActive) { --- 1483,1486 ---- *************** *** 1489,1492 **** --- 1488,1492 ---- fCacheStaticBlockActive = false; } + fCurrentCachedPageArrayIndex = fCachedPage.getCurrentIndex(); fCacheStaticBlockActive = true; fCacheStaticBlockStartPosition = 0; |
From: Klaus H. <js...@us...> - 2004-05-02 12:45:32
|
Update of /cvsroot/hmath/org.hartmath.tex2mml/src/org/hartmath/tex2mml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv709/src/org/hartmath/tex2mml Modified Files: TeX2MathMLFactory.java Log Message: misc changes Index: TeX2MathMLFactory.java =================================================================== RCS file: /cvsroot/hmath/org.hartmath.tex2mml/src/org/hartmath/tex2mml/TeX2MathMLFactory.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TeX2MathMLFactory.java 14 Apr 2004 19:54:22 -0000 1.9 --- TeX2MathMLFactory.java 2 May 2004 12:45:24 -0000 1.10 *************** *** 191,195 **** CONSTANT_SYMBOLS.put("\\infty", new Operator(toEntity('\u221E'), CONSTANT)); CONSTANT_SYMBOLS.put("\\aleph", new Operator(toEntity('\u2135'), CONSTANT)); ! CONSTANT_SYMBOLS.put("\\ldots", new Operator(toEntity('\u222B'), CONSTANT)); String quad = toEntity('\u00A0') + toEntity('\u00A0'); // TODO find a better way to distinguish the different spacings: --- 191,195 ---- CONSTANT_SYMBOLS.put("\\infty", new Operator(toEntity('\u221E'), CONSTANT)); CONSTANT_SYMBOLS.put("\\aleph", new Operator(toEntity('\u2135'), CONSTANT)); ! String quad = toEntity('\u00A0') + toEntity('\u00A0'); // TODO find a better way to distinguish the different spacings: *************** *** 199,203 **** CONSTANT_SYMBOLS.put("\\quad", new Space("thickmathspace", quad)); CONSTANT_SYMBOLS.put("\\qquad", new Space("verythickmathspace",quad+quad)); ! CONSTANT_SYMBOLS.put("\\cdots", new Operator(toEntity('\u22EF'), CONSTANT)); CONSTANT_SYMBOLS.put("\\diamond", new Operator(toEntity('\u22C4'), CONSTANT)); CONSTANT_SYMBOLS.put("\\square", new Operator(toEntity('\u25A1'), CONSTANT)); --- 199,209 ---- CONSTANT_SYMBOLS.put("\\quad", new Space("thickmathspace", quad)); CONSTANT_SYMBOLS.put("\\qquad", new Space("verythickmathspace",quad+quad)); ! ! CONSTANT_SYMBOLS.put("\\dots", new Operator("…", CONSTANT)); ! CONSTANT_SYMBOLS.put("\\ldots", new Operator("…", CONSTANT)); ! CONSTANT_SYMBOLS.put("\\cdots", new Operator("⋯", CONSTANT)); ! CONSTANT_SYMBOLS.put("\\ddots", new Operator("⋱", CONSTANT)); ! CONSTANT_SYMBOLS.put("\\udots", new Operator("⋰", CONSTANT)); ! CONSTANT_SYMBOLS.put("\\vdots", new Operator("⋮", CONSTANT)); CONSTANT_SYMBOLS.put("\\diamond", new Operator(toEntity('\u22C4'), CONSTANT)); CONSTANT_SYMBOLS.put("\\square", new Operator(toEntity('\u25A1'), CONSTANT)); *************** *** 222,225 **** --- 228,247 ---- CONSTANT_SYMBOLS.put("\\unlhd", new Operator("⊴", CONSTANT)); + CONSTANT_SYMBOLS.put("\\beth", new Operator("ℶ", CONSTANT)); + CONSTANT_SYMBOLS.put("\\Subset", new Operator("⋐", CONSTANT)); + CONSTANT_SYMBOLS.put("\\bigtriangleup", new Operator("△", CONSTANT)); + CONSTANT_SYMBOLS.put("\\smallsmile", new Operator("⌣", CONSTANT)); + CONSTANT_SYMBOLS.put("\\bumpeq", new Operator("≏", CONSTANT)); + CONSTANT_SYMBOLS.put("\\ggg", new Operator("⋙", CONSTANT)); + CONSTANT_SYMBOLS.put("\\pitchfork", new Operator("⋔", CONSTANT)); + + CONSTANT_SYMBOLS.put("\\infinity", new Operator(toEntity('\u221E'), CONSTANT)); + + CONSTANT_SYMBOLS.put("\\naturals", new Operator("ℕ", CONSTANT)); + CONSTANT_SYMBOLS.put("\\integers", new Operator("ℤ", CONSTANT)); + CONSTANT_SYMBOLS.put("\\reals", new Operator("ℝ", CONSTANT)); + CONSTANT_SYMBOLS.put("\\rationals", new Operator("ℚ", CONSTANT)); + CONSTANT_SYMBOLS.put("\\irrationals", new Operator("ℙ", CONSTANT)); + // {input:"\\ ", tag:"mo", output:"\u00A0"}, // {input:"CC", tag:"mo", output:"\u2102"}, // \mathbf{C} |
From: Klaus H. <js...@us...> - 2004-05-02 12:43:18
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32636/WEB-INF/src/org/hartmath/server/render Modified Files: HMathRenderEngine.java Log Message: misc changes Index: HMathRenderEngine.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/HMathRenderEngine.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HMathRenderEngine.java 25 Apr 2004 18:55:56 -0000 1.1 --- HMathRenderEngine.java 2 May 2004 12:43:07 -0000 1.2 *************** *** 25,29 **** import javax.servlet.http.HttpServletRequest; ! import org.hartmath.server.cache.CachedPageCompiler; import org.hartmath.server.cache.CachedPage; --- 25,29 ---- import javax.servlet.http.HttpServletRequest; ! import org.hartmath.server.cache.CachedPageGenerator; import org.hartmath.server.cache.CachedPage; *************** *** 150,162 **** String versionName = name+ snip.getVersion(); ! CachedPage cachedPage = (CachedPage) CachedPageCompiler.PAGE_MAP.get(versionName); if (cachedPage == null) { versionName = name+ (snip.getVersion()-1); ! cachedPage = (CachedPage) CachedPageCompiler.PAGE_MAP.get(versionName); if (cachedPage != null) { // delete previous version // System.out.println("remove:"+versionName); ! synchronized (CachedPageCompiler.PAGE_MAP){ ! CachedPageCompiler.PAGE_MAP.remove(versionName); } } --- 150,162 ---- String versionName = name+ snip.getVersion(); ! CachedPage cachedPage = (CachedPage) CachedPageGenerator.PAGE_MAP.get(versionName); if (cachedPage == null) { versionName = name+ (snip.getVersion()-1); ! cachedPage = (CachedPage) CachedPageGenerator.PAGE_MAP.get(versionName); if (cachedPage != null) { // delete previous version // System.out.println("remove:"+versionName); ! synchronized (CachedPageGenerator.PAGE_MAP){ ! CachedPageGenerator.PAGE_MAP.remove(versionName); } } *************** *** 172,176 **** // create a new class: ! CachedPageCompiler compiler = new CachedPageCompiler("P" + Long.toString(CachedPageCompiler.CLASS_COUNTER)); String result = f.filter(content, filterContext, macros, compiler, 0); --- 172,176 ---- // create a new class: ! CachedPageGenerator compiler = new CachedPageGenerator("P" + Long.toString(CachedPageGenerator.CLASS_COUNTER)); String result = f.filter(content, filterContext, macros, compiler, 0); *************** *** 179,184 **** versionName = name+ snip.getVersion(); // System.out.println("put:"+versionName); ! synchronized (CachedPageCompiler.PAGE_MAP){ ! CachedPageCompiler.PAGE_MAP.put(versionName, cachedPage); } return cachedPage.filter(filterContext, macros); --- 179,184 ---- versionName = name+ snip.getVersion(); // System.out.println("put:"+versionName); ! synchronized (CachedPageGenerator.PAGE_MAP){ ! CachedPageGenerator.PAGE_MAP.put(versionName, cachedPage); } return cachedPage.filter(filterContext, macros); |
From: Klaus H. <js...@us...> - 2004-05-02 12:43:15
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32636/WEB-INF/src/org/hartmath/server/filter Modified Files: CachedWikipediaParser.java CachedWikipediaFilter.java Log Message: misc changes Index: CachedWikipediaFilter.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CachedWikipediaFilter.java 25 Apr 2004 18:50:07 -0000 1.1 --- CachedWikipediaFilter.java 2 May 2004 12:43:07 -0000 1.2 *************** *** 16,20 **** * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- */ - package org.hartmath.server.filter; --- 16,19 ---- *************** *** 30,35 **** import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; ! import org.hartmath.server.cache.DummyCachedPage; ! import org.hartmath.server.cache.ICachedPage; import org.hartmath.server.taglib.MathSniffer; import org.radeox.api.engine.ImageRenderEngine; --- 29,34 ---- import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; ! import org.hartmath.server.cache.DummyCachedPageGenerator; ! import org.hartmath.server.cache.ICachedPageGenerator; import org.hartmath.server.taglib.MathSniffer; import org.radeox.api.engine.ImageRenderEngine; *************** *** 50,56 **** /** * Parse the input and transform it for the most used wiki patterns */ public class CachedWikipediaFilter extends FilterSupport implements CacheFilter, IWikipediaFilterConstants { ! public static final DummyCachedPage DUMMY_CACHED_PAGE = new DummyCachedPage(); public class InvalidInputException extends Exception { --- 49,59 ---- /** * Parse the input and transform it for the most used wiki patterns + * + * Parts of the Wiki Syntax are borrowed from Wikipedia.org and SnipSnap.org + * + * @see org.hartmath.server.filter.CachedWikipediaParser */ public class CachedWikipediaFilter extends FilterSupport implements CacheFilter, IWikipediaFilterConstants { ! public static final DummyCachedPageGenerator DUMMY_CACHED_PAGE = new DummyCachedPageGenerator(); public class InvalidInputException extends Exception { *************** *** 423,431 **** } ! public String filter(String input, FilterContext context, MacroRepository macros, ICachedPage compiler, int recursionLevel) { try { if (++recursionLevel > RECURSION_LIMIT) { String error = "<span class=\"error\">Error - recursion limit exceeded.</span>"; ! compiler.compileHTML(error); return error; } --- 426,434 ---- } ! public String filter(String input, FilterContext context, MacroRepository macros, ICachedPageGenerator compiler, int recursionLevel) { try { if (++recursionLevel > RECURSION_LIMIT) { String error = "<span class=\"error\">Error - recursion limit exceeded.</span>"; ! compiler.addHTML(error); return error; } *************** *** 447,451 **** } String error = "<span class=\"error\">Error in Parser.</span>"; ! compiler.compileHTML(error); return error; } --- 450,454 ---- } String error = "<span class=\"error\">Error in Parser.</span>"; ! compiler.addHTML(error); return error; } *************** *** 454,458 **** String input, FilterContext context, ! ICachedPage compiler, MacroRepository macros, int recursionLevel) { --- 457,461 ---- String input, FilterContext context, ! ICachedPageGenerator compiler, MacroRepository macros, int recursionLevel) { Index: CachedWikipediaParser.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/CachedWikipediaParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CachedWikipediaParser.java 25 Apr 2004 18:50:07 -0000 1.1 --- CachedWikipediaParser.java 2 May 2004 12:43:07 -0000 1.2 *************** *** 1,6 **** /* ! * Created on 21.04.2004 * ! * To change the template for this generated file go to Window - Preferences - Java - Code Generation - Code and Comments */ package org.hartmath.server.filter; --- 1,18 ---- /* ! * This file is part of the "HMath MathML BLOG/Wiki Engine". * [...1633 lines suppressed...] ! fResultBufferHeader.append("<ol>"); createToC((ArrayList) toc.get(i)); ! fResultBufferHeader.append("</ol>"); } else { ! fResultBufferHeader.append(toc.get(i)); } } *************** *** 1881,1885 **** private void unexpectedTag(String tag) { ! fResult.append("<div class=\"error\">Unexpected end for tag: <" + tag + "></div>"); } --- 1933,1937 ---- private void unexpectedTag(String tag) { ! fResultBuffer.append("<div class=\"error\">Unexpected end for tag: <" + tag + "></div>"); } |
From: Klaus H. <js...@us...> - 2004-05-02 12:43:15
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32636/WEB-INF/src/org/hartmath/server/cache Modified Files: CachedPage.java Added Files: DummyCachedPageGenerator.java CachedPageGenerator.java ICachedPageGenerator.java Removed Files: ICachedPage.java CachedPageCompiler.java DummyCachedPage.java Log Message: misc changes --- NEW FILE: ICachedPageGenerator.java --- package org.hartmath.server.cache; /** * * Interface for a CachedPage generator */ public interface ICachedPageGenerator { public void addHTML(String text); public void addLink(String text); public void addMacro(String text); public void addMath(String[] mathStrings); public int getCurrentIndex(); public void setCurrentIndex(int currentIndex); public CachedPage getCachedPage(); } --- NEW FILE: DummyCachedPageGenerator.java --- package org.hartmath.server.cache; /** * * Dummy implementation - internally used by the parser * * @see org.hartmath.server.filter.CachedWikipediaParser */ public class DummyCachedPageGenerator implements ICachedPageGenerator { public void addHTML(String text) { } public void addLink(String text) { } public void addMacro(String text) { } public void addMath(String[] mathStrings) { } public int getCurrentIndex() { return 0; } public void setCurrentIndex(int currentIndex) { } public CachedPage getCachedPage() { return null; } } --- ICachedPage.java DELETED --- --- NEW FILE: CachedPageGenerator.java --- package org.hartmath.server.cache; import java.util.ArrayList; import java.util.HashMap; public class CachedPageGenerator extends ClassLoader implements ICachedPageGenerator { public static long CLASS_COUNTER = 0; public static HashMap PAGE_MAP = new HashMap(); public final static int HTML = 1; public final static Integer HTML_TEXT = new Integer(HTML); public final static int LINK = 2; public final static Integer LINK_TEXT = new Integer(LINK); public final static int MACRO = 3; public final static Integer MACRO_TEXT = new Integer(MACRO); public final static int MATH = 4; public final static Integer MATH_TEXT = new Integer(MATH); String fClassName; int fCurrentIndex; ArrayList fTextList; ArrayList fTypeList; public CachedPageGenerator(String className) { fClassName = className; fTypeList = new ArrayList(); fTextList = new ArrayList(); fCurrentIndex = 0; } public void addHTML(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitText", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(HTML_TEXT); fTextList.add(text); } else { fTypeList.add(fCurrentIndex, HTML_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void addLink(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitLink", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(LINK_TEXT); fTextList.add(text); } else { fTypeList.add(fCurrentIndex, LINK_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void addMacro(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitMacro", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(MACRO_TEXT); fTextList.add(text); } else { fTypeList.add(fCurrentIndex, MACRO_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void addMath(String[] mathStrings) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); //// fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(inlineExpression); // // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitMath", // "(Ljava/lang/String;Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(MATH_TEXT); fTextList.add(mathStrings); } else { fTypeList.add(fCurrentIndex, MATH_TEXT); fTextList.add(fCurrentIndex, mathStrings); } fCurrentIndex++; } /** * @return Returns the currentIndex. */ public int getCurrentIndex() { return fCurrentIndex; } /** * @param currentIndex * The currentIndex to set. */ public void setCurrentIndex(int currentIndex) { fCurrentIndex = currentIndex; } public CachedPage getCachedPage() { CachedPage p = new CachedPage(); p.fTextList = fTextList; p.fTypeList = fTypeList; return p; } } --- CachedPageCompiler.java DELETED --- Index: CachedPage.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache/CachedPage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CachedPage.java 25 Apr 2004 18:46:35 -0000 1.1 --- CachedPage.java 2 May 2004 12:43:06 -0000 1.2 *************** *** 9,12 **** --- 9,16 ---- import org.radeox.macro.MacroRepository; + /** + * A cached wiki (snip) representation + * + */ public class CachedPage implements Cloneable { FilterContext fContext; *************** *** 22,38 **** } ! protected void emitLink(String text) { CachedWikipediaFilter.handleSnipLink(fResult, fWikiEngine, text); } ! protected void emitMacro(String text) { CachedWikipediaFilter.createMacro(fResult, text, fContext, fMacros); } ! protected void emitMath(String[] mathStrings) { CachedWikipediaFilter.handleTeXMath(fResult, mathStrings); } ! protected void emitText(String text) { fResult.append(text); } --- 26,42 ---- } ! protected void addLinkToBuffer(String text) { CachedWikipediaFilter.handleSnipLink(fResult, fWikiEngine, text); } ! protected void addMacroToBuffer(String text) { CachedWikipediaFilter.createMacro(fResult, text, fContext, fMacros); } ! protected void addMathToBuffer(String[] mathStrings) { CachedWikipediaFilter.handleTeXMath(fResult, mathStrings); } ! protected void addTextToBuffer(String text) { fResult.append(text); } *************** *** 43,61 **** String text; switch (type) { ! case CachedPageCompiler.HTML : text = (String) fTextList.get(i); ! emitText(text); break; ! case CachedPageCompiler.LINK : text = (String) fTextList.get(i); ! emitLink(text); break; ! case CachedPageCompiler.MACRO : text = (String) fTextList.get(i); ! emitMacro(text); break; ! case CachedPageCompiler.MATH : String[] mathStrings = (String[]) fTextList.get(i); ! emitMath(mathStrings); break; } --- 47,65 ---- String text; switch (type) { ! case CachedPageGenerator.HTML : text = (String) fTextList.get(i); ! addTextToBuffer(text); break; ! case CachedPageGenerator.LINK : text = (String) fTextList.get(i); ! addLinkToBuffer(text); break; ! case CachedPageGenerator.MACRO : text = (String) fTextList.get(i); ! addMacroToBuffer(text); break; ! case CachedPageGenerator.MATH : String[] mathStrings = (String[]) fTextList.get(i); ! addMathToBuffer(mathStrings); break; } --- DummyCachedPage.java DELETED --- |
From: Klaus H. <js...@us...> - 2004-04-25 19:20:49
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23995/WEB-INF/src/org/hartmath/server/cache Added Files: ICachedPage.java CachedPage.java CachedPageCompiler.java DummyCachedPage.java Log Message: misc changes --- NEW FILE: CachedPage.java --- package org.hartmath.server.cache; import java.util.ArrayList; import org.hartmath.server.filter.CachedWikipediaFilter; import org.hartmath.tex2mml.TeXParser; import org.radeox.api.engine.RenderEngine; import org.radeox.filter.context.FilterContext; import org.radeox.macro.MacroRepository; public class CachedPage implements Cloneable { FilterContext fContext; MacroRepository fMacros; StringBuffer fResult; private TeXParser fTeXParser; RenderEngine fWikiEngine; ArrayList fTextList; ArrayList fTypeList; public CachedPage() { fTeXParser = new TeXParser(""); } protected void emitLink(String text) { CachedWikipediaFilter.handleSnipLink(fResult, fWikiEngine, text); } protected void emitMacro(String text) { CachedWikipediaFilter.createMacro(fResult, text, fContext, fMacros); } protected void emitMath(String[] mathStrings) { CachedWikipediaFilter.handleTeXMath(fResult, mathStrings); } protected void emitText(String text) { fResult.append(text); } public void render() { for (int i = 0; i < fTypeList.size(); i++) { int type = ((Integer) fTypeList.get(i)).intValue(); String text; switch (type) { case CachedPageCompiler.HTML : text = (String) fTextList.get(i); emitText(text); break; case CachedPageCompiler.LINK : text = (String) fTextList.get(i); emitLink(text); break; case CachedPageCompiler.MACRO : text = (String) fTextList.get(i); emitMacro(text); break; case CachedPageCompiler.MATH : String[] mathStrings = (String[]) fTextList.get(i); emitMath(mathStrings); break; } } } /** * @return Returns the context. */ public FilterContext getContext() { return fContext; } /** * @param context * The context to set. */ public String filter(FilterContext context, MacroRepository macros) { fContext = context; fMacros = macros; fWikiEngine = context.getRenderContext().getRenderEngine(); if (fResult != null) { fResult.setLength(0); } else { fResult = new StringBuffer(); } render(); return fResult.toString(); } /* * (non-Javadoc) * * @see java.lang.Object#clone() */ public Object clone() throws CloneNotSupportedException { CachedPage p = new CachedPage(); p.fTextList = fTextList; p.fTypeList = fTypeList; return p; } } --- NEW FILE: CachedPageCompiler.java --- package org.hartmath.server.cache; import java.util.ArrayList; import java.util.HashMap; public class CachedPageCompiler extends ClassLoader implements ICachedPage { public static long CLASS_COUNTER = 0; public static HashMap PAGE_MAP = new HashMap(); public final static int HTML = 1; public final static Integer HTML_TEXT = new Integer(HTML); public final static int LINK = 2; public final static Integer LINK_TEXT = new Integer(LINK); public final static int MACRO = 3; public final static Integer MACRO_TEXT = new Integer(MACRO); public final static int MATH = 4; public final static Integer MATH_TEXT = new Integer(MATH); String fClassName; int fCurrentIndex; ArrayList fTextList; ArrayList fTypeList; public CachedPageCompiler(String className) { fClassName = className; fTypeList = new ArrayList(); fTextList = new ArrayList(); fCurrentIndex = 0; } public void compileHTML(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitText", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(HTML_TEXT); fTextList.add(text); } else { fTypeList.add(fCurrentIndex, HTML_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void compileLink(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitLink", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(LINK_TEXT); fTextList.add(text); } else { fTypeList.add(fCurrentIndex, LINK_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void compileMacro(String text) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitMacro", "(Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(MACRO_TEXT); fTextList.add(text); } else { fTypeList.add(fCurrentIndex, MACRO_TEXT); fTextList.add(fCurrentIndex, text); } fCurrentIndex++; } public void compileMath(String[] mathStrings) { // fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(text); //// fCodeVisitor.visitVarInsn(ALOAD, 0); // fCodeVisitor.visitLdcInsn(inlineExpression); // // fCodeVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/hartmath/server/asm/ASMPage", "emitMath", // "(Ljava/lang/String;Ljava/lang/String;)V"); if (fCurrentIndex == fTypeList.size()) { fTypeList.add(MATH_TEXT); fTextList.add(mathStrings); } else { fTypeList.add(fCurrentIndex, MATH_TEXT); fTextList.add(fCurrentIndex, mathStrings); } fCurrentIndex++; } /** * @return Returns the currentIndex. */ public int getCurrentIndex() { return fCurrentIndex; } /** * @param currentIndex * The currentIndex to set. */ public void setCurrentIndex(int currentIndex) { fCurrentIndex = currentIndex; } public CachedPage getCachedPage() { CachedPage p = new CachedPage(); p.fTextList = fTextList; p.fTypeList = fTypeList; return p; } } --- NEW FILE: ICachedPage.java --- package org.hartmath.server.cache; public interface ICachedPage { public void compileHTML(String text); public void compileLink(String text); public void compileMacro(String text); public void compileMath(String[] mathStrings); public int getCurrentIndex(); public void setCurrentIndex(int currentIndex); } --- NEW FILE: DummyCachedPage.java --- package org.hartmath.server.cache; public class DummyCachedPage implements ICachedPage { public void compileHTML(String text) { } public void compileLink(String text) { } public void compileMacro(String text) { } public void compileMath(String[] mathStrings) { } public int getCurrentIndex() { return 0; } public void setCurrentIndex(int currentIndex) { } } |
From: Klaus H. <js...@us...> - 2004-04-25 19:20:36
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/filter/context In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25944/WEB-INF/src/org/hartmath/server/render/filter/context Added Files: HMathFilterContext.java Log Message: misc changes --- NEW FILE: HMathFilterContext.java --- /* * This file is part of "SnipSnap Wiki/Weblog". * * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel * All Rights Reserved. * * Please visit http://snipsnap.org/ for updates and contact. * * --LICENSE NOTICE-- * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * --LICENSE NOTICE-- */ package org.hartmath.server.render.filter.context; import org.radeox.macro.parameter.MacroParameter; import org.radeox.filter.context.BaseFilterContext; import org.snipsnap.render.macro.parameter.SnipMacroParameter; import org.snipsnap.render.context.SnipRenderContext; import org.snipsnap.snip.Snip; /** * Special implementation of FilterContext to execute * filters in a SnipSnap enviroment. Especially stores * the snip in which it is called. * * @author Stephan J. Schmidt * @version $Id: HMathFilterContext.java,v 1.1 2004/04/25 18:55:59 jsurfer Exp $ */ public class HMathFilterContext extends BaseFilterContext { private Snip snip; public HMathFilterContext(Snip snip) { this.snip = snip; } public Snip getSnip() { return snip; } public SnipRenderContext getSnipRenderContext() { return (SnipRenderContext) this.context; } public MacroParameter getMacroParameter() { return new SnipMacroParameter(this.context); } } |
From: Klaus H. <js...@us...> - 2004-04-25 19:11:35
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25858/WEB-INF/src/org/hartmath/server/render/filter Log Message: Directory /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/filter added to the repository |
From: Klaus H. <js...@us...> - 2004-04-25 19:03:18
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/table In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25944/WEB-INF/src/org/hartmath/server/macro/table Modified Files: Table.java Log Message: misc changes Index: Table.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/table/Table.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Table.java 9 Mar 2004 20:13:06 -0000 1.1 --- Table.java 25 Apr 2004 18:55:57 -0000 1.2 *************** *** 25,29 **** import java.util.List; ! import org.radeox.api.engine.RenderEngine; import org.radeox.api.engine.context.RenderContext; import org.radeox.macro.Repository; --- 25,29 ---- import java.util.List; ! import org.hartmath.server.render.HMathRenderEngine; import org.radeox.api.engine.context.RenderContext; import org.radeox.macro.Repository; *************** *** 45,49 **** private List functionOccurences; private RenderContext fContext; ! private RenderEngine fEngine; private Repository functions; --- 45,49 ---- private List functionOccurences; private RenderContext fContext; ! private HMathRenderEngine fEngine; private Repository functions; *************** *** 54,58 **** functions = FunctionRepository.getInstance(); fContext = context; ! fEngine = context.getRenderEngine(); } --- 54,58 ---- functions = FunctionRepository.getInstance(); fContext = context; ! fEngine = (HMathRenderEngine)context.getRenderEngine(); } *************** *** 88,92 **** // jsurfer start - filter the current tables cell ! String temp = fEngine.render(content, fContext); if (temp != null) { currentRow.add(temp); --- 88,92 ---- // jsurfer start - filter the current tables cell ! String temp = fEngine.renderSnippet(content, fContext); if (temp != null) { currentRow.add(temp); |
From: Klaus H. <js...@us...> - 2004-04-25 18:59:39
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25944/WEB-INF/src/org/hartmath/server/macro Modified Files: MathMLMacro.java QuoteMacro.java JViewMacro.java AppletMacro.java STableMacro.java WikipediaMacro.java CodeMacro.java MacroListMacro.java LinkMacro.java ImageMacro.java MMLMacro.java Removed Files: HMathMacroLoader.java HMathMacroRepository.java Log Message: misc changes Index: QuoteMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/QuoteMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** QuoteMacro.java 9 Mar 2004 20:13:05 -0000 1.1 --- QuoteMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 31,34 **** --- 31,35 ---- import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.hartmath.server.filter.ICachableMacro; import org.hartmath.server.filter.INoParserBodyFilterMacro; import org.radeox.macro.LocalePreserved; *************** *** 45,49 **** */ ! public class QuoteMacro extends LocalePreserved implements INoParserBodyFilterMacro { private static Log log = LogFactory.getLog(QuoteMacro.class); --- 46,50 ---- */ ! public class QuoteMacro extends LocalePreserved implements INoParserBodyFilterMacro, ICachableMacro { private static Log log = LogFactory.getLog(QuoteMacro.class); *************** *** 65,69 **** throws IllegalArgumentException, IOException { ! writer.write("<blockquote class=\"quote\">"); writer.write(params.getContent()); String source = "Source"; // i18n --- 66,70 ---- throws IllegalArgumentException, IOException { ! writer.write("<blockquote>"); writer.write(params.getContent()); String source = "Source"; // i18n Index: CodeMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/CodeMacro.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CodeMacro.java 14 Apr 2004 20:06:24 -0000 1.3 --- CodeMacro.java 25 Apr 2004 18:55:54 -0000 1.4 *************** *** 29,32 **** --- 29,33 ---- import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.hartmath.server.filter.ICachableMacro; import org.hartmath.server.filter.INoParserBodyFilterMacro; import org.hartmath.server.macro.code.AbstractCPPBasedCodeFilter; *************** *** 50,54 **** */ ! public class CodeMacro extends LocalePreserved implements INoParserBodyFilterMacro { private static Log log = LogFactory.getLog(CodeMacro.class); --- 51,55 ---- */ ! public class CodeMacro extends LocalePreserved implements INoParserBodyFilterMacro, ICachableMacro { private static Log log = LogFactory.getLog(CodeMacro.class); Index: JViewMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/JViewMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JViewMacro.java 9 Mar 2004 20:13:06 -0000 1.1 --- JViewMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- import java.io.Writer; + import org.hartmath.server.filter.ICachableMacro; import org.radeox.macro.parameter.MacroParameter; import org.snipsnap.app.Application; *************** *** 12,16 **** * @author jsurfer */ ! public class JViewMacro extends HMathMacro { private String[] paramDescription = { }; --- 13,17 ---- * @author jsurfer */ ! public class JViewMacro extends HMathMacro implements ICachableMacro { private String[] paramDescription = { }; Index: MacroListMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/MacroListMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MacroListMacro.java 9 Mar 2004 20:13:06 -0000 1.1 --- MacroListMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 1,25 **** /* * This file is part of "SnipSnap Radeox Rendering Engine". ! * ! * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel ! * All Rights Reserved. ! * * Please visit http://radeox.org/ for updates and contact. ! * ! * --LICENSE NOTICE-- ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! * --LICENSE NOTICE-- */ package org.hartmath.server.macro; --- 1,18 ---- /* * This file is part of "SnipSnap Radeox Rendering Engine". ! * ! * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel All Rights Reserved. ! * * Please visit http://radeox.org/ for updates and contact. ! * ! * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser ! * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any ! * later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free ! * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- */ package org.hartmath.server.macro; *************** *** 31,34 **** --- 24,28 ---- import java.util.List; + import org.hartmath.server.filter.ICachableMacro; import org.hartmath.server.filter.IRenderResultMacro; import org.radeox.macro.BaseLocaleMacro; *************** *** 38,55 **** /* ! * MacroListMacro displays a list of all known macros of the EngineManager ! * with their name, parameters and a description. ! * * @author Matthias L. Jugel * @version $Id$ */ ! public class MacroListMacro extends BaseLocaleMacro implements IRenderResultMacro { public String getLocaleKey() { return "macro.macrolist"; } ! public void execute(Writer writer, MacroParameter params) ! throws IllegalArgumentException, IOException { if (params.getLength() == 0) { appendTo(writer); --- 32,48 ---- /* ! * MacroListMacro displays a list of all known macros of the EngineManager with their name, parameters and a description. ! * * @author Matthias L. Jugel + * * @version $Id$ */ ! public class MacroListMacro extends BaseLocaleMacro implements IRenderResultMacro, ICachableMacro { public String getLocaleKey() { return "macro.macrolist"; } ! public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() == 0) { appendTo(writer); --- HMathMacroLoader.java DELETED --- Index: MMLMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/MMLMacro.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MMLMacro.java 20 Mar 2004 14:35:54 -0000 1.2 --- MMLMacro.java 25 Apr 2004 18:55:54 -0000 1.3 *************** *** 8,12 **** import org.hartmath.core.eval.MathMLUtilities; - import org.hartmath.server.taglib.BrowserTag; import org.hartmath.server.taglib.MathSniffer; import org.radeox.macro.parameter.MacroParameter; --- 8,11 ---- Index: WikipediaMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/WikipediaMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WikipediaMacro.java 9 Mar 2004 20:13:06 -0000 1.1 --- WikipediaMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- import java.io.Writer; + import org.hartmath.server.filter.ICachableMacro; import org.hartmath.server.filter.IRenderResultMacro; import org.radeox.macro.parameter.MacroParameter; *************** *** 32,36 **** */ ! public class WikipediaMacro extends HMathMacro implements IRenderResultMacro { private String fCopiedFrom; private String fWikipediaCopyright; --- 33,37 ---- */ ! public class WikipediaMacro extends HMathMacro implements IRenderResultMacro, ICachableMacro { private String fCopiedFrom; private String fWikipediaCopyright; Index: MathMLMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/MathMLMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MathMLMacro.java 9 Mar 2004 20:13:06 -0000 1.1 --- MathMLMacro.java 25 Apr 2004 18:55:46 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- import java.io.Writer; + import org.hartmath.server.filter.ICachableMacro; import org.radeox.macro.parameter.MacroParameter; *************** *** 11,15 **** * @author jsurfer */ ! public class MathMLMacro extends HMathMacro { private String[] paramDescription = { }; --- 12,16 ---- * @author jsurfer */ ! public class MathMLMacro extends HMathMacro implements ICachableMacro { private String[] paramDescription = { }; Index: AppletMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/AppletMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AppletMacro.java 28 Mar 2004 17:25:07 -0000 1.1 --- AppletMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- import java.io.Writer; + import org.hartmath.server.filter.ICachableMacro; import org.radeox.macro.parameter.MacroParameter; import org.snipsnap.app.Application; *************** *** 12,16 **** * @author jsurfer */ ! public class AppletMacro extends HMathMacro { private String[] paramDescription = { }; --- 13,17 ---- * @author jsurfer */ ! public class AppletMacro extends HMathMacro implements ICachableMacro{ private String[] paramDescription = { }; --- HMathMacroRepository.java DELETED --- Index: STableMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/STableMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** STableMacro.java 2 Apr 2004 18:16:25 -0000 1.1 --- STableMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 42,47 **** * The first line of the table is rendered as column headers. * {table} ! * A|B|C ! * 1|2|3 * {table} * --- 42,48 ---- * The first line of the table is rendered as column headers. * {table} ! * A B C ! * = = = ! * 1 2 3 * {table} * Index: ImageMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/ImageMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ImageMacro.java 2 Apr 2004 18:12:59 -0000 1.1 --- ImageMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 21,25 **** import java.io.Writer; ! import org.hartmath.server.filter.WikipediaFilter; import org.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.RenderEngine; --- 21,26 ---- import java.io.Writer; ! import org.hartmath.server.filter.CachedWikipediaFilter; ! import org.hartmath.server.filter.ICachableMacro; import org.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.RenderEngine; *************** *** 41,45 **** */ ! public class ImageMacro extends SnipMacro { Configuration config; --- 42,46 ---- */ ! public class ImageMacro extends SnipMacro implements ICachableMacro { Configuration config; *************** *** 99,103 **** // Does the name contain an extension? int dotIndex = imageName.lastIndexOf('.'); ! if (dotIndex==(-1) && img != null && WikipediaFilter.createStaticImage(img, buff)) { writer.write(buff.toString()); } else { --- 100,104 ---- // Does the name contain an extension? int dotIndex = imageName.lastIndexOf('.'); ! if (dotIndex==(-1) && img != null && CachedWikipediaFilter.createStaticImage(img, buff)) { writer.write(buff.toString()); } else { Index: LinkMacro.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro/LinkMacro.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LinkMacro.java 20 Mar 2004 10:10:35 -0000 1.1 --- LinkMacro.java 25 Apr 2004 18:55:54 -0000 1.2 *************** *** 28,31 **** --- 28,32 ---- import java.io.Writer; + import org.hartmath.server.filter.ICachableMacro; import org.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.RenderEngine; *************** *** 44,48 **** */ ! public class LinkMacro extends BaseLocaleMacro { public String getLocaleKey() { return "macro.link"; --- 45,49 ---- */ ! public class LinkMacro extends BaseLocaleMacro implements ICachableMacro { public String getLocaleKey() { return "macro.link"; |
From: Klaus H. <js...@us...> - 2004-04-25 18:59:06
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/META-INF/services In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25944/WEB-INF/src/META-INF/services Modified Files: org.radeox.engine.RenderEngine org.radeox.filter.Filter Log Message: misc changes Index: org.radeox.filter.Filter =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/META-INF/services/org.radeox.filter.Filter,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** org.radeox.filter.Filter 14 Apr 2004 20:04:47 -0000 1.2 --- org.radeox.filter.Filter 25 Apr 2004 18:55:55 -0000 1.3 *************** *** 11,15 **** #org.radeox.filter.ItalicFilter #org.hartmath.server.filter.ParserFilter ! org.hartmath.server.filter.WikipediaFilter #org.radeox.filter.UrlFilter #org.radeox.filter.MarkFilter --- 11,15 ---- #org.radeox.filter.ItalicFilter #org.hartmath.server.filter.ParserFilter ! org.hartmath.server.filter.CachedWikipediaFilter #org.radeox.filter.UrlFilter #org.radeox.filter.MarkFilter Index: org.radeox.engine.RenderEngine =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/META-INF/services/org.radeox.engine.RenderEngine,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** org.radeox.engine.RenderEngine 9 Mar 2004 20:13:08 -0000 1.1 --- org.radeox.engine.RenderEngine 25 Apr 2004 18:55:55 -0000 1.2 *************** *** 1 **** ! org.snipsnap.render.SnipRenderEngine --- 1 ---- ! org.hartmath.server.render.HMathRenderEngine |
From: Klaus H. <js...@us...> - 2004-04-25 18:59:01
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25944/WEB-INF/src/org/hartmath/server/render Added Files: HMathRenderEngine.java BaseRenderEngine.java Log Message: misc changes --- NEW FILE: HMathRenderEngine.java --- /* * This file is part of "SnipSnap Wiki/Weblog". * * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel All Rights Reserved. * * Please visit http://snipsnap.org/ for updates and contact. * * --LICENSE NOTICE-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. --LICENSE NOTICE-- */ package org.hartmath.server.render; import java.io.IOException; import java.io.Writer; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.hartmath.server.cache.CachedPageCompiler; import org.hartmath.server.cache.CachedPage; import org.hartmath.server.filter.CachedWikipediaFilter; import org.hartmath.server.render.filter.context.HMathFilterContext; import org.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.IncludeRenderEngine; import org.radeox.api.engine.WikiRenderEngine; import org.radeox.api.engine.context.RenderContext; import org.radeox.engine.context.BaseInitialRenderContext; import org.radeox.filter.context.FilterContext; import org.radeox.macro.MacroRepository; import org.radeox.util.Encoder; import org.snipsnap.app.Application; import org.snipsnap.config.Configuration; import org.snipsnap.render.context.SnipRenderContext; import org.snipsnap.render.macro.parameter.SnipMacroParameter; import org.snipsnap.serialization.StringBufferWriter; import org.snipsnap.snip.Snip; import org.snipsnap.snip.SnipLink; import org.snipsnap.snip.SnipSpaceFactory; import org.snipsnap.user.AuthenticationService; /** * renderEngine implementation for SnipSnap which understoods e.g. howto include other snips. * * @author Stephan J. Schmidt * @version $Id: HMathRenderEngine.java,v 1.1 2004/04/25 18:55:56 jsurfer Exp $ */ public class HMathRenderEngine extends BaseRenderEngine implements WikiRenderEngine, IncludeRenderEngine, ImageRenderEngine { // private SnipSpace space; private AuthenticationService authService; public HMathRenderEngine(AuthenticationService authService) { this.authService = authService; //MacroRepository.getInstance().addLoader(new GroovyMacroLoader()); // DOES NOT WORK BECAUSE OF ASPECTS // this.space = space; } public String getName() { return "snipsnap"; } public boolean exists(String name) { return SnipSpaceFactory.getInstance().exists(name); } public boolean showCreate() { return authService.isAuthenticated(Application.get().getUser()); } public void appendLink(StringBuffer buffer, String name, String view, String anchor) { SnipLink.appendLink(buffer, name, view, anchor); } public void appendLink(StringBuffer buffer, String name, String view) { SnipLink.appendLink(buffer, name, view); } public void appendCreateLink(StringBuffer buffer, String name, String view) { Configuration config = Application.get().getConfiguration(); String encodedSpace = config.getEncodedSpace(); if (name.indexOf(encodedSpace.charAt(0)) == -1) { SnipLink.appendCreateLink(buffer, name); } else { buffer.append("[<span class=\"error\">illegal '" + encodedSpace + "' in " + Encoder.escape(name) + "</span>]"); } } public String include(String name) { Snip includeSnip = SnipSpaceFactory.getInstance().load(name); if (null != includeSnip) { return includeSnip.getContent(); } else { return null; } } private String externalImageLink = null; public String getExternalImageLink() { if (null == externalImageLink) { Writer writer = new StringBufferWriter(); try { SnipLink.appendImage(writer, "Icon-Extlink", ">>"); } catch (IOException e) { // ignore } externalImageLink = writer.toString(); } return externalImageLink; } public String render(String content, RenderContext context) { init(); FilterContext filterContext = new HMathFilterContext(((SnipRenderContext) context).getSnip()); filterContext.setRenderContext(context); context.setRenderEngine(this); Map map = Application.get().getParameters(); HttpServletRequest request = (HttpServletRequest) map.get("request"); if (request.getAttribute("previewMode") != null) { CachedWikipediaFilter f = new CachedWikipediaFilter(); // f.setInitialContext(new BaseInitialRenderContext()); MacroRepository macros = MacroRepository.getInstance(); macros.setInitialContext(new BaseInitialRenderContext()); return f.filter(content, filterContext, macros, CachedWikipediaFilter.DUMMY_CACHED_PAGE, 1); } CachedWikipediaFilter f = new CachedWikipediaFilter(); MacroRepository macros = MacroRepository.getInstance(); macros.setInitialContext(new BaseInitialRenderContext()); SnipMacroParameter params = (SnipMacroParameter) filterContext.getMacroParameter(); Snip snip = params.getSnipRenderContext().getSnip(); String name = snip.getName(); String parent = snip.getParentName(); if (parent != null) { name = parent + name; } name = ((String) Application.get().getObject(Application.OID)) + name; String versionName = name+ snip.getVersion(); CachedPage cachedPage = (CachedPage) CachedPageCompiler.PAGE_MAP.get(versionName); if (cachedPage == null) { versionName = name+ (snip.getVersion()-1); cachedPage = (CachedPage) CachedPageCompiler.PAGE_MAP.get(versionName); if (cachedPage != null) { // delete previous version // System.out.println("remove:"+versionName); synchronized (CachedPageCompiler.PAGE_MAP){ CachedPageCompiler.PAGE_MAP.remove(versionName); } } } else { try { // System.out.println("found:"+versionName); return ((CachedPage)cachedPage.clone()).filter(filterContext, macros); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // create a new class: CachedPageCompiler compiler = new CachedPageCompiler("P" + Long.toString(CachedPageCompiler.CLASS_COUNTER)); String result = f.filter(content, filterContext, macros, compiler, 0); cachedPage = compiler.getCachedPage(); if (cachedPage != null && name != null) { versionName = name+ snip.getVersion(); // System.out.println("put:"+versionName); synchronized (CachedPageCompiler.PAGE_MAP){ CachedPageCompiler.PAGE_MAP.put(versionName, cachedPage); } return cachedPage.filter(filterContext, macros); } return result; } public String renderSnippet(String content, RenderContext context) { init(); FilterContext filterContext = new HMathFilterContext(((SnipRenderContext) context).getSnip()); filterContext.setRenderContext(context); context.setRenderEngine(this); CachedWikipediaFilter f = new CachedWikipediaFilter(); // f.setInitialContext(new BaseInitialRenderContext()); MacroRepository macros = MacroRepository.getInstance(); macros.setInitialContext(new BaseInitialRenderContext()); return f.filter(content, filterContext, macros, CachedWikipediaFilter.DUMMY_CACHED_PAGE, 1); } } --- NEW FILE: BaseRenderEngine.java --- /* * This file is part of "SnipSnap Radeox Rendering Engine". * * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel * All Rights Reserved. * * Please visit http://radeox.org/ for updates and contact. * * --LICENSE NOTICE-- * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * --LICENSE NOTICE-- */ package org.hartmath.server.render; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.radeox.EngineManager; import org.radeox.api.engine.RenderEngine; import org.radeox.engine.context.BaseInitialRenderContext; import org.radeox.api.engine.context.InitialRenderContext; import org.radeox.api.engine.context.RenderContext; import org.radeox.filter.Filter; import org.radeox.filter.FilterPipe; import org.radeox.filter.context.BaseFilterContext; import org.radeox.filter.context.FilterContext; import org.radeox.util.Service; import java.io.*; import java.util.Iterator; /** * Base implementation of RenderEngine * * @author Stephan J. Schmidt * @version $Id: BaseRenderEngine.java,v 1.1 2004/04/25 18:55:57 jsurfer Exp $ */ public abstract class BaseRenderEngine implements RenderEngine { private static Log log = LogFactory.getLog(BaseRenderEngine.class); protected InitialRenderContext initialContext; public BaseRenderEngine(InitialRenderContext context) { this.initialContext = context; } public BaseRenderEngine() { this(new BaseInitialRenderContext()); } protected void init() { } /** * Name of the RenderEngine. This is used to get a RenderEngine instance * with EngineManager.getInstance(name); * * @return name Name of the engine */ public String getName() { return EngineManager.DEFAULT; } /** * Render an input with text markup from a Reader and write the result to a writer * * @param in Reader to read the input from * @param context Special context for the render engine, e.g. with * configuration information */ public String render(Reader in, RenderContext context) throws IOException { StringBuffer buffer = new StringBuffer(); BufferedReader inputReader = new BufferedReader(in); String line; while ((line = inputReader.readLine()) != null) { buffer.append(line); } return render(buffer.toString(), context); } public void render(Writer out, String content, RenderContext context) throws IOException { out.write(render(content, context)); } } |
From: Klaus H. <js...@us...> - 2004-04-25 18:58:37
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25858/WEB-INF/src/org/hartmath/server/render Log Message: Directory /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render added to the repository |
From: Klaus H. <js...@us...> - 2004-04-25 18:58:22
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/filter/context In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25858/WEB-INF/src/org/hartmath/server/render/filter/context Log Message: Directory /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/render/filter/context added to the repository |
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24472/WEB-INF/src/org/hartmath/server/filter Modified Files: WikipediaFilter.java Added Files: CachedWikipediaParser.java CachedWikipediaFilter.java ICachableMacro.java Removed Files: MacroHMathFilter.java Log Message: misc changes --- NEW FILE: ICachableMacro.java --- /* * Created on 27.01.2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package org.hartmath.server.filter; /** * this interface indicates that a macro has a body content */ public interface ICachableMacro { } Index: WikipediaFilter.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/WikipediaFilter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** WikipediaFilter.java 14 Apr 2004 20:06:24 -0000 1.7 --- WikipediaFilter.java 25 Apr 2004 18:50:05 -0000 1.8 *************** *** 55,59 **** import org.snipsnap.snip.Snip; import org.snipsnap.snip.SnipLink; - /** * Parse the input and transform it for the most used wiki patterns --- 55,58 ---- *************** *** 77,80 **** --- 76,81 ---- private RenderEngine fWikiEngine; private Snip fSnip; + private boolean fASMStart = false; + private int fASMStartPosition = 0; public static final String INVALID_CHAR_IN_PLUGIN_IDENTIFIER = "Invalid_Char_In_Plugin_Identifier"; *************** *** 159,162 **** --- 160,167 ---- private void copyWhite(boolean whiteStart, final int whiteStartPosition, final int diff) { if (whiteStart) { + if (!fASMStart) { + fASMStart = true; + fASMStartPosition = fResult.length(); + } final int len = fCurrentPosition - diff; int currentIndex = whiteStartPosition; *************** *** 216,220 **** case '<' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); lastIndex = currentIndex; } --- 221,225 ---- case '<' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } *************** *** 223,227 **** case '>' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); lastIndex = currentIndex; } --- 228,232 ---- case '>' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } *************** *** 230,234 **** case '&' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); lastIndex = currentIndex; } --- 235,239 ---- case '&' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } *************** *** 237,241 **** case '\'' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); lastIndex = currentIndex; } --- 242,246 ---- case '\'' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } *************** *** 244,248 **** case '\"' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); lastIndex = currentIndex; } --- 249,253 ---- case '\"' : // special html escape character if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } *************** *** 262,268 **** while (currentIndex < len) { switch (text.charAt(currentIndex++)) { ! case '\n' : if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex-1)); lastIndex = currentIndex; } --- 267,273 ---- while (currentIndex < len) { switch (text.charAt(currentIndex++)) { ! case '\n' : if (lastIndex < (currentIndex - 1)) { ! fResult.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } *************** *** 271,307 **** 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; } } --- 276,312 ---- 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; } } *************** *** 616,654 **** macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1); if (macroStartTag != null) { ! String command = ""; ! String endTag; ! ! String parameterString = null; ! String macroBodyString = ""; ! int index0; ! int index1; ! if ((index0 = macroStartTag.indexOf(':')) >= 0) { ! command = macroStartTag.substring(0, index0); ! parameterString = macroStartTag.substring(index0 + 1, macroStartTag.length()); ! } else { ! command = macroStartTag; ! } ! Macro macro = (Macro) getMacroRepository().get(command); ! ! String completeMacroSubString; ! ! if ((macro != null) && (macro instanceof IBodyTagSupportMacro)) { ! endTag = '{' + command + '}'; ! index0 = fStringSource.indexOf(endTag, fCurrentPosition); ! ! if (index0 >= 0) { ! macroBodyString = fStringSource.substring(fCurrentPosition, index0); ! completeMacroSubString = ! new String(fSource, startMacroPosition - 1, index0 + endTag.length() - startMacroPosition + 1); ! fCurrentPosition = startMacroPosition + completeMacroSubString.length() - 1; ! } else { ! completeMacroSubString = new String(fSource, startMacroPosition - 1, macroStartTag.length() + 2); ! } ! } else { ! completeMacroSubString = new String(fSource, startMacroPosition - 1, macroStartTag.length() + 2); ! } ! ! handleMacro(completeMacroSubString, command, parameterString, macroBodyString); ! continue; } --- 621,625 ---- macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1); if (macroStartTag != null) { ! createMacro(startMacroPosition, macroStartTag); continue; } *************** *** 1042,1046 **** fCurrentPosition += 7; if (readUntilString("</nowiki>")) { ! String nowikiContent = new String(fSource, htmlStartPosition + 7, fCurrentPosition - htmlStartPosition - 16); if (nowikiContent != null) { copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); --- 1013,1018 ---- fCurrentPosition += 7; if (readUntilString("</nowiki>")) { ! String nowikiContent = ! new String(fSource, htmlStartPosition + 7, fCurrentPosition - htmlStartPosition - 16); if (nowikiContent != null) { copyWhite(fWhiteStart, fWhiteStartPosition, fCurrentPosition - htmlStartPosition + 1); *************** *** 1095,1098 **** --- 1067,1074 ---- fWhiteStartPosition = fCurrentPosition - 1; } + if (!fASMStart) { + fASMStart = true; + fASMStartPosition = fResult.length(); + } startOfIndent = false; } *************** *** 1105,1108 **** --- 1081,1122 ---- } + private void createMacro(int startMacroPosition, String macroStartTag) { + String command = ""; + String endTag; + + String parameterString = null; + String macroBodyString = ""; + int index0; + int index1; + if ((index0 = macroStartTag.indexOf(':')) >= 0) { + command = macroStartTag.substring(0, index0); + parameterString = macroStartTag.substring(index0 + 1, macroStartTag.length()); + } else { + command = macroStartTag; + } + Macro macro = (Macro) getMacroRepository().get(command); + + String completeMacroSubString; + + if ((macro != null) && (macro instanceof IBodyTagSupportMacro)) { + endTag = '{' + command + '}'; + index0 = fStringSource.indexOf(endTag, fCurrentPosition); + + if (index0 >= 0) { + macroBodyString = fStringSource.substring(fCurrentPosition, index0); + completeMacroSubString = new String(fSource, startMacroPosition - 1, index0 + endTag.length() - startMacroPosition + 1); + fCurrentPosition = startMacroPosition + completeMacroSubString.length() - 1; + } else { + completeMacroSubString = new String(fSource, startMacroPosition - 1, macroStartTag.length() + 2); + } + } else { + completeMacroSubString = new String(fSource, startMacroPosition - 1, macroStartTag.length() + 2); + } + + copyWhite(fWhiteStart, fWhiteStartPosition, 1); + + handleMacro(completeMacroSubString, command, parameterString, macroBodyString); + } + private void createExternalLink(String urlString) { *************** *** 1299,1306 **** 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>"); --- 1313,1320 ---- 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>"); *************** *** 2117,2120 **** --- 2131,2135 ---- } + public String filter(String input, FilterContext context, int recursionLevel) { try { *************** *** 2122,2125 **** --- 2137,2141 ---- return "<span class=\"error\">Error - recursion limit exceeded.</span>"; } + StringBuffer result = new StringBuffer(input.length() + input.length() / 10); // instantiate inner Parser class *************** *** 2130,2138 **** } catch (Exception e) { //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); ! log.warn("Error for: " + this); err.printStackTrace(); } --- 2146,2154 ---- } catch (Exception e) { //log.warn("<span class=\"error\">Exception</span>: " + this + ": " + e); ! log.warn("Exception for: " + " " + e); e.printStackTrace(); } catch (Error err) { //log.warn("<span class=\"error\">Error</span>: " + this + ": " + err); ! log.warn("Error for: " ); err.printStackTrace(); } --- NEW FILE: CachedWikipediaFilter.java --- /* * This file is part of the "HMath MathML BLOG/Wiki Engine". * * Copyright (c) 2004 Klaus Hartlage All Rights Reserved. * * Please visit http://www.hmath.org/ for updates and contact. * * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any * later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE-- */ package org.hartmath.server.filter; import java.io.IOException; import java.io.Writer; import java.text.MessageFormat; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hartmath.server.cache.DummyCachedPage; import org.hartmath.server.cache.ICachedPage; import org.hartmath.server.taglib.MathSniffer; import org.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.IncludeRenderEngine; import org.radeox.api.engine.RenderEngine; import org.radeox.api.engine.WikiRenderEngine; import org.radeox.filter.CacheFilter; import org.radeox.filter.FilterSupport; import org.radeox.filter.context.FilterContext; import org.radeox.filter.interwiki.InterWiki; import org.radeox.macro.Macro; import org.radeox.macro.MacroRepository; import org.radeox.macro.parameter.MacroParameter; import org.radeox.util.Encoder; import org.radeox.util.StringBufferWriter; import org.snipsnap.app.Application; /** * Parse the input and transform it for the most used wiki patterns */ public class CachedWikipediaFilter extends FilterSupport implements CacheFilter, IWikipediaFilterConstants { public static final DummyCachedPage DUMMY_CACHED_PAGE = new DummyCachedPage(); public class InvalidInputException extends Exception { public InvalidInputException() { super(); } public InvalidInputException(String s) { super(s); } } public static class Token { private int fToken; public Token(int token) { fToken = token; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { return (obj instanceof Token) && fToken == ((Token) obj).fToken; } /** * @return */ public int getToken() { return fToken; } public String getTagName() { return ""; } } public static class ListToken extends Token { int fLevel; public ListToken(int token, int level) { super(token); fLevel = level; } public int getLevel() { return fLevel; } } public static class OpenTagToken extends Token { private String fTagName; private String fOpenTag; public OpenTagToken(int token, String name, String openTag) { super(token); fTagName = name; fOpenTag = openTag; } public String getTagName() { return fTagName; } public String getOpenTag() { return fOpenTag; } public void setTagName(String name) { fTagName = name; } public void setOpenTag(String openTag) { fOpenTag = openTag; } } public static class SpecialTagToken extends OpenTagToken { public SpecialTagToken(int token, String name, String openTag) { super(token, name, openTag); } } public static class CloseTagToken extends Token { private String fTagName; private String fCloseTag; public CloseTagToken(int token, String name, String closeTag) { super(token); fTagName = name; fCloseTag = closeTag; } public String getTagName() { return fTagName; } public String getCloseTag() { return fCloseTag; } public void setTagName(String name) { fTagName = name; } public void setCloseTag(String closeTag) { fCloseTag = closeTag; } } final static String HEADER_STRINGS[] = { "=", "==", "===", "====", "=====", "======" }; final static int TokenNotFound = -2; final static int TokenIgnore = -1; final static int TokenSTART = 0; final static int TokenEOF = 1; final static int TokenERROR = 2; final static int TokenBOLD = 3; final static int TokenITALIC = 4; final static int TokenSTRIKETHROUGH = 5; final static int TokenSTRONG = 8; final static int TokenEM = 9; final static int TokenCOMMA = 134; final static int TokenDOLLAR_LBRACE = 127; final static int TokenLIST_UL_START = 50; final static int TokenLIST_OL_START = 51; final static int TokenLIST_UL_END = 75; final static int TokenLIST_OL_END = 76; final static int TokenHTML_BR_OPEN = 190; final static int TokenHTML_HR_OPEN = 191; final static int TokenHTML_BOLD_OPEN = 200; final static int TokenHTML_BOLD_CLOSE = 201; final static int TokenHTML_ITALIC_OPEN = 202; final static int TokenHTML_ITALIC_CLOSE = 203; final static int TokenHTML_UNDERLINE_OPEN = 204; final static int TokenHTML_UNDERLINE_CLOSE = 205; final static int TokenHTML_STRIKE_OPEN = 206; final static int TokenHTML_STRIKE_CLOSE = 207; final static int TokenHTML_PARAGRAPH_OPEN = 208; final static int TokenHTML_PARAGRAPH_CLOSE = 209; final static int TokenHTML_PRE_OPEN = 210; final static int TokenHTML_PRE_CLOSE = 211; final static int TokenHTML_BLOCKQUOTE_OPEN = 212; final static int TokenHTML_BLOCKQUOTE_CLOSE = 213; final static int TokenHTML_SUB_OPEN = 216; final static int TokenHTML_SUB_CLOSE = 217; final static int TokenHTML_SUP_OPEN = 218; final static int TokenHTML_SUP_CLOSE = 219; final static int TokenHTML_H1_CLOSE = 221; final static int TokenHTML_H1_OPEN = 220; final static int TokenHTML_H2_CLOSE = 223; final static int TokenHTML_H2_OPEN = 222; final static int TokenHTML_H3_CLOSE = 225; final static int TokenHTML_H3_OPEN = 224; final static int TokenHTML_H4_CLOSE = 227; final static int TokenHTML_H4_OPEN = 226; final static int TokenHTML_H5_CLOSE = 229; final static int TokenHTML_H5_OPEN = 228; final static int TokenHTML_H6_CLOSE = 231; final static int TokenHTML_H6_OPEN = 230; final static int TokenHTML_EM_OPEN = 240; final static int TokenHTML_EM_CLOSE = 241; final static int TokenHTML_STRONG_CLOSE = 243; final static int TokenHTML_STRONG_OPEN = 242; final static int TokenHTML_VAR_OPEN = 245; final static int TokenHTML_VAR_CLOSE = 246; final static int TokenHTML_CODE_OPEN = 247; final static int TokenHTML_CODE_CLOSE = 248; final static int TokenHTML_MATH_OPEN = 400; final static int TokenHTML_MATH_CLOSE = 401; final static int TokenIdentifier = 138; final static int TokenLBRACKET = 132; final static int TokenLPAREN = 128; final static int TokenPLUGIN_IDENTIFIER = 130; final static int TokenRBRACE = 131; final static int TokenRBRACKET = 133; final static int TokenRPAREN = 129; final static Token BOLD = new Token(TokenBOLD); final static Token ITALIC = new Token(TokenITALIC); final static Token STRONG = new Token(TokenSTRONG); final static Token EM = new Token(TokenEM); 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>"); final static Token HTML_MATH_CLOSE = new CloseTagToken(TokenHTML_MATH_OPEN, "math", "</math>"); final static Token LIST_OL_START = new Token(TokenLIST_OL_START); final static Token LIST_UL_START = new Token(TokenLIST_UL_START); final static Token HTML_VAR_CLOSE = new CloseTagToken(TokenHTML_VAR_CLOSE, "var", "</var>"); final static Token HTML_VAR_OPEN = new OpenTagToken(TokenHTML_VAR_OPEN, "var", "<var>"); final static Token HTML_CODE_CLOSE = new CloseTagToken(TokenHTML_CODE_CLOSE, "code", "</code>"); final static Token HTML_CODE_OPEN = new OpenTagToken(TokenHTML_CODE_OPEN, "code", "<code>"); final static HashMap OPEN_TAGS = new HashMap(); final static HashMap CLOSE_TAGS = new HashMap(); final static HashSet ENTITY_SET = new HashSet(); final static HashMap IMAGE_MAP = new HashMap(); private static Log log = LogFactory.getLog(CachedWikipediaFilter.class); { for (int i = 0; i < ENTITY_STRINGS.length; i++) { ENTITY_SET.add(ENTITY_STRINGS[i]); } for (int i = 0; i < IMAGE_STRINGS.length; i += 2) { IMAGE_MAP.put(IMAGE_STRINGS[i], IMAGE_STRINGS[i + 1]); } OPEN_TAGS.put("br", HTML_BR_OPEN); OPEN_TAGS.put("hr", HTML_HR_OPEN); OPEN_TAGS.put("h1", HTML_H1_OPEN); OPEN_TAGS.put("h2", HTML_H2_OPEN); OPEN_TAGS.put("h3", HTML_H3_OPEN); OPEN_TAGS.put("h4", HTML_H4_OPEN); OPEN_TAGS.put("h5", HTML_H5_OPEN); OPEN_TAGS.put("h6", HTML_H6_OPEN); CLOSE_TAGS.put("h1", HTML_H1_CLOSE); CLOSE_TAGS.put("h2", HTML_H2_CLOSE); CLOSE_TAGS.put("h3", HTML_H1_CLOSE); CLOSE_TAGS.put("h4", HTML_H2_CLOSE); CLOSE_TAGS.put("h5", HTML_H1_CLOSE); CLOSE_TAGS.put("h6", HTML_H2_CLOSE); OPEN_TAGS.put("em", HTML_EM_OPEN); CLOSE_TAGS.put("em", HTML_EM_CLOSE); OPEN_TAGS.put("i", HTML_ITALIC_OPEN); CLOSE_TAGS.put("i", HTML_ITALIC_CLOSE); OPEN_TAGS.put("b", HTML_BOLD_OPEN); CLOSE_TAGS.put("b", HTML_BOLD_CLOSE); OPEN_TAGS.put("strong", HTML_STRONG_OPEN); CLOSE_TAGS.put("strong", HTML_STRONG_CLOSE); OPEN_TAGS.put("u", HTML_UNDERLINE_OPEN); CLOSE_TAGS.put("u", HTML_UNDERLINE_CLOSE); OPEN_TAGS.put("p", HTML_PARAGRAPH_OPEN); CLOSE_TAGS.put("p", HTML_PARAGRAPH_CLOSE); OPEN_TAGS.put("pre", HTML_PRE_OPEN); CLOSE_TAGS.put("pre", HTML_PRE_CLOSE); OPEN_TAGS.put("blockquote", HTML_BLOCKQUOTE_OPEN); CLOSE_TAGS.put("blockquote", HTML_BLOCKQUOTE_CLOSE); OPEN_TAGS.put("var", HTML_PRE_OPEN); CLOSE_TAGS.put("var", HTML_PRE_CLOSE); OPEN_TAGS.put("code", HTML_CODE_OPEN); CLOSE_TAGS.put("code", HTML_CODE_CLOSE); OPEN_TAGS.put("sub", HTML_SUB_OPEN); CLOSE_TAGS.put("sub", HTML_SUB_CLOSE); OPEN_TAGS.put("sup", HTML_SUP_OPEN); CLOSE_TAGS.put("sup", HTML_SUP_CLOSE); OPEN_TAGS.put("strike", HTML_STRIKE_OPEN); CLOSE_TAGS.put("strike", HTML_STRIKE_CLOSE); OPEN_TAGS.put("math", HTML_MATH_OPEN); CLOSE_TAGS.put("math", HTML_MATH_CLOSE); } /** * Limits the recursive call of this filter to a depth of RECURSION_LIMIT */ final static int RECURSION_LIMIT = 5; final static Token START = new Token(TokenSTART); final static Token STRIKETHROUGH = new Token(TokenSTRIKETHROUGH); /** * Determines if the specified character may be part of a url */ public final static boolean isUrlIdentifierPart(char ch) { if (Character.isLetterOrDigit(ch)) { return true; } final String test = "-_.!~*';/?:@#&=+$,"; return test.indexOf(ch) != (-1); } /** * Determines if the specified character may be part of a wiki plugin identifier as other than the first character */ public final static boolean isWikiPluginIdentifierPart(char ch) { return Character.isLetterOrDigit(ch) || (ch == '_'); } /** * Determines if the specified character may be part the first character of a wiki plugin identifier */ public final static boolean isWikiPluginIdentifierStart(char ch) { return Character.isLetter(ch); } public static boolean createStaticImage(String imageTag, StringBuffer buff) { String value = (String) IMAGE_MAP.get(imageTag); if (value != null) { buff.append(MessageFormat.format(value, ARGUMENTS)); return true; } return false; } // private MacroRepository macros; public CachedWikipediaFilter() { super(); } public String filter(String input, FilterContext context) { return filter(input, context, null, DUMMY_CACHED_PAGE, 0); } public String filter(String input, FilterContext context, MacroRepository macros, ICachedPage compiler, int recursionLevel) { try { if (++recursionLevel > RECURSION_LIMIT) { String error = "<span class=\"error\">Error - recursion limit exceeded.</span>"; compiler.compileHTML(error); return error; } StringBuffer result = new StringBuffer(input.length() + input.length() / 10); // instantiate inner Parser class CachedWikipediaParser parser = new CachedWikipediaParser(macros, input, result, compiler, context, recursionLevel); parser.parse(); return result.toString(); // Util.substitute(matcher, p, new Perl5Substitution(s, interps), result, limit); } catch (Exception e) { //log.warn("<span class=\"error\">Exception</span>: " + this + ": " + e); log.warn("Exception for: " + " " + e); e.printStackTrace(); } catch (Error err) { //log.warn("<span class=\"error\">Error</span>: " + this + ": " + err); log.warn("Error for: "); err.printStackTrace(); } String error = "<span class=\"error\">Error in Parser.</span>"; compiler.compileHTML(error); return error; } public static String filterParser( String input, FilterContext context, ICachedPage compiler, MacroRepository macros, int recursionLevel) { try { if (++recursionLevel > RECURSION_LIMIT) { return "<span class=\"error\">Error - recursion limit exceeded.</span>"; } StringBuffer result = new StringBuffer(input.length() + input.length() / 10); // instantiate inner Parser class CachedWikipediaParser parser = new CachedWikipediaParser(macros, input, result, compiler, context, recursionLevel); parser.parse(); return result.toString(); // Util.substitute(matcher, p, new Perl5Substitution(s, interps), result, limit); } catch (Exception e) { //log.warn("<span class=\"error\">Exception</span>: " + this + ": " + e); log.warn("Exception for: " + " " + e); e.printStackTrace(); } catch (Error err) { //log.warn("<span class=\"error\">Error</span>: " + this + ": " + err); log.warn("Error for: "); err.printStackTrace(); } return "<span class=\"error\">Error in Parser.</span>"; } // 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() { // return macros; // } // public void setInitialContext(InitialRenderContext context) { // macros = MacroRepository.getInstance(); // macros.setInitialContext(context); // } public static void copyWhite(StringBuffer result, 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)) { result.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } else { lastIndex++; } result.append("<"); break; case '>' : // special html escape character if (lastIndex < (currentIndex - 1)) { result.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } else { lastIndex++; } result.append(">"); break; case '&' : // special html escape character if (lastIndex < (currentIndex - 1)) { result.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } else { lastIndex++; } result.append("&"); break; case '\'' : // special html escape character if (lastIndex < (currentIndex - 1)) { result.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } else { lastIndex++; } result.append("'"); break; case '\"' : // special html escape character if (lastIndex < (currentIndex - 1)) { result.append(text.substring(lastIndex, currentIndex - 1)); lastIndex = currentIndex; } else { lastIndex++; } result.append("""); break; } } if (lastIndex < (currentIndex)) { result.append(text.substring(lastIndex, currentIndex)); } } public static void createMacro(StringBuffer result, String macroCommand, FilterContext context, MacroRepository macros) { String command = ""; String endTag; String parameterString = null; String macroBodyString = ""; int index0 = 0; int index1 = macroCommand.indexOf('}'); if ((index0 = macroCommand.indexOf(':')) >= 0 && (index0 < index1)) { command = macroCommand.substring(1, index0); parameterString = macroCommand.substring(index0 + 1, index1); } else { command = macroCommand.substring(1, index1); } Macro macro = (Macro) macros.get(command); String completeMacroSubString; if ((macro != null) && (macro instanceof IBodyTagSupportMacro)) { endTag = '{' + command + '}'; index0 = macroCommand.indexOf(endTag, command.length()); if (index0 >= 0) { macroBodyString = macroCommand.substring(index1 + 1, index0); } } completeMacroSubString = macroCommand; handleMacro(result, completeMacroSubString, command, parameterString, macroBodyString, context, macros); } private static void handleMacro( StringBuffer result, String completeMacroSubString, String command, String unsplittedMacroParameters, String group3, FilterContext context, MacroRepository macros) { if (command != null) { // {$peng} are variables not macros. if (!command.startsWith("$")) { MacroParameter mParams = context.getMacroParameter(); if (group3 != null) { mParams.setContent(group3); mParams.setContentStart(0); mParams.setContentEnd(group3.length()); } if (unsplittedMacroParameters != null && unsplittedMacroParameters.length() > 1) { // mParams.setParams(parseParameters(unsplittedMacroParameters)); mParams.setParams(unsplittedMacroParameters); } mParams.setStart(0); mParams.setEnd(completeMacroSubString.length()); // @DANGER: recursive calls may replace macros in included source code try { if (macros.containsKey(command)) { Macro macro = (Macro) macros.get(command); // recursively filter macros within macros if (null != mParams.getContent() && !(macro instanceof INoParserBodyFilterMacro)) { mParams.setContent(filterParser(mParams.getContent(), context, DUMMY_CACHED_PAGE, macros, 0)); } StringBufferWriter writer = new StringBufferWriter(new StringBuffer(256)); macro.execute(writer, mParams); StringBuffer buffer = writer.getBuffer(); if (macro instanceof IRenderResultMacro) { result.append(filterParser(buffer.toString(), context, DUMMY_CACHED_PAGE, macros, 0)); } else { result.append(buffer); } } else if (command.startsWith("!")) { RenderEngine engine = context.getRenderContext().getRenderEngine(); if (engine instanceof IncludeRenderEngine) { String include = ((IncludeRenderEngine) engine).include(command.substring(1)); if (null != include) { // Filter paramFilter = new ParamFilter(mParams); // included = paramFilter.filter(included, null); // fResult.append(include); result.append(filterParser(include, context, DUMMY_CACHED_PAGE, macros, 0)); } else { result.append(command.substring(1) + " not found."); } } return; } else { // fResult.append(group0); copyWhite(result, completeMacroSubString); return; } } catch (IllegalArgumentException e) { result.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>"); e.printStackTrace(); } catch (Throwable e) { log.warn("MacroFilter: unable to format macro: " + command, e); result.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>"); e.printStackTrace(); return; } } else { result.append("<"); result.append(command.substring(1)); result.append(">"); } } else { // fResult.append(group0); copyWhite(result, completeMacroSubString); } } public static void createExternalLink(StringBuffer result, RenderEngine wikiEngine, String urlString) { // Does our engine know images? if (wikiEngine instanceof ImageRenderEngine) { result.append(((ImageRenderEngine) wikiEngine).getExternalImageLink()); } result.append("<span class=\"nobr\">"); result.append("<a href=\""); result.append(Encoder.escape(urlString)); result.append("\">"); result.append(Encoder.toEntity(urlString.charAt(0)) + urlString.substring(1)); result.append("</a></span>"); } public static void handleSnipLink(StringBuffer result, RenderEngine wikiEngine, String name) { if (name != null) { int index = name.indexOf("http://"); // User probably wrote [http://radeox.org] instead of http://radeox.org if (index != -1) { createExternalLink(result, wikiEngine, name.substring(index)); // show error // fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>"); } else { // trim the name and unescape it name = Encoder.unescape(name.trim()); // Is there an alias like [alias|link] ? int pipeIndex = name.indexOf('|'); String alias = ""; if (-1 != pipeIndex) { alias = name.substring(0, pipeIndex); name = name.substring(pipeIndex + 1); } int hashIndex = name.lastIndexOf('#'); String hash = ""; if (-1 != hashIndex && hashIndex != name.length() - 1) { hash = name.substring(hashIndex + 1); name = name.substring(0, hashIndex); } int colonIndex = name.indexOf(':'); // typed link ? if (-1 != colonIndex) { // for now throw away the type information name = name.substring(colonIndex + 1); } int atIndex = name.lastIndexOf('@'); // InterWiki link ? if (-1 != atIndex) { String extSpace = name.substring(atIndex + 1); // known extarnal space ? InterWiki interWiki = InterWiki.getInstance(); if (interWiki.contains(extSpace)) { name = name.substring(0, atIndex); Writer writer = new StringBufferWriter(result); try { if (-1 != hashIndex) { interWiki.expand(writer, extSpace, name, hash); } else { interWiki.expand(writer, extSpace, name, ""); } } catch (IOException e) { log.debug("InterWiki " + extSpace + " not found."); } } else { result.append("[<span class=\"error\">"); result.append(name); result.append("?</span>]"); } } else { // internal link if (wikiEngine != null && wikiEngine instanceof WikiRenderEngine) { if (((WikiRenderEngine) wikiEngine).exists(name)) { String view = name; if (-1 != pipeIndex) { view = alias; } // Do not add hash if an alias was given if (-1 != hashIndex) { ((WikiRenderEngine) wikiEngine).appendLink(result, name, view, hash); } else { ((WikiRenderEngine) wikiEngine).appendLink(result, name, view); } } else if (((WikiRenderEngine) wikiEngine).showCreate()) { ((WikiRenderEngine) wikiEngine).appendCreateLink(result, name, name); // links with "create" are not cacheable because // a missing wiki could be created // TODO is this ok? // fContext.getRenderContext().setCacheable(false); } else { // cannot display/create wiki, so just display the text result.append(name); } } else { // cannot display/create wiki, so just display the text result.append(name); } } } } } public static void handleTeXMath(StringBuffer result, String[] mathStrings) { Map map = Application.get().getParameters(); HttpServletRequest request = (HttpServletRequest) map.get("request"); MathSniffer sniffy = MathSniffer.getBrowserDetection(request); switch (sniffy.getBrowserId()) { case MathSniffer.XMLID : case MathSniffer.MATHPLAYERID : result.append(mathStrings[0]); break; case MathSniffer.CSSID : result.append(mathStrings[1]); break; default : result.append(mathStrings[2]); } } } --- NEW FILE: CachedWikipediaParser.java --- /* * Created on 21.04.2004 * * To change the template for this generated file go to Window - Preferences - Java - Code Generation - Code and Comments */ package org.hartmath.server.filter; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Map; import java.util.NoSuchElementException; import java.util.Stack; import java.util.StringTokenizer; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; [...1876 lines suppressed...] */ 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; } } --- MacroHMathFilter.java DELETED --- |
From: Klaus H. <js...@us...> - 2004-04-25 18:49:37
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23955/WEB-INF/src/org/hartmath/server/cache Log Message: Directory /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/cache added to the repository |