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 2012/12/07 15:34:21 UTC

svn commit: r1418330 - in /turbine/core/trunk/proposals/gk: ./ CacheModules/ CacheModules/org/ CacheModules/org/apache/ CacheModules/org/apache/turbine/ CacheModules/org/apache/turbine/modules/ CacheModules/org/apache/turbine/modules/layouts/ CacheModu...

Author: gk
Date: Fri Dec  7 14:34:19 2012
New Revision: 1418330

URL: http://svn.apache.org/viewvc?rev=1418330&view=rev
Log:
add renamed cache screen and layout module (proposal)

Added:
    turbine/core/trunk/proposals/gk/
    turbine/core/trunk/proposals/gk/CacheModules/
    turbine/core/trunk/proposals/gk/CacheModules/org/
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/VelocityCachedLayout.java   (with props)
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/screens/
    turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/screens/VelocityCachedScreen.java   (with props)
    turbine/core/trunk/proposals/gk/CacheModules/readme.txt   (with props)

Added: turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/VelocityCachedLayout.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/VelocityCachedLayout.java?rev=1418330&view=auto
==============================================================================
--- turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/VelocityCachedLayout.java (added)
+++ turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/VelocityCachedLayout.java Fri Dec  7 14:34:19 2012
@@ -0,0 +1,121 @@
+package org.apache.jetspeed.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 allows Velocity templates
+ * to be used as layouts. Was pre-Turbine 2.3.3 VelocityDirectLayout, now with method added for {@link PipelineData}.
+ */
+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/proposals/gk/CacheModules/org/apache/turbine/modules/layouts/VelocityCachedLayout.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/screens/VelocityCachedScreen.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/screens/VelocityCachedScreen.java?rev=1418330&view=auto
==============================================================================
--- turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/screens/VelocityCachedScreen.java (added)
+++ turbine/core/trunk/proposals/gk/CacheModules/org/apache/turbine/modules/screens/VelocityCachedScreen.java Fri Dec  7 14:34:19 2012
@@ -0,0 +1,147 @@
+package org.apache.jetspeed.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 was pre-Turbine 2.3.3 VelocityDirectScreen, now with method added for {@link PipelineData}.
+ * 
+ * <p>
+ */
+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/proposals/gk/CacheModules/org/apache/turbine/modules/screens/VelocityCachedScreen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: turbine/core/trunk/proposals/gk/CacheModules/readme.txt
URL: http://svn.apache.org/viewvc/turbine/core/trunk/proposals/gk/CacheModules/readme.txt?rev=1418330&view=auto
==============================================================================
--- turbine/core/trunk/proposals/gk/CacheModules/readme.txt (added)
+++ turbine/core/trunk/proposals/gk/CacheModules/readme.txt Fri Dec  7 14:34:19 2012
@@ -0,0 +1,3 @@
+Reintroduce the renamed velocity cached layout and screen modules (named VelocityDirectScreen, VelocityDirectLayout in Turbine 2.3.3).
+
+This is used in Jetspeed 1.6 framework and makes live there easier again.
\ No newline at end of file

Propchange: turbine/core/trunk/proposals/gk/CacheModules/readme.txt
------------------------------------------------------------------------------
    svn:eol-style = native