[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/macro HMathMacro.java,NONE,1.1 Quot
Status: Pre-Alpha
Brought to you by:
jsurfer
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21210/WEB-INF/src/org/hartmath/server/macro Added Files: HMathMacro.java QuoteMacro.java CodeMacro.java HMathMacroLoader.java HMathMacroRepository.java WeblogMacro.java MMLMacro.java EvalMacro.java MacroListMacro.java JViewMacro.java MathMLMacro.java WikipediaMacro.java TableMacro.java Log Message: initial version --- NEW FILE: HMathMacro.java --- /* * * */ package org.hartmath.server.macro; import org.hartmath.server.filter.INoParserBodyFilterMacro; import org.radeox.macro.BaseMacro; /** * @author jsurfer * */ public abstract class HMathMacro extends BaseMacro implements INoParserBodyFilterMacro { } --- NEW FILE: QuoteMacro.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.macro; import java.io.IOException; import java.io.Writer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hartmath.server.filter.INoParserBodyFilterMacro; import org.radeox.macro.LocalePreserved; import org.radeox.macro.parameter.MacroParameter; /* * Macro to display quotations from other sources. The * output is wrapped usually in <blockquote> to look like * a quotation. * * @author stephan * @team sonicteam * @version $Id: QuoteMacro.java,v 1.1 2004/03/09 20:13:05 jsurfer Exp $ */ public class QuoteMacro extends LocalePreserved implements INoParserBodyFilterMacro { private static Log log = LogFactory.getLog(QuoteMacro.class); private String[] paramDescription = {"?1: source", "?2: displayed description, default is Source"}; public String[] getParamDescription() { return paramDescription; } public QuoteMacro() { } public String getLocaleKey() { return "macro.quote"; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { writer.write("<blockquote class=\"quote\">"); writer.write(params.getContent()); String source = "Source"; // i18n if (params.getLength() == 2) { source = params.get(1); } // if more than one was present, we // should show a description for the link if (params.getLength() > 0) { writer.write("<a href=\""+params.get(0)+"\">"); writer.write(source); writer.write("</a>"); } writer.write("</blockquote>"); return; } } --- NEW FILE: CodeMacro.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.macro; import java.io.IOException; import java.io.Writer; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hartmath.server.filter.INoParserBodyFilterMacro; import org.radeox.api.engine.context.InitialRenderContext; import org.radeox.api.engine.context.RenderContext; import org.radeox.filter.context.BaseFilterContext; import org.radeox.filter.context.FilterContext; import org.radeox.macro.LocalePreserved; import org.radeox.macro.code.SourceCodeFormatter; import org.radeox.macro.parameter.MacroParameter; import org.radeox.util.Encoder; import org.radeox.util.Service; /* * Macro for displaying programming language source code. CodeMacro knows about * different source code formatters which can be plugged into radeox to * display more languages. CodeMacro displays Java, Ruby or SQL code. * * @author stephan * @team sonicteam * @version $Id: CodeMacro.java,v 1.1 2004/03/09 20:13:05 jsurfer Exp $ */ public class CodeMacro extends LocalePreserved implements INoParserBodyFilterMacro { private static Log log = LogFactory.getLog(CodeMacro.class); private Map formatters; private FilterContext nullContext = new BaseFilterContext(); private String start; private String end; private String[] paramDescription = {"?1: syntax highlighter to use, defaults to java"}; public String[] getParamDescription() { return paramDescription; } public String getLocaleKey() { return "macro.code"; } public void setInitialContext(InitialRenderContext context) { super.setInitialContext(context); Locale outputLocale = (Locale) context.get(RenderContext.OUTPUT_LOCALE); String outputName = (String) context.get(RenderContext.OUTPUT_BUNDLE_NAME); ResourceBundle outputMessages = ResourceBundle.getBundle(outputName, outputLocale); start = outputMessages.getString(getLocaleKey() + ".start"); end = outputMessages.getString(getLocaleKey() + ".end"); } public CodeMacro() { formatters = new HashMap(); Iterator formatterIt = Service.providers(SourceCodeFormatter.class); while (formatterIt.hasNext()) { try { SourceCodeFormatter formatter = (SourceCodeFormatter) formatterIt.next(); String name = formatter.getName(); if (formatters.containsKey(name)) { SourceCodeFormatter existing = (SourceCodeFormatter) formatters.get(name); if (existing.getPriority() < formatter.getPriority()) { formatters.put(name, formatter); log.debug("Replacing formatter: " + formatter.getClass() + " (" + name + ")"); } } else { formatters.put(name, formatter); log.debug("Loaded formatter: " + formatter.getClass() + " (" + name +")"); } } catch (Exception e) { log.warn("CodeMacro: unable to load code formatter", e); } } addSpecial('['); addSpecial(']'); addSpecial('{'); addSpecial('}'); addSpecial('*'); addSpecial('-'); addSpecial('\\'); } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { SourceCodeFormatter formatter = null; if (params.getLength() == 0 || !formatters.containsKey(params.get("0"))) { formatter = (SourceCodeFormatter) formatters.get(initialContext.get(RenderContext.DEFAULT_FORMATTER)); if (null == formatter) { System.err.println("Formatter not found."); formatter = (SourceCodeFormatter) formatters.get("java"); } } else { formatter = (SourceCodeFormatter) formatters.get(params.get("0")); } String result = formatter.filter(Encoder.escape( params.getContent() ), nullContext); writer.write(start); writer.write(replace(result.trim())); writer.write(end); return; } } --- NEW FILE: HMathMacroLoader.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.macro; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.radeox.macro.PluginLoader; import org.radeox.macro.Repository; /** * Plugin loader for macros * * @author Stephan J. Schmidt * @version $Id: HMathMacroLoader.java,v 1.1 2004/03/09 20:13:05 jsurfer Exp $ */ public class HMathMacroLoader extends PluginLoader { private static Log log = LogFactory.getLog(HMathMacroLoader.class); public Class getLoadClass() { return HMathMacro.class; } /** * Add a plugin to the known plugin map * * @param macro Macro to add */ public void add(Repository repository, Object plugin) { if (plugin instanceof HMathMacro) { repository.put(((HMathMacro) plugin).getName(), plugin); } else { log.debug("MacroLoader: " + plugin.getClass() + " not of Type " + getLoadClass()); } } } --- NEW FILE: HMathMacroRepository.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.macro; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.radeox.macro.PluginRepository; import org.radeox.macro.Repository; /** * Repository for plugins * * @author Stephan J. Schmidt * @version $Id: HMathMacroRepository.java,v 1.1 2004/03/09 20:13:05 jsurfer Exp $ */ public class HMathMacroRepository extends PluginRepository { private static Log log = LogFactory.getLog(HMathMacroRepository.class); protected static HMathMacroRepository instance; protected List loaders; public synchronized static Repository getInstance() { if (null == instance) { instance = new HMathMacroRepository(); } return instance; } private void load() { Iterator iterator = loaders.iterator(); while (iterator.hasNext()) { HMathMacroLoader loader = (HMathMacroLoader) iterator.next(); log.debug("Loading from: " + loader.getClass()); loader.loadPlugins(this); } } private HMathMacroRepository() { loaders = new ArrayList(); loaders.add(new HMathMacroLoader()); load(); } } --- NEW FILE: WeblogMacro.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.macro; import java.io.IOException; import java.io.Writer; import java.util.Iterator; import java.util.List; import org.snipsnap.render.macro.SnipMacro; import org.snipsnap.render.macro.parameter.SnipMacroParameter; import org.snipsnap.snip.Blog; import org.snipsnap.snip.Snip; import org.snipsnap.snip.SnipLink; import org.snipsnap.snip.SnipSpace; import org.snipsnap.snip.SnipSpaceFactory; import org.snipsnap.snip.SnipUtil; import org.snipsnap.util.StringUtil; /* * Macro that displays a weblog. All subsnips are read and * displayed in reverse chronological order. * * @author stephan * @version $Id: WeblogMacro.java,v 1.1 2004/03/09 20:13:06 jsurfer Exp $ */ public class WeblogMacro extends SnipMacro { private SnipSpace space; private String[] paramDescription = {"?1: number of shown posts"}; public WeblogMacro() { space = SnipSpaceFactory.getInstance(); } public String getName() { return "weblog"; } public String getDescription() { return "Renders the sub-snips from the namespace as a weblog."; } public String[] getParamDescription() { return paramDescription; } public void execute(Writer writer, SnipMacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() < 2) { int count = 0; if (params.getLength() == 1) { count = Integer.parseInt(params.get("0")); } else { count = 10; } String name = params.getSnipRenderContext().getSnip().getName(); Blog blog = space.getBlog(name); // order by name // with correct ending /1,/2,/3,...,/11,/12 List posts = blog.getPosts(count); //System.out.println("Weblog Posts for '"+name+"': "+posts.size()); // Convert // - all Snips with start parent -> rename start/2003-05-02 // - comments? // start/2002-03-01 // start/2002-05-06 // start/2002-05-06/1 // start/2002-05-06/2 // // 1. Group by day // - iterate // - cut "name/" // - get day // - if day changes, render new day // 2. Render each day int NAME_INDEX = 0; int DAY_INDEX = 1; int COUNT_INDEX = 2; String lastDay = ""; Iterator iterator = posts.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); // System.err.println("Class="+object.getClass()); Snip entry = (Snip) object; String[] entryName = StringUtil.split(entry.getName(), "/"); int slashOffset = entryName.length - 3; String day = (entryName.length > 1 ? entryName[slashOffset + DAY_INDEX] : entryName[0]); // New Day? //System.err.println("entryName="+Arrays.asList(entryName)); if (!lastDay.equals(day)) { writer.write("<div class=\"blog-date\">"); writer.write(SnipUtil.toDate(day)); lastDay = day; writer.write("</div>"); } writer.write(entry.getXMLContent()); writer.write(" <a href=\""); SnipLink.appendUrl(writer, entry.getName()); writer.write("\" title=\"Permalink to "); writer.write(entry.getName()); writer.write("\">"); SnipLink.appendImage(writer, "Icon-Permalink", "PermaLink"); writer.write("</a>"); writer.write("<div class=\"snip-post-comments\">"); writer.write(entry.getComments().getCommentString()); writer.write(" | "); 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 { throw new IllegalArgumentException("Number of arguments does not match"); } } } --- NEW FILE: MMLMacro.java --- package org.hartmath.server.macro; import java.io.IOException; import java.io.Writer; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.hartmath.core.eval.MathMLUtilities; import org.hartmath.server.taglib.BrowserTag; import org.radeox.macro.parameter.MacroParameter; import org.snipsnap.app.Application; /* * A MathML macro. This Macro displays the generated MathML from a math expression * * @author jsurfer */ public class MMLMacro extends HMathMacro { private String[] paramDescription = { }; private static MathMLUtilities MATHML_UTILITY_MSIE = null; private static MathMLUtilities MATHML_UTILITY_NETSCAPE = null; public String getName() { return "mml"; } public String getDescription() { return "Generate MathML from a math expression (i.e. D[Sin[x],x] )"; } public String[] getParamDescription() { return paramDescription; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() == 0) { Map map = Application.get().getParameters(); HttpServletRequest request = (HttpServletRequest) map.get("request"); String browser = BrowserTag.getBrowserType(request); // TODO optimize this code; create a new MathMLUtilities once for every session! if (browser == BrowserTag.MSIE) { if (MATHML_UTILITY_MSIE == null) { MATHML_UTILITY_MSIE = new MathMLUtilities("MMLMacro", true); } MATHML_UTILITY_MSIE.toMathML(params.getContent(), writer); } else { if (MATHML_UTILITY_NETSCAPE == null) { MATHML_UTILITY_NETSCAPE = new MathMLUtilities("MMLMacro", false); } MATHML_UTILITY_NETSCAPE.toMathML(params.getContent(), writer); } } else { throw new IllegalArgumentException("Number of arguments does not match"); } } } --- NEW FILE: EvalMacro.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.macro; import java.io.IOException; import java.io.Writer; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.hartmath.core.eval.TimeConstrainedEvaluator; import org.hartmath.server.filter.IRenderResultMacro; import org.radeox.macro.BaseMacro; import org.radeox.macro.parameter.MacroParameter; import org.snipsnap.app.Application; import org.snipsnap.container.Components; import org.snipsnap.snip.SnipSpace; import org.snipsnap.snip.SnipSpaceFactory; import org.snipsnap.user.AuthenticationService; /* * Macro for fulltext searches in SnipSnap. The macro displays the search results for the input string. Can be used in snips to * "store" searches. For user defined searches use a {field} macro combined with the {search} macro. * * @author stephan * * @version $Id: EvalMacro.java,v 1.1 2004/03/09 20:13:06 jsurfer Exp $ */ public class EvalMacro extends BaseMacro implements IRenderResultMacro { private SnipSpace space; private static final String SNIP_EVAL_MACRO_KEY = "eval_output_form_servlet"; private String[] paramDescription = { "1: string to evaluate" }; public EvalMacro() { space = SnipSpaceFactory.getInstance(); } public String[] getParamDescription() { return paramDescription; } public String getName() { return "eval"; } public String getDescription() { return "Evaluate a mathematical expression."; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() == 1) { String expressionString = params.get("0"); AuthenticationService service = (AuthenticationService) Components.getComponent(AuthenticationService.class); if (expressionString == null || expressionString.trim().length() == 0) { } else if (!service.isAuthenticated(Application.get().getUser())) { writer.write("<p>Only <b>registered users</b> can use this service</p>"); } else { TimeConstrainedEvaluator utility; Map map = Application.get().getParameters(); HttpServletRequest request = (HttpServletRequest) map.get("request"); HttpSession session = request.getSession(); if (session.isNew()) { //log("new session "+session.toString()); utility = new TimeConstrainedEvaluator(session.getId(), false, 2000); session.setAttribute(SNIP_EVAL_MACRO_KEY, utility); } else { //log("old session "+session.toString()); utility = (TimeConstrainedEvaluator) session.getAttribute(SNIP_EVAL_MACRO_KEY); if (utility == null) { utility = new TimeConstrainedEvaluator(session.getId(), false, 2000); session.setAttribute(SNIP_EVAL_MACRO_KEY, utility); } } // StringBuffer buffer = new StringBuffer(); writer.write("{code:none}\n"); // writer.write(buffer.toString()); utility.constrainedEval(writer, expressionString); writer.write("{code}"); // request.setAttribute("result", buffer.toString()); } return; } else { throw new IllegalArgumentException("Number of arguments does not match"); } } } --- NEW FILE: MacroListMacro.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.macro; import java.io.IOException; import java.io.Writer; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.hartmath.server.filter.IRenderResultMacro; import org.radeox.macro.BaseLocaleMacro; import org.radeox.macro.Macro; import org.radeox.macro.MacroRepository; import org.radeox.macro.parameter.MacroParameter; /* * MacroListMacro displays a list of all known macros of the EngineManager * with their name, parameters and a description. * * @author Matthias L. Jugel * @version $Id: MacroListMacro.java,v 1.1 2004/03/09 20:13:06 jsurfer Exp $ */ 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); } else { throw new IllegalArgumentException("MacroListMacro: number of arguments does not match"); } } public Writer appendTo(Writer writer) throws IOException { List macroList = MacroRepository.getInstance().getPlugins(); Collections.sort(macroList); Iterator iterator = macroList.iterator(); writer.write("{table}\n"); writer.write("Macro|Description|Parameters\n"); while (iterator.hasNext()) { Macro macro = (Macro) iterator.next(); writer.write(macro.getName()); writer.write("|"); writer.write(macro.getDescription()); writer.write("|"); String[] params = macro.getParamDescription(); if (params.length == 0) { writer.write("none"); } else { for (int i = 0; i < params.length; i++) { String description = params[i]; if (description.startsWith("?")) { writer.write(description.substring(1)); writer.write(" (optional)"); } else { writer.write(params[i]); } writer.write("\\\\"); } } writer.write("\n"); } writer.write("{table}"); return writer; } } --- NEW FILE: JViewMacro.java --- package org.hartmath.server.macro; import java.io.IOException; import java.io.Writer; import org.radeox.macro.parameter.MacroParameter; import org.snipsnap.app.Application; /* * A Javaview macro. This Macro displays the mathematica graphic * * @author jsurfer */ public class JViewMacro extends HMathMacro { private String[] paramDescription = { }; public JViewMacro() { } public String getName() { return "jview"; } public String getDescription() { return "Insert the content as a Javaview applet."; } public String[] getParamDescription() { return paramDescription; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() == 0) { String copy = params.getContent(); // de-escape tag delimiters copy = copy.replaceAll("<", "<"); copy = copy.replaceAll(">", ">"); copy = copy.replaceAll("\n", " "); copy = copy.replaceAll("\r", " "); writer.write( "<applet name=\"jvLite\" code=\"jvLite.class\" " + "codebase=\"" + Application.get().getConfiguration().getUrl("/lib") +"\" " + "width=\"400\" height=\"300\" " + "alt=\"JavaView lite applet\" " + "archive=\"jvLite.jar\" id=\"applet1\">\n" + "<param name=\"Axes\" value=\"show\" />\n" + "<param name=\"mathematica\" value=\""); // System.out.println(copy); // writer.write(replace(copy)); writer.write(copy); writer.write("\" /></applet>"); } else { throw new IllegalArgumentException("Number of arguments does not match"); } } } --- NEW FILE: MathMLMacro.java --- package org.hartmath.server.macro; import java.io.IOException; import java.io.Writer; import org.radeox.macro.parameter.MacroParameter; /* * A MathML macro. This Macro displays the generated MathML from a math expression * * @author jsurfer */ public class MathMLMacro extends HMathMacro { private String[] paramDescription = { }; public String getName() { return "mathml"; } public String getDescription() { return "Insert the content as a pure MathML xml-tree."; } public String[] getParamDescription() { return paramDescription; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() == 0) { String copy = params.getContent(); // de-escape tag delimiters copy = copy.replaceAll("<\\/", "</m:"); copy = copy.replaceAll("<m", "<m:m"); // copy = copy.replaceAll(">", ">"); // System.out.println(copy); // TODO check if this tag contains a valid mathml expression int index0 = copy.indexOf("<m:math"); if (index0 >= 0) { index0 = copy.indexOf("</m:math>", index0 + 6); } if (index0 < 0) { copy = "<m:math><m:mtext>!!!Expecting complete math-tag for mathml-plugin!!!</m:mtext></m:math>"; } writer.write(copy); } else { throw new IllegalArgumentException("Number of arguments does not match"); } } } --- NEW FILE: WikipediaMacro.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.macro; import java.io.IOException; import java.io.Writer; import org.hartmath.server.filter.IRenderResultMacro; import org.radeox.macro.parameter.MacroParameter; /* * Macro that displays a copyright link to Wikipedia * * @author jsurfer */ public class WikipediaMacro extends HMathMacro implements IRenderResultMacro { private String fCopiedFrom; private String fWikipediaCopyright; private String[] paramDescription = {"Wikipedia reference"}; public String[] getParamDescription() { return paramDescription; } public WikipediaMacro() { fCopiedFrom = "Copied from http://en.wikipedia.org/wiki/"; fWikipediaCopyright = "http://en.wikipedia.org/wiki/Wikipedia:Copyrights"; } public String getDescription() { return "Displays a Wikipedia reference."; } public String getName() { return "wikipedia"; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() == 1) { writer.write(fCopiedFrom); writer.write(params.get(0)); writer.write("<br/>"); writer.write(fWikipediaCopyright); } else { throw new IllegalArgumentException("Number of arguments does not match"); } } } --- NEW FILE: TableMacro.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.macro; import java.io.IOException; import java.io.Writer; import org.hartmath.server.filter.INoParserBodyFilterMacro; import org.hartmath.server.macro.table.Table; import org.hartmath.server.macro.table.TableBuilder; import org.radeox.api.engine.context.RenderContext; import org.radeox.macro.BaseLocaleMacro; import org.radeox.macro.parameter.MacroParameter; /* * Macro for defining and displaying tables. The rows of the table are * devided by newlins and the columns are divided by pipe symbols "|". * The first line of the table is rendered as column headers. * {table} * A|B|C * 1|2|3 * {table} * * @author stephan * @team sonicteam * @version $Id: TableMacro.java,v 1.1 2004/03/09 20:13:06 jsurfer Exp $ */ public class TableMacro extends BaseLocaleMacro implements INoParserBodyFilterMacro { private String[] paramDescription = {}; public String[] getParamDescription() { return paramDescription; } public String getLocaleKey() { return "macro.table"; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { String content = params.getContent(); if (null == content) throw new IllegalArgumentException("TableMacro: missing table content"); content = content.trim() + "\n"; RenderContext context = params.getContext(); Table table = TableBuilder.build(content, context); table.calc(); // calculate macros like =SUM(A1:A3) table.appendTo(writer); return; } } |