You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by gk...@apache.org on 2013/02/01 16:43:44 UTC

svn commit: r1441493 - in /turbine/core/trunk: proposals/gk/ src/changes/changes.xml src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java

Author: gk
Date: Fri Feb  1 15:43:44 2013
New Revision: 1441493

URL: http://svn.apache.org/viewvc?rev=1441493&view=rev
Log:
moved classes from proposals/gk to turbine trunk

Added:
    turbine/core/trunk/src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java   (with props)
    turbine/core/trunk/src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java   (with props)
Removed:
    turbine/core/trunk/proposals/gk/
Modified:
    turbine/core/trunk/src/changes/changes.xml

Modified: turbine/core/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/changes/changes.xml?rev=1441493&r1=1441492&r2=1441493&view=diff
==============================================================================
--- turbine/core/trunk/src/changes/changes.xml (original)
+++ turbine/core/trunk/src/changes/changes.xml Fri Feb  1 15:43:44 2013
@@ -25,6 +25,9 @@
 
   <body>
     <release version="4.0-M2" date="in Subversion">
+     <action type="update" dev="gk">
+        Reintroduce VelocityCachedLayout/Screen classes 
+      </action>
       <action type="update" dev="tv">
         Adjust site for Apache Turbine Parent POM version 2
       </action>

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java?rev=1441493&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java Fri Feb  1 15:43:44 2013
@@ -0,0 +1,127 @@
+package org.apache.turbine.modules.layouts;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.turbine.TurbineConstants;
+import org.apache.turbine.modules.Layout;
+import org.apache.turbine.pipeline.PipelineData;
+import org.apache.turbine.services.velocity.TurbineVelocity;
+import org.apache.turbine.util.RunData;
+import org.apache.turbine.util.template.TemplateNavigation;
+import org.apache.turbine.util.template.TemplateScreen;
+import org.apache.velocity.context.Context;
+
+/**
+ * This Layout module is Turbine 2.3.3 VelocityDirectLayout (same package) 
+ * with methods added for {@link PipelineData}. It is used in Jetspeed-1 portal.
+ *
+ * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
+ * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
+ * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @version $Id$
+ */
+public class VelocityCachedLayout
+    extends Layout
+{
+    /** Logging */
+    private static Log log = LogFactory.getLog(VelocityCachedLayout.class);
+
+    /** The prefix for lookup up layout pages */
+    private String prefix = getPrefix() + "/";
+
+    /**
+     * Method called by LayoutLoader.
+     *
+     * @param data Turbine information.
+     * @exception Exception a generic exception.
+     */
+    public void doBuild(RunData data)
+        throws Exception
+    {
+        // Get the context needed by Velocity.
+        Context context = TurbineVelocity.getContext(data);
+
+        // variable for the screen in the layout template
+        context.put(TurbineConstants.SCREEN_PLACEHOLDER,
+                    new TemplateScreen(data));
+
+        // variable to reference the navigation screen in the layout template
+        context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
+                    new TemplateNavigation(data));
+
+        // Grab the layout template set in the VelocityPage.
+        // If null, then use the default layout template
+        // (done by the TemplateInfo object)
+        String templateName = data.getTemplateInfo().getLayoutTemplate();
+
+        // Set the locale and content type
+        data.getResponse().setLocale(data.getLocale());
+        data.getResponse().setContentType(data.getContentType());
+
+        log.debug("Now trying to render layout " + templateName);
+
+        // Finally, generate the layout template and send it to the browser
+        TurbineVelocity.handleRequest(context,
+                prefix + templateName, data.getOut());
+    }
+    
+    /**
+     * Method called by LayoutLoader.
+     *
+     *
+     * @param data PipelineData
+     * @throws Exception generic exception
+     */
+    @Override
+    public void doBuild(PipelineData pipelineData)
+        throws Exception
+    {
+        RunData data = getRunData(pipelineData);
+        // Get the context needed by Velocity.
+        Context context = TurbineVelocity.getContext(pipelineData);
+
+        // variable for the screen in the layout template
+        context.put(TurbineConstants.SCREEN_PLACEHOLDER,
+                    new TemplateScreen(data));
+
+        // variable to reference the navigation screen in the layout template
+        context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
+                    new TemplateNavigation(data));
+
+        // Grab the layout template set in the VelocityPage.
+        // If null, then use the default layout template
+        // (done by the TemplateInfo object)
+        String templateName = data.getTemplateInfo().getLayoutTemplate();
+
+        // Set the locale and content type
+        data.getResponse().setLocale(data.getLocale());
+        data.getResponse().setContentType(data.getContentType());
+
+        log.debug("Now trying to render layout " + templateName);
+
+        // Finally, generate the layout template and send it to the browser
+        TurbineVelocity.handleRequest(context,
+                prefix + templateName, data.getOut());
+    }
+}
+

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/layouts/VelocityCachedLayout.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java?rev=1441493&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java Fri Feb  1 15:43:44 2013
@@ -0,0 +1,152 @@
+package org.apache.turbine.modules.screens;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.ecs.ConcreteElement;
+import org.apache.turbine.Turbine;
+import org.apache.turbine.TurbineConstants;
+import org.apache.turbine.modules.screens.VelocityScreen;
+import org.apache.turbine.pipeline.PipelineData;
+import org.apache.turbine.services.template.TurbineTemplate;
+import org.apache.turbine.services.velocity.TurbineVelocity;
+import org.apache.turbine.util.RunData;
+import org.apache.velocity.context.Context;
+
+/**
+ * VelocityCachedScreen is Turbine 2.3.3 VelocityDirectScreen (same package) 
+ * with methods added for {@link PipelineData}.
+ * It is is a screen class which buffers its output
+ * before flushing the output stream. It is used in Jetspeed-1 portal.
+ * <p>
+ * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @version $Id$
+ */
+public class VelocityCachedScreen
+    extends VelocityScreen
+{
+    /** The prefix for lookup up screen pages */
+    private String prefix = getPrefix() + "/";
+
+    /**
+     * This builds the Velocity template.
+     *
+     * @param data Turbine information.
+     * @return A ConcreteElement.
+     * @exception Exception, a generic exception.
+     */
+    public ConcreteElement buildTemplate(RunData data)
+        throws Exception
+    {
+        Context context = TurbineVelocity.getContext(data);
+
+        String screenTemplate = data.getTemplateInfo().getScreenTemplate();
+        String templateName
+            = TurbineTemplate.getScreenTemplateName(screenTemplate);
+
+        // The Template Service could not find the Screen
+        if (StringUtils.isEmpty(templateName))
+        {
+            log.error("Screen " + screenTemplate + " not found!");
+            throw new Exception("Could not find screen for " + screenTemplate);
+        }
+
+        try
+        {
+            TurbineVelocity.handleRequest(context,
+                                          prefix + templateName,
+                                          data.getOut());
+
+        }
+        catch (Exception e)
+        {
+            // If there is an error, build a $processingException and
+            // attempt to call the error.vm template in the screens
+            // directory.
+            context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
+            context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
+
+            templateName = Turbine.getConfiguration()
+                .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
+                           TurbineConstants.TEMPLATE_ERROR_VM);
+
+            TurbineVelocity.handleRequest(context,
+                    prefix + templateName,
+                    data.getOut());
+        }
+
+        return null;
+    }
+    
+    /**
+     * This builds the Velocity template.
+     *
+     * @param data Turbine information.
+     * @return A ConcreteElement.
+     * @exception Exception, a generic exception.
+     */
+    public ConcreteElement buildTemplate(PipelineData pipelineData)
+        throws Exception
+    {
+        RunData data = getRunData(pipelineData);
+        Context context = TurbineVelocity.getContext(pipelineData);
+
+        String screenTemplate = data.getTemplateInfo().getScreenTemplate();
+        String templateName
+            = TurbineTemplate.getScreenTemplateName(screenTemplate);
+
+        // The Template Service could not find the Screen
+        if (StringUtils.isEmpty(templateName))
+        {
+            log.error("Screen " + screenTemplate + " not found!");
+            throw new Exception("Could not find screen for " + screenTemplate);
+        }
+
+        try
+        {
+            TurbineVelocity.handleRequest(context,
+                                          prefix + templateName,
+                                          data.getOut());
+
+        }
+        catch (Exception e)
+        {
+            // If there is an error, build a $processingException and
+            // attempt to call the error.vm template in the screens
+            // directory.
+            context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
+            context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
+
+            templateName = Turbine.getConfiguration()
+                .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
+                           TurbineConstants.TEMPLATE_ERROR_VM);
+
+            TurbineVelocity.handleRequest(context,
+                    prefix + templateName,
+                    data.getOut());
+        }
+
+        return null;
+    }
+}
+
+

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/screens/VelocityCachedScreen.java
------------------------------------------------------------------------------
    svn:eol-style = native