[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server SnipEvalServlet.java,NONE,1.1 EvalO
Status: Pre-Alpha
Brought to you by:
jsurfer
|
From: <js...@us...> - 2004-03-09 20:38:37
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21210/WEB-INF/src/org/hartmath/server Added Files: SnipEvalServlet.java EvalOutputFormServlet.java MathMLPresentation.java Log Message: initial version --- NEW FILE: SnipEvalServlet.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; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.snipsnap.app.Application; import org.snipsnap.config.Configuration; /** * Load a snip to view. * * @author Matthias L. Jugel * @version $Id: SnipEvalServlet.java,v 1.1 2004/03/09 20:13:13 jsurfer Exp $ */ public class SnipEvalServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String query = request.getParameter("expr"); if (query != null && query.length() > 0) { HttpSession session = request.getSession(); session.setAttribute("expr", query); RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/eval.jsp"); dispatcher.forward(request, response); return; } Configuration config = Application.get().getConfiguration(); response.sendRedirect(config.getUrl()); } } --- NEW FILE: EvalOutputFormServlet.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; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.hartmath.core.eval.TimeConstrainedEvaluator; import org.radeox.util.StringBufferWriter; /** * Load a snip to edit. Loads the snip into the request context. In case * the snip is newly created put the name into "snip_name". * * @author Matthias L. Jugel * @version $Id: EvalOutputFormServlet.java,v 1.1 2004/03/09 20:13:13 jsurfer Exp $ */ public class EvalOutputFormServlet extends HttpServlet { private static final String EVAL_OUTPUT_FORM_KEY = "eval_output_form_servlet"; public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // UserManager um = UserManagerFactory.getInstance(); // User user = Application.get().getUser(); // if (um.isAuthenticated(user)) { // user.lastAccess(); // } HttpSession session = request.getSession(); TimeConstrainedEvaluator utility; if (session.isNew()) { //log("new session "+session.toString()); utility = new TimeConstrainedEvaluator(session.getId(), false, 2000); session.setAttribute(EVAL_OUTPUT_FORM_KEY, utility); } else { //log("old session "+session.toString()); utility = (TimeConstrainedEvaluator) session.getAttribute(EVAL_OUTPUT_FORM_KEY); if (utility == null) { utility = new TimeConstrainedEvaluator(session.getId(), false, 2000); session.setAttribute(EVAL_OUTPUT_FORM_KEY, utility); } } // // handle the snip name // String name = request.getPathInfo(); // if (null == name || "/".equals(name)) { // name = "start"; // } else { // name = name.substring(1); // } // name = name.replace('+', ' '); String query = request.getParameter("content"); if (request.getParameter("eval") != null) { } StringBuffer buffer = new StringBuffer(); StringBufferWriter writer = new StringBufferWriter(buffer); utility.constrainedEval(writer, query); // if (result!=null) { // OutputFormFactory.convert(buffer,result); // request.setAttribute("result", buffer.toString()); // } request.setAttribute("result", buffer.toString()); RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/evaloutput.jsp"); dispatcher.forward(request, response); } } --- NEW FILE: MathMLPresentation.java --- /* * Created on 23.09.2003 * */ package org.hartmath.server; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.hartmath.core.eval.MathMLUtilities; /** * Converst a request parameter "expr" into MATHML output * */ public class MathMLPresentation extends HttpServlet { public static final String MATHML_FOOTER = "</body></html>"; public static final String MATHML_HEADER = "<?xml version=\"1.0\"?>" + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" " + " \"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd\" [" + " <!ENTITY mathml \"http://www.w3.org/1998/Math/MathML\">" + "]>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title></title></head><body>"; public static final String MATHML_HEADER_MSIE = "<html xmlns:m=\"http://www.w3.org/1998/Math/MathML\" xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">" + "<head>" + "<title></title>" + "<object id=\"showEqn\" classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\">" + "<!--comment required to prevent this becoming an empty tag-->" + "</object>" + "<?import NAMESPACE=\"M\" IMPLEMENTATION=\"#showEqn\"?>" + "</head><body>"; public static final String MATHML_FOOTER_MSIE = "</body></html>"; private static final String MATHML_UTILITY_KEY = "mathml_utility_servlet"; /** * MS Internet Explorer ActiveX on client side */ private final static boolean MSIE = true; /** * Create a complete HTML page? */ private boolean fShowPage; protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // log("doPost"); String inputExpression = null; fShowPage = false; PrintWriter out = new PrintWriter(resp.getOutputStream()); MathMLUtilities utility; HttpSession session = req.getSession(true); if (session.isNew()) { //log("new session "+session.toString()); utility = new MathMLUtilities(session.getId(), MSIE); session.setAttribute(MATHML_UTILITY_KEY, utility); } else { //log("old session "+session.toString()); utility = (MathMLUtilities) session.getAttribute(MATHML_UTILITY_KEY); if (utility == null) { utility = new MathMLUtilities(session.getId(), MSIE); session.setAttribute(MATHML_UTILITY_KEY, utility); } } // get request parameters if (req.getParameterValues("expr") != null) { inputExpression = req.getParameterValues("expr")[0]; } if (req.getParameterValues("page") != null) { fShowPage = true; } if (!fShowPage) { resp.setContentType("text/xml"); } resp.setHeader("pragma", "no-cache"); if (fShowPage) { // out.println(MATHML_HEADER); out.println(MATHML_HEADER_MSIE); } utility.toMathML(inputExpression, out); if (fShowPage) { // out.println(MATHML_FOOTER); out.println(MATHML_FOOTER_MSIE); } out.close(); } public String getServletInfo() { return "MathML converter servlet"; } public void init(ServletConfig config) throws ServletException { super.init(config); } // /** Replace all // * '<' with '<', // * '>' with '>', // * '"' with '"' // * '&' with '&'. // */ // public static String htmlSpecialChars(String str) { // StringBuffer htmlString = new StringBuffer(str.length() + 50); // char c; // for (int i = 0; i < str.length(); i++) { // c = str.charAt(i); // switch (c) { // case '<' : // htmlString.append("<"); // break; // case '>' : // htmlString.append(">"); // break; // case '"' : // htmlString.append("""); // break; // case '&' : // htmlString.append("&"); // break; // default : // htmlString.append(c); // } // } // return (htmlString.toString()); // } } |