[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/taglib BrowserTag.java,NONE,1.1 Eva
Status: Pre-Alpha
Brought to you by:
jsurfer
|
From: <js...@us...> - 2004-03-09 20:38:31
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/taglib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21210/WEB-INF/src/org/hartmath/server/taglib Added Files: BrowserTag.java EvalTag.java MathMLTag.java WikiTag.java Log Message: initial version --- NEW FILE: BrowserTag.java --- package org.hartmath.server.taglib; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; import org.snipsnap.app.Application; /** * Java JSP taglib interface to detect the clients browser type * */ public class BrowserTag extends BodyTagSupport { private String fType; private String fContent = null; public static String MSIE = "msie"; public static String NETSCAPE = "netscape"; /** * Returns "msie" for Internet Explorer; "netscape" otherwise * * @param request * @return */ public static String getBrowserType(HttpServletRequest request) { String userAgentString = request.getHeader("User-Agent"); String browser = new String(""); if (userAgentString != null) { if ((userAgentString.indexOf("MSIE") == -1) && (userAgentString.indexOf("msie") == -1)) { browser = NETSCAPE; } else { browser = MSIE; } } return browser; } private String getBrowserVersion(HttpServletRequest request) { String userAgentString = request.getHeader("User-Agent"); String version = new String(""); if (userAgentString != null) { if ((userAgentString.indexOf("MSIE") == -1) && (userAgentString.indexOf("msie") == -1)) { int verPos = userAgentString.indexOf("/"); if (verPos != -1) version = userAgentString.substring(verPos + 1, verPos + 5); } else { String tempStr = userAgentString.substring(userAgentString.indexOf("MSIE"), userAgentString.length()); version = tempStr.substring(4, tempStr.indexOf(";")); } } return version; } public int doAfterBody() throws JspException { // log("doPost"); BodyContent body = getBodyContent(); JspWriter out = body.getEnclosingWriter(); String bodyData = body.getString(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); // HttpSession session = request.getSession(true); String browserType = getBrowserType(request); // System.out.println(browserType); // System.out.println(fType); if (browserType.equalsIgnoreCase(fType)) { if (fContent != null) { pageContext.getResponse().setContentType(fContent+"; "+Application.get().getConfiguration().getEncoding()); } try { out.print(bodyData); } catch (IOException e) { } } return SKIP_BODY; } /** * @return */ public String getType() { return fType; } /** * @param string */ public void setType(String string) { fType = string; } /** * @return */ public String getContent() { return fContent; } /** * @param string */ public void setContent(String string) { fContent = string; } } --- NEW FILE: EvalTag.java --- package org.hartmath.server.taglib; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; import org.hartmath.core.eval.EvalUtilities; /** * Java JSP taglib interface for evaluating HartMath expressions * */ public class EvalTag extends BodyTagSupport { private static final String EVAL_UTILITY_KEY = "eval_utility_taglib"; public int doAfterBody() throws JspException { // log("doPost"); BodyContent body = getBodyContent(); JspWriter out = body.getEnclosingWriter(); String inputExpression = body.getString(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); HttpSession session = request.getSession(true); if (inputExpression != null && !inputExpression.equals("")) { EvalUtilities evalUtility; if (session.isNew()) { //log("new session "+session.toString()); evalUtility = new EvalUtilities(session.getId(), true); session.setAttribute(EVAL_UTILITY_KEY, evalUtility); } else { //log("old session "+session.toString()); evalUtility = (EvalUtilities) session.getAttribute(EVAL_UTILITY_KEY); if (evalUtility == null) { evalUtility = new EvalUtilities(session.getId(), true); session.setAttribute(EVAL_UTILITY_KEY, evalUtility); } } evalUtility.toMathML(inputExpression, out); } return SKIP_BODY; } } --- NEW FILE: MathMLTag.java --- package org.hartmath.server.taglib; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; import org.hartmath.core.eval.MathMLUtilities; /** * Java JSP taglib interface for the HartMath MathML converter * */ public class MathMLTag extends BodyTagSupport { private static final String MATHML_UTILITY_KEY = "mathml_utility_taglib"; public int doAfterBody() throws JspException { // log("doPost"); BodyContent body = getBodyContent(); JspWriter out = body.getEnclosingWriter(); String inputExpression = body.getString(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); HttpSession session = request.getSession(true); if (inputExpression != null && !inputExpression.equals("")) { MathMLUtilities mathmlUtility; if (session.isNew()) { //log("new session "+session.toString()); mathmlUtility = new MathMLUtilities(session.getId(), true); session.setAttribute(MATHML_UTILITY_KEY, mathmlUtility); } else { //log("old session "+session.toString()); mathmlUtility = (MathMLUtilities) session.getAttribute(MATHML_UTILITY_KEY); if (mathmlUtility == null) { mathmlUtility = new MathMLUtilities(session.getId(), true); session.setAttribute(MATHML_UTILITY_KEY, mathmlUtility); } } mathmlUtility.toMathML(inputExpression, out); } return SKIP_BODY; } } --- NEW FILE: WikiTag.java --- package org.hartmath.server.taglib; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; import org.radeox.api.engine.RenderEngine; import org.radeox.engine.BaseRenderEngine; import org.radeox.engine.context.BaseRenderContext; /** * Java JSP taglib interface for using Wiki syntax * */ public class WikiTag extends BodyTagSupport { private final static RenderEngine RADEOX_RENDER_ENGINE = new BaseRenderEngine(); private final static BaseRenderContext RADEOX_CONTEXT_ENGINE = new BaseRenderContext(); public int doAfterBody() throws JspException { // log("doPost"); BodyContent body = getBodyContent(); JspWriter out = body.getEnclosingWriter(); String inputExpression = body.getString(); if (inputExpression != null && !inputExpression.equals("")) { try { RADEOX_RENDER_ENGINE.render(out, inputExpression, RADEOX_CONTEXT_ENGINE); } catch (IOException e) { throw new JspException("IOException in JSP Wiki tag", e); } } return SKIP_BODY; } } |