[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/macro FieldMacro.java,NONE,1.1 Link
Status: Pre-Alpha
Brought to you by:
jsurfer
|
From: Klaus H. <js...@us...> - 2004-03-20 10:20:31
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/macro In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8583/WEB-INF/src/org/hartmath/server/macro Added Files: FieldMacro.java LinkMacro.java GraphMacro.java Log Message: misc changes --- NEW FILE: GraphMacro.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 org.hartmath.server.filter.INoParserBodyFilterMacro; import org.snipsnap.render.macro.SnipMacro; import org.snipsnap.render.macro.parameter.SnipMacroParameter; import org.snipsnap.snip.Snip; /* * Macro that renders graphs. * * @author stephan * @team sonicteam * @version $Id: GraphMacro.java,v 1.1 2004/03/20 10:10:35 jsurfer Exp $ */ public class GraphMacro extends SnipMacro implements INoParserBodyFilterMacro { public GraphMacro() { } public String getName() { return "graph"; } public String getDescription() { return "Render a graph like an organigram or mindmap."; } public void execute(Writer writer, SnipMacroParameter params) throws IllegalArgumentException, IOException { Snip snip = params.getSnipRenderContext().getSnip(); String name = snip.getName(); String handler = params.get("handler", 0); // writer.write(""+params.getContentStart()); // writer.write(":"+ params.getContentEnd()); // writer.write(":"+params.getSnip().getContent().length()); // writer.write("<br/>"); writer.write("<img src=\"exec/render?name="); writer.write(name); writer.write("&handler="); writer.write(handler); // Remove {graph} from start and end offset int start = snip.getContent().indexOf('}', params.getStart() + getName().length()) + 1; int end = params.getEnd() - getName().length() - 2; writer.write("&start=" + start); writer.write("&end=" + end); // writer.write("&start="+params.getContentStart()); // writer.write("&end="+params.getContentEnd()); writer.write("\"/>"); } } --- NEW FILE: LinkMacro.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.radeox.api.engine.ImageRenderEngine; import org.radeox.api.engine.RenderEngine; import org.radeox.api.engine.context.RenderContext; import org.radeox.macro.BaseLocaleMacro; import org.radeox.macro.parameter.MacroParameter; import org.radeox.util.Encoder; /* * Macro for displaying external links with a name. The normal UrlFilter * takes the url as a name. * * @author stephan * @team sonicteam * @version $Id: LinkMacro.java,v 1.1 2004/03/20 10:10:35 jsurfer Exp $ */ public class LinkMacro extends BaseLocaleMacro { public String getLocaleKey() { return "macro.link"; } public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { RenderContext context = params.getContext(); RenderEngine engine = context.getRenderEngine(); String text = params.get("text", 0); String url = params.get("url", 1); String img = params.get("img", 2); // check for single url argument (text == url) if(params.getLength() == 1) { url = text; text = Encoder.toEntity(text.charAt(0)) + Encoder.escape(text.substring(1)); } if (url != null && text != null) { writer.write("<span class=\"nobr\">"); if (!"none".equals(img) && engine instanceof ImageRenderEngine) { writer.write(((ImageRenderEngine) engine).getExternalImageLink()); } writer.write("<a href=\""); writer.write(Encoder.escape(url)); writer.write("\">"); writer.write(text); writer.write("</a></span>"); } else { throw new IllegalArgumentException("link needs a name and a url as argument"); } return; } } --- NEW FILE: FieldMacro.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 org.radeox.util.Encoder; import org.snipsnap.render.macro.SnipMacro; import org.snipsnap.render.macro.parameter.SnipMacroParameter; import org.snipsnap.snip.SnipLink; /* * Macro that creates (HTML) input fields with forms. * * @author stephan * @team sonicteam * @version $Id: FieldMacro.java,v 1.1 2004/03/20 10:10:35 jsurfer Exp $ */ public class FieldMacro extends SnipMacro { public String getName() { return "field"; } public String getDescription() { return "Display a form input field and submit button."; } /** * {field:id|value|target|button} */ public void execute(Writer writer, SnipMacroParameter params) throws IllegalArgumentException, IOException { if (params.getLength() > 0) { writer.write("<form class=\"form\" action=\""); if (params.getLength() >= 3) { SnipLink.appendUrl(writer, params.get("2")); } else { SnipLink.appendUrl(writer, params.getSnipRenderContext().getSnip().getName()); } writer.write("\" method=\"get\">"); writer.write("<input size=\"18\" name=\""); writer.write(Encoder.escape( params.get("0") )); writer.write("\""); if (params.getLength() >= 2) { writer.write(" value=\""); writer.write(Encoder.escape(params.get("1"))); writer.write("\""); } writer.write("/>"); if (params.getLength() >= 4) { writer.write(" <input type=\"submit\" name=\"submit\" value=\""); writer.write(Encoder.escape(params.get("3"))); writer.write("\"/>"); } writer.write("</form>"); return; } else { throw new IllegalArgumentException("Number of arguments does not match"); } } } |