jvanzyl 02/01/22 05:50:46
Added: src/java/org/apache/turbine/pipeline JspRenderer.java
JspRendererValve.java
Log:
- adding a JspRenderer and JspRendererValve to show how two entirely
separate view mechanism can be used at the same time. i will add
the logic to process many pipelines later this week.
Revision Changes Path
1.1
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/JspRenderer.java
Index: JspRenderer.java
===================================================================
package org.apache.turbine.pipeline;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import org.apache.turbine.Log;
import org.apache.turbine.RunData;
import org.apache.turbine.Turbine;
import org.apache.turbine.TurbineException;
import org.apache.log4j.Category;
import org.apache.commons.util.StringUtils;
/**
* Valve to call the JspRenderer.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id: JspRenderer.java,v 1.1 2002/01/22 13:50:46 jvanzyl Exp $
*/
public class JspRenderer
{
/** The base path[s] prepended to filenames given in arguments */
private String[] templatePaths;
/** The relative path[s] prepended to filenames */
private String[] relativeTemplatePaths;
/** The buffer size for the output stream. */
private int bufferSize;
private static final Category log =
Category.getInstance(JspRenderer.class);
/**
* RunData of the request this Renderer is for.
*/
protected RunData data = null;
/**
* Construct a renderer for the given RunData.
*/
public JspRenderer(RunData data)
{
this.data = data;
}
/**
* The buffer size
*
*/
public int getDefaultBufferSize()
{
return bufferSize;
}
/**
* Process the request
*
* @param RunData
* @param String the filename of the template.
* @throws TurbineException Any exception trown while processing will be
* wrapped into a TurbineException and rethrown.
*/
public void render(String jsp)
throws TurbineException
{
render(jsp, false);
}
/**
* Process the request
*
* @param RunData
* @param String the filename of the template.
* @param boolean whether to perform a forward or include.
* @throws TurbineException Any exception trown while processing will be
* wrapped into a TurbineException and rethrown.
*/
public void render(String jsp, boolean isForward)
throws TurbineException
{
// This obviously can be improved.
String jspPath = "/templates/jsp/" + jsp;
log.debug("Jsp to render: " + jspPath);
if (jspPath == null)
{
throw new TurbineException(
"JSP " + jsp + " not found in specified paths");
}
// get the RequestDispatcher for the JSP
RequestDispatcher dispatcher = data.getServletContext()
.getRequestDispatcher(jspPath);
data.getResponse().setBufferSize(8192);
data.getResponse().setContentType("text/html");
try
{
if (isForward)
{
// forward the request to the JSP
dispatcher.forward( data.getRequest(), data.getResponse() );
}
else
{
data.getOut().flush();
// include the JSP
dispatcher.include( data.getRequest(), data.getResponse() );
}
}
catch(Exception e)
{
log.error(StringUtils.stackTrace(e));
}
}
}
1.1
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/JspRendererValve.java
Index: JspRendererValve.java
===================================================================
package org.apache.turbine.pipeline;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.IOException;
import java.util.Enumeration;
import org.apache.turbine.Turbine;
import org.apache.turbine.RunData;
import org.apache.turbine.TurbineException;
import org.apache.turbine.Valve;
import org.apache.turbine.ValveContext;
import org.apache.log4j.Category;
/**
* Valve that delegates to JspRenderer to produce a view
* based on JSP.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id: JspRendererValve.java,v 1.1 2002/01/22 13:50:46 jvanzyl Exp $
*/
public class JspRendererValve
implements Valve
{
private static final Category log =
Category.getInstance(JspRendererValve.class);
/**
* @see org.apache.turbine.Valve#invoke(RunData, ValveContext)
*/
public void invoke(RunData data, ValveContext context)
throws IOException, TurbineException
{
try
{
String jsp = data.getTarget();
render(data,jsp);
}
catch (Exception e)
{
throw new TurbineException(e);
}
// Pass control to the next Valve in the Pipeline
context.invokeNext(data);
}
protected void render(RunData data, String jsp)
throws Exception
{
if (log.isDebugEnabled())
{
log.debug("Rendering target " + jsp);
}
JspRenderer r = new JspRenderer(data);
r.render(jsp,true);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>