|
From: Tim P <ti...@us...> - 2008-03-27 22:51:24
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/util In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22532/src/org/webmacro/util Modified Files: WMEval.java Log Message: Move methods to improve readability, remove code that cannot be reached as template output encoding is specified in defaults Index: WMEval.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/util/WMEval.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** WMEval.java 27 Mar 2008 10:19:35 -0000 1.27 --- WMEval.java 27 Mar 2008 22:51:17 -0000 1.28 *************** *** 284,303 **** /** - * Evaluate the named template against the given context - * and return the result as a String. - * If an output stream is specified, the return value is - * also written out to the stream. - * - * @param templateName The name of the template. - * @param out An optional output stream. - * @return The output from the evaluated template - */ - public String eval (Context context, String templateName, OutputStream out) - throws Exception - { - return eval(context, templateName, out, null); - } - - /** * Evaluates the string template against the current context * and returns the value. --- 284,287 ---- *************** *** 311,342 **** /** ! * Evaluates the string template against a new context and writes ! * it to the http Response output stream using the proper encoding. ! * <p> ! * This is an exceptionally useful method for a servlet to use to ! * write out a template. ! * <p> ! * @param context The WM context to use. * @param templateName The name of the template. ! * @param resp The servlet response from which the encoding will be derived. ! * @return The output from the evaluated template. */ ! public String eval (WebContext context, String templateName, ! HttpServletResponse resp) throws ServletException { ! String value = null; ! try { ! resp.setContentType("text/html"); ! String encoding = wm ! .getConfig(WMConstants.TEMPLATE_OUTPUT_ENCODING); ! if (encoding == null) { ! encoding = resp.getCharacterEncoding(); ! } ! value = eval(context, templateName, resp.getOutputStream(), ! encoding); ! } catch (Exception e) { ! throw new ServletException(e); ! } ! return value; } --- 295,311 ---- /** ! * Evaluate the named template against the given context ! * and return the result as a String. ! * If an output stream is specified, the return value is ! * also written out to the stream. ! * * @param templateName The name of the template. ! * @param out An optional output stream. ! * @return The output from the evaluated template */ ! public String eval (Context context, String templateName, OutputStream out) ! throws Exception { ! return eval(context, templateName, out, null); } *************** *** 381,384 **** --- 350,381 ---- return value; } + /** + * Evaluates the string template against a new context and writes + * it to the http Response output stream using the proper encoding. + * <p> + * This is an exceptionally useful method for a servlet to use to + * write out a template. + * <p> + * @param context The WM context to use. + * @param templateName The name of the template. + * @param resp The servlet response from which the encoding will be derived. + * @return The output from the evaluated template. + */ + public String eval (WebContext context, String templateName, + HttpServletResponse resp) throws ServletException + { + String value = null; + try { + resp.setContentType("text/html"); + String encoding = wm + .getConfig(WMConstants.TEMPLATE_OUTPUT_ENCODING); + value = eval(context, templateName, resp.getOutputStream(), + encoding); + } catch (Exception e) { + throw new ServletException(e); + } + return value; + } + /** *************** *** 396,400 **** public String eval (Context context, String templateName, String outputFileName, boolean append, String encoding) ! throws Exception { OutputStream out = new FileOutputStream(outputFileName, append); --- 393,397 ---- public String eval (Context context, String templateName, String outputFileName, boolean append, String encoding) ! throws Exception { OutputStream out = new FileOutputStream(outputFileName, append); |