taylor 2004/10/24 12:32:47
Modified: portals-bridges/velocity project.xml
Added: portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity
BridgesVelocityViewServlet.java
Removed: portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity
JetspeedVelocityViewServlet.java
Log:
- renamed JetspeedVelocityViewServlet to something non-jetspeed specific
- completely decoupling from Jetspeed and Pluto dependencies
Revision Changes Path
1.1
jakarta-jetspeed-2/portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity/BridgesVelocityViewServlet.java
Index: BridgesVelocityViewServlet.java
===================================================================
/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.portals.bridges.velocity;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletRequest;
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.io.VelocityWriter;
import org.apache.velocity.tools.view.servlet.VelocityViewServlet;
import org.apache.velocity.util.SimplePool;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
* @version $Id: BridgesVelocityViewServlet.java,v 1.1 2004/10/24 19:32:46 taylor
Exp $
*/
public class BridgesVelocityViewServlet extends VelocityViewServlet
{
public final static String PORTLET_REQUEST = "javax.portlet.request";
public final static String PORTLET_RESPONSE = "javax.portlet.response";
public final static String PORTLET_CONFIG = "javax.portlet.config";
public static final String VELOCITY_WRITER_ATTR =
"org.apache.velocity.io.VelocityWriter";
/** Cache of writers */
private static SimplePool writerPool = new SimplePool(40);
public static final String VELOCITY_CONTEXT_ATTR = "org.apache.velocity.Context";
/**
* Adds the RenderRequest, RenderResponse and PortletConfig to the context
*
* @see
org.apache.velocity.tools.view.servlet.VelocityViewServlet#handleRequest(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, org.apache.velocity.context.Context)
*/
protected Template handleRequest(HttpServletRequest request, HttpServletResponse
response, Context ctx) throws Exception
{
PortletRequest renderRequest = (PortletRequest)
request.getAttribute(PORTLET_REQUEST);
RenderResponse renderResponse = (RenderResponse)
request.getAttribute(PORTLET_RESPONSE);
PortletConfig portletConfig = (PortletConfig)
request.getAttribute(PORTLET_CONFIG);
if (renderRequest != null)
{
renderRequest.setAttribute(VELOCITY_CONTEXT_ATTR, ctx);
}
// standard render request and response also available in context
ctx.put(PORTLET_REQUEST, renderRequest);
ctx.put(PORTLET_RESPONSE, renderResponse);
return super.handleRequest(request, response, ctx);
}
/**
* @see
org.apache.velocity.tools.view.servlet.VelocityViewServlet#mergeTemplate(org.apache.velocity.Template,
org.apache.velocity.context.Context, javax.servlet.http.HttpServletResponse)
*/
protected void mergeTemplate(Template template, Context context,
HttpServletResponse response)
throws
ResourceNotFoundException,
ParseErrorException,
MethodInvocationException,
IOException,
UnsupportedEncodingException,
Exception
{
PrintWriter pw = response.getWriter();
VelocityWriter vw = null;
try
{
vw = (VelocityWriter) writerPool.get();
if (vw == null)
{
vw = new VelocityWriter(pw, 4 * 1024, true);
}
else
{
vw.recycle(pw);
}
// Place the VelocityWriter into the Context
context.put(VELOCITY_WRITER_ATTR, vw);
template.merge(context, vw);
}
catch (Exception e)
{
throw e;
}
finally
{
try
{
if (vw != null)
{
// flush and put back into the pool
// don't close to allow us to play
// nicely with others.
vw.flush();
/* This hack sets the VelocityWriter's internal ref to the
* PrintWriter to null to keep memory free while
* the writer is pooled. See bug report #18951 */
vw.recycle(null);
writerPool.put(vw);
}
}
catch (Exception e)
{
// do nothing
}
}
}
}
1.2 +1 -22 jakarta-jetspeed-2/portals-bridges/velocity/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/velocity/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 22 Oct 2004 22:43:33 -0000 1.1
+++ project.xml 24 Oct 2004 19:32:46 -0000 1.2
@@ -33,11 +33,6 @@
<url>http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/portals-bridges/velocity/</url>
</repository>
<dependencies>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.3</version>
- </dependency>
<dependency>
<groupId>portlet-api</groupId>
<artifactId>portlet-api</artifactId>
@@ -57,22 +52,6 @@
<version>1.1-beta1</version>
<url>http://jakarta.apache.org/velocity</url>
</dependency>
-
- <dependency>
- <id>jetspeed2:jetspeed-api</id>
- <version>2.0-a1-dev</version>
- <properties>
- <war.bundle>false</war.bundle>
- </properties>
- </dependency>
- <dependency>
- <id>pluto</id>
- <groupId>pluto</groupId>
- <version>1.0.1-rc1</version>
- <properties>
- <war.bundle>false</war.bundle>
- </properties>
- </dependency>
<dependency>
<groupId>portals-bridges</groupId>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]