[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/cache ICachedPage.java,NONE,1.1 Cac
Status: Pre-Alpha
Brought to you by:
jsurfer
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) { } } |