1 package org.apache.turbine.pipeline; 2 3 56 57 import javax.servlet.RequestDispatcher ; 58 59 import org.apache.commons.lang.exception.ExceptionUtils; 60 import org.apache.commons.logging.Log; 61 import org.apache.commons.logging.LogFactory; 62 import org.apache.turbine.RunData; 63 import org.apache.turbine.TurbineException; 64 65 71 public class JspRenderer 72 { 73 private static final Log log = LogFactory.getLog(JspRenderer.class); 74 75 76 private String [] templatePaths; 77 78 79 private String [] relativeTemplatePaths; 80 81 82 private int bufferSize; 83 84 87 protected RunData data = null; 88 89 92 public JspRenderer(RunData data) 93 { 94 this.data = data; 95 } 96 97 101 public int getDefaultBufferSize() 102 { 103 return bufferSize; 104 } 105 106 114 public void render(String jsp) 115 throws TurbineException 116 { 117 render(jsp, false); 118 } 119 120 129 public void render(String jsp, boolean isForward) 130 throws TurbineException 131 { 132 String jspPath = "/templates/jsp/" + jsp; 134 135 log.debug("Jsp to render: " + jspPath); 136 137 if (jspPath == null) 138 { 139 throw new TurbineException( 140 "JSP " + jsp + " not found in specified paths"); 141 } 142 143 RequestDispatcher dispatcher = data.getServletContext() 145 .getRequestDispatcher(jspPath); 146 147 data.getResponse().setBufferSize(8192); 148 data.getResponse().setContentType("text/html"); 149 150 try 151 { 152 if (isForward) 153 { 154 dispatcher.forward( data.getRequest(), data.getResponse() ); 156 } 157 else 158 { 159 data.getOut().flush(); 160 dispatcher.include( data.getRequest(), data.getResponse() ); 162 } 163 } 164 catch(Exception e) 165 { 166 log.error(ExceptionUtils.getStackTrace(e)); 167 } 168 } 169 } 170 | Popular Tags |