📄 enginerenderer.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// EngineRenderer// EV 04.12.2000//// render( sourceFile, formString )////package org.jahia.engines;import java.io.*; // PrintWriterimport java.util.*; // HashMapimport javax.servlet.*; // ServletExceptionimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.params.*; // ParamBeanimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.data.*; // JahiaDataimport org.jahia.exceptions.JahiaException;public class EngineRenderer { public static final String FORM_TOKEN = "<!--ENGINE_CONTENT-->"; private static EngineRenderer theObject = null; private static final String ENGINE_JSP = "/jsp/jahia/engines/engine.jsp"; /*** * constructor * EV 04.12.2000 * */ private EngineRenderer() { JahiaConsole.println( "EngineRenderer", "***** Starting EngineRenderer *****" ); } // end constructor /*** * getInstance * EV 04.12.2000 * */ public static synchronized EngineRenderer getInstance() { if (theObject == null) { theObject = new EngineRenderer(); } return theObject; } // end getInstance /*** * render * ParamBean render * EV 23.12.2000 * AK 04.01.2001 remove the fileName from method arguments * */ public void render( ParamBean jParams, HashMap engineHashMap ) throws JahiaException { jParams.getRequest().setAttribute("org.jahia.data.JahiaParams", jParams); renderCore( jParams, engineHashMap ); } // end render /*** * render * JahiaData render * EV 23.12.2000 * AK 04.01.2001 remove the fileName from method arguments * */ public void render( JahiaData jData, HashMap engineHashMap ) throws JahiaException { jData.params().getRequest().setAttribute("org.jahia.data.JahiaData", jData); renderCore( jData.params(), engineHashMap ); } // end render /*** * renderCore * called by ParamBean render, JahiaData render * EV 23.12.2000 * AK 04.01.2001 get the fileName from the engineHashMap and not from method arguments * AK 04.01.2001 get the render type from the engineHashMap (include or forward) * AK 04.01.2001 correct the jahiaChrono call consoleMsg * */ private void renderCore( ParamBean jParams, HashMap engineHashMap ) throws JahiaException { String fileName = null; try { // add default & common properties to the hashmap... engineHashMap.put("jahiaBuild", new Integer(jParams.settings().getBuildNumber())); engineHashMap.put("javaScriptPath", jParams.settings().getJsHttpPath()); engineHashMap.put("imagesPath", jParams.settings().getEnginesContext() + "engines/images/"); if ( engineHashMap.get("engineOutputFile") == null ) engineHashMap.put("engineOutputFile", ENGINE_JSP); if ( engineHashMap.get("engineUrl") == null ) engineHashMap.put("engineUrl",""); // set response attributes... jParams.getResponse().setContentType("text/html"); // add "no cache" to request header only if methode is not a get if (! jParams.getRequest().getMethod().toLowerCase().equals("get")){ jParams.getResponse().setHeader("Cache-Control", "No-Cache"); jParams.getResponse().setHeader("Pragma", "No-Cache"); jParams.getResponse().setDateHeader("Expires", 0); } boolean isIE = false; String userAgent = jParams.getRequest().getHeader( "user-agent" ); if (userAgent != null) { isIE = (userAgent.indexOf( "IE" ) != -1); } jParams.getRequest().setAttribute("isIE" , new Boolean(isIE)); jParams.getRequest().setAttribute("org.jahia.engines.EngineHashMap" , engineHashMap); jParams.getRequest().setAttribute("javaScriptPath" , jParams.settings().getJsHttpPath()); jParams.getRequest().setAttribute("URL" , getJahiaCoreHttpPath(jParams) + jParams.settings().getEnginesContext()); jParams.getRequest().setAttribute("engineURL" , getJahiaCoreHttpPath(jParams) + jParams.settings().getEnginesContext()); jParams.getRequest().setAttribute("serverURL" , getJahiaCoreHttpPath(jParams) ); jParams.getRequest().setAttribute("httpJsContextPath" , getJahiaCoreHttpPath(jParams) + jParams.settings().getJavascriptContext()); String jspSource = (String)engineHashMap.get("jspSource"); if ( jspSource == null ) jspSource = ""; jParams.getRequest().setAttribute("jspSource" , jspSource ); if ( jParams.getRequest().getAttribute("engineTitle")==null) jParams.getRequest().setAttribute("engineTitle" , "No title"); //jParams.getRequest().setAttribute("jParams" , jParams); // get the fileName from the engineHashMap... fileName = (String) engineHashMap.get("engineOutputFile"); // get the render type from the engineHashMap... (include or forward) Integer renderType = (Integer) engineHashMap.get("renderType"); JahiaConsole.println("EngineRenderer.renderCore", "Dispatching request to " + fileName + " using render type " + renderType + "..."); if(renderType.intValue() == JahiaEngine.RENDERTYPE_INCLUDE) { jParams.getContext().getRequestDispatcher( fileName ).include( jParams.getRequest(), jParams.getResponse() ); } else if(renderType.intValue() == JahiaEngine.RENDERTYPE_FORWARD) { jParams.getContext().getRequestDispatcher( fileName ).forward( jParams.getRequest(), jParams.getResponse() ); } } catch (IOException ie) { if (fileName == null) fileName = "undefined file"; String errorMsg = "Error while drawing the Engine " + fileName + " : " + ie.getMessage() + " -> BAILING OUT"; JahiaConsole.println( "Engine", errorMsg ); throw new JahiaException( "Error while drawing a Jahia engine's content", errorMsg, JahiaException.WINDOW_ERROR, JahiaException.CRITICAL, ie ); } catch (ServletException se) { if (fileName == null) fileName = "undefined file"; String errorMsg = "Error while forwarding the Engine " + fileName + " : " + se.getMessage() + " -> BAILING OUT"; JahiaConsole.println( "Engine", errorMsg ); if (se.getRootCause() != null) { se.getRootCause().printStackTrace(System.out); } throw new JahiaException( "Error while forwarding a Jahia engine's content", errorMsg, JahiaException.WINDOW_ERROR, JahiaException.CRITICAL, se ); } } // end renderCore //------------------------------------------------------------------------- /** * Build an http path containing the server name for the current site, * instead of the path from JahiaPrivateSettings. * * @return An http path leading to Jahia, built with the server name, and * the server port if nonstandard. * */ private final String getJahiaCoreHttpPath (ParamBean jParams) { return jParams.getRequest().getContextPath(); }/*********************************************************************************** ******** A PARTIR DE LA CES METHODES SONT DESTINEES A MOURIR.... ******** ***********************************************************************************/ /*** * render * EV 04.12.2000 * */ public void render( JahiaData jData, String sourceFileName, String formString ) throws JahiaException { String fileName = jData.params().settings().getJahiaEnginesDiskPath() + File.separator + sourceFileName + ".html"; String finalSource = decomposeSource( fileName, formString ); displaySource( finalSource, jData.params() ); } // end render /*** * render * EV 04.12.2000 * */ public void render( ParamBean jParams, String sourceFileName, String formString ) throws JahiaException { String fileName = jParams.settings().getJahiaEnginesDiskPath() + File.separator + sourceFileName + ".html"; String finalSource = decomposeSource( fileName, formString ); displaySource( finalSource, jParams ); } // end render /*** * decomposeSource * EV 04.12.2000 * */ private String decomposeSource( String fileName, String form ) throws JahiaException { String source = FileUtils.getInstance().readFile( fileName ); String firstPart = source.substring( 0, source.indexOf( FORM_TOKEN ) ); String secondPart = source.substring( source.indexOf(FORM_TOKEN) + FORM_TOKEN.length(), source.length() ); return firstPart + form + secondPart; } // end decomposeSource /*** * displaySource * EV 04.12.2000 * */ public void displaySource( String source, ParamBean jParams ) throws JahiaException { try { PrintWriter out = jParams.getResponse().getWriter(); jParams.getResponse().setContentType( "text/html" ); out.println( source ); } catch (IOException ie) { String errorMsg = "Error while drawing the Engine Window : " + ie.getMessage() + " -> BAILING OUT"; JahiaConsole.println( "Engine", errorMsg ); throw new JahiaException( "Error while drawing a Jahia window's content", errorMsg, JahiaException.WINDOW_ERROR, JahiaException.CRITICAL, ie ); } } // end displaySource/*********************************************************************************** ******** JUSQU'A LA CES METHODES SONT DESTINEES A MOURIR.... ******** ***********************************************************************************/} // end EngineRenderer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -