You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2015/10/20 20:12:50 UTC

svn commit: r1709655 - in /turbine/core/trunk/src: java/org/apache/turbine/modules/actions/ java/org/apache/turbine/modules/navigations/ java/org/apache/turbine/modules/screens/ test/org/apache/turbine/modules/actions/ test/org/apache/turbine/services/...

Author: tv
Date: Tue Oct 20 18:12:50 2015
New Revision: 1709655

URL: http://svn.apache.org/viewvc?rev=1709655&view=rev
Log:
Add basic support for Turbine 2 legacy modules

Added:
    turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocityAction.java   (with props)
    turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocitySecureAction.java   (with props)
    turbine/core/trunk/src/java/org/apache/turbine/modules/navigations/LegacyVelocityNavigation.java   (with props)
    turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocityScreen.java   (with props)
    turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocitySecureScreen.java   (with props)
    turbine/core/trunk/src/test/org/apache/turbine/modules/actions/Turbine2LegacyAction.java   (with props)
Modified:
    turbine/core/trunk/src/java/org/apache/turbine/modules/actions/VelocitySecureAction.java
    turbine/core/trunk/src/test/org/apache/turbine/services/intake/LoginForm.java

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocityAction.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocityAction.java?rev=1709655&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocityAction.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocityAction.java Tue Oct 20 18:12:50 2015
@@ -0,0 +1,86 @@
+package org.apache.turbine.modules.actions;
+
+/*
+ * 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.fulcrum.parser.ParameterParser;
+import org.apache.turbine.Turbine;
+import org.apache.turbine.pipeline.PipelineData;
+import org.apache.turbine.services.velocity.TurbineVelocity;
+import org.apache.turbine.util.RunData;
+import org.apache.velocity.context.Context;
+
+/**
+ * This class provides a methods for Turbine2 Velocity Actions to use. Since
+ * this class is abstract, it should only be extended and not used directly.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @deprecated Use VelocityAction directly
+ */
+@Deprecated
+public abstract class LegacyVelocityAction extends VelocityAction
+{
+    /**
+     * You SHOULD override this method and implement it in your action.
+     *
+     * @param data Turbine information.
+     * @param context Context for web pages.
+     * @throws Exception a generic exception.
+     */
+    public abstract void doPerform(RunData data, Context context)
+            throws Exception;
+
+    /**
+     * Adapter method for legacy signature
+     *
+     * @param pipelineData Turbine information.
+     * @param context Context for web pages.
+     * @throws Exception a generic exception.
+     */
+    @Override
+    public void doPerform(PipelineData pipelineData, Context context)
+            throws Exception
+    {
+        doPerform(getRunData(pipelineData), context);
+    }
+
+    /**
+     * This overrides the default Action.doPerform() to execute the
+     * doEvent() method.  If that fails, then it will execute the
+     * doPerform() method instead.
+     *
+     * @param pipelineData A Turbine RunData object.
+     * @exception Exception a generic exception.
+     */
+    @Override
+    public void doPerform(PipelineData pipelineData)
+            throws Exception
+    {
+        if (!initialized)
+        {
+            initialize();
+        }
+
+        RunData data = getRunData(pipelineData);
+        ParameterParser pp = pipelineData.get(Turbine.class, ParameterParser.class);
+        Context context = TurbineVelocity.getContext(pipelineData);
+        executeEvents(pp, new Class<?>[]{ RunData.class, Context.class },
+                new Object[]{ data, context });
+    }
+}

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocityAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocitySecureAction.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocitySecureAction.java?rev=1709655&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocitySecureAction.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocitySecureAction.java Tue Oct 20 18:12:50 2015
@@ -0,0 +1,69 @@
+package org.apache.turbine.modules.actions;
+
+/*
+ * 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.turbine.pipeline.PipelineData;
+import org.apache.turbine.util.RunData;
+
+/**
+ * VelocitySecure action.
+ *
+ * Always performs a Security Check that you've defined before
+ * executing the doPerform().  You should extend this class and
+ * add the specific security check needed.  If you have a number of
+ * actions that need to perform the same check, you could make a base
+ * action by extending this class and implementing the isAuthorized().
+ * Then each action that needs to perform the same check could extend
+ * your base action.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @deprecated Use VelocitySecureAction directly
+ */
+@Deprecated
+public abstract class LegacyVelocitySecureAction extends LegacyVelocityAction
+{
+    /**
+     * This method overrides the method in VelocityAction to
+     * perform a security check first.
+     *
+     * @param pipelineData Turbine information.
+     * @throws Exception a generic exception.
+     */
+    @Override
+    protected void perform(PipelineData pipelineData) throws Exception
+    {
+        if (isAuthorized(getRunData(pipelineData)))
+        {
+            super.perform(pipelineData);
+        }
+    }
+
+    /**
+     * Implement this method to perform the security check needed.
+     * You should set the template in this method that you want the
+     * user to be sent to if they're unauthorized.
+     *
+     * @param data Turbine information.
+     * @return True if the user is authorized to access the screen.
+     * @throws Exception a generic exception.
+     */
+    protected abstract boolean isAuthorized(RunData data) throws Exception;
+}

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/actions/LegacyVelocitySecureAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: turbine/core/trunk/src/java/org/apache/turbine/modules/actions/VelocitySecureAction.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/actions/VelocitySecureAction.java?rev=1709655&r1=1709654&r2=1709655&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/actions/VelocitySecureAction.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/actions/VelocitySecureAction.java Tue Oct 20 18:12:50 2015
@@ -26,10 +26,10 @@ import org.apache.turbine.pipeline.Pipel
  * VelocitySecure action.
  *
  * Always performs a Security Check that you've defined before
- * executing the doBuildtemplate().  You should extend this class and
+ * executing the doPerform().  You should extend this class and
  * add the specific security check needed.  If you have a number of
- * screens that need to perform the same check, you could make a base
- * screen by extending this class and implementing the isAuthorized().
+ * actions that need to perform the same check, you could make a base
+ * action by extending this class and implementing the isAuthorized().
  * Then each action that needs to perform the same check could extend
  * your base action.
  *

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/navigations/LegacyVelocityNavigation.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/navigations/LegacyVelocityNavigation.java?rev=1709655&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/navigations/LegacyVelocityNavigation.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/navigations/LegacyVelocityNavigation.java Tue Oct 20 18:12:50 2015
@@ -0,0 +1,61 @@
+package org.apache.turbine.modules.navigations;
+
+
+/*
+ * 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.turbine.pipeline.PipelineData;
+import org.apache.turbine.util.RunData;
+import org.apache.velocity.context.Context;
+
+/**
+ * Support Turbine 2 navigation modules
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @deprecated Use VelocityNavigation directly
+ */
+@Deprecated
+public class LegacyVelocityNavigation
+        extends VelocityNavigation
+{
+    /**
+     * Velocity Navigations extending this class should override this
+     * method to perform any particular business logic and add
+     * information to the context.
+     *
+     * @param data Turbine information.
+     * @param context Context for web pages.
+     * @exception Exception, a generic exception.
+     */
+    protected void doBuildTemplate(RunData data, Context context)
+            throws Exception
+    {
+        // empty
+    }
+
+    /**
+     * Adapter method
+     */
+    @Override
+    protected void doBuildTemplate(PipelineData pipelineData, Context context) throws Exception
+    {
+        doBuildTemplate(getRunData(pipelineData), context);
+    }
+}

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/navigations/LegacyVelocityNavigation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocityScreen.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocityScreen.java?rev=1709655&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocityScreen.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocityScreen.java Tue Oct 20 18:12:50 2015
@@ -0,0 +1,65 @@
+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.turbine.pipeline.PipelineData;
+import org.apache.turbine.util.RunData;
+import org.apache.velocity.context.Context;
+
+/**
+ * Support Turbine 2 screens
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @deprecated Use VelocityScreen directly
+ */
+@Deprecated
+public class LegacyVelocityScreen
+    extends VelocityScreen
+{
+    /**
+     * Velocity Screens extending this class should override this
+     * method to perform any particular business logic and add
+     * information to the context.
+     *
+     * @param data Turbine information.
+     * @param context Context for web pages.
+     * @exception Exception, a generic exception.
+     */
+    protected void doBuildTemplate(RunData data, Context context)
+            throws Exception
+    {
+        // empty
+    }
+
+    /**
+     * Adapter method
+     *
+     * @param pipelineData Turbine information.
+     * @param context Context for web pages.
+     * @exception Exception, a generic exception.
+     */
+    @Override
+    protected void doBuildTemplate(PipelineData pipelineData,
+                                   Context context)
+            throws Exception
+    {
+        doBuildTemplate(getRunData(pipelineData), context);
+    }
+}

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocityScreen.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocitySecureScreen.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocitySecureScreen.java?rev=1709655&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocitySecureScreen.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocitySecureScreen.java Tue Oct 20 18:12:50 2015
@@ -0,0 +1,78 @@
+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.turbine.pipeline.PipelineData;
+import org.apache.turbine.services.velocity.TurbineVelocity;
+import org.apache.turbine.util.RunData;
+import org.apache.velocity.context.Context;
+
+/**
+ * Support Turbine 2 screens
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @deprecated Use VelocitySecureScreen directly
+ */
+@Deprecated
+public abstract class LegacyVelocitySecureScreen
+        extends LegacyVelocityScreen
+{
+    /**
+     * Implement this to add information to the context.
+     *
+     * @param data Turbine information.
+     * @param context Context for web pages.
+     * @exception Exception, a generic exception.
+     */
+    @Override
+    protected abstract void doBuildTemplate(RunData data, Context context)
+            throws Exception;
+
+    /**
+     * This method overrides the method in VelocityScreen to
+     * perform a security check first.
+     *
+     * @param pipelineData Turbine information.
+     * @exception Exception, a generic exception.
+     */
+    @Override
+    protected void doBuildTemplate(PipelineData pipelineData)
+        throws Exception
+    {
+        if (isAuthorized(getRunData(pipelineData)))
+        {
+            doBuildTemplate(getRunData(pipelineData), TurbineVelocity.getContext(pipelineData));
+        }
+    }
+
+    /**
+     * Implement this method to perform the security check needed.
+     * You should set the template in this method that you want the
+     * user to be sent to if they're unauthorized.  See the
+     * VelocitySecurityCheck utility.
+     *
+     * @param data Turbine information.
+     * @return True if the user is authorized to access the screen.
+     * @exception Exception, a generic exception.
+     */
+    protected abstract boolean isAuthorized(RunData data)
+            throws Exception;
+}

Propchange: turbine/core/trunk/src/java/org/apache/turbine/modules/screens/LegacyVelocitySecureScreen.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: turbine/core/trunk/src/test/org/apache/turbine/modules/actions/Turbine2LegacyAction.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/modules/actions/Turbine2LegacyAction.java?rev=1709655&view=auto
==============================================================================
--- turbine/core/trunk/src/test/org/apache/turbine/modules/actions/Turbine2LegacyAction.java (added)
+++ turbine/core/trunk/src/test/org/apache/turbine/modules/actions/Turbine2LegacyAction.java Tue Oct 20 18:12:50 2015
@@ -0,0 +1,53 @@
+package org.apache.turbine.modules.actions;
+
+/*
+ * 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 static org.junit.Assert.assertNotNull;
+
+import org.apache.turbine.util.RunData;
+import org.apache.velocity.context.Context;
+
+/**
+ * This action is used for testing the Turbine 2 Legacy method signatures.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ */
+@SuppressWarnings("deprecation")
+public class Turbine2LegacyAction extends LegacyVelocityAction
+{
+    public static int numberOfCalls;
+
+    /**
+     *  Default action is throw an exception.
+     *
+     * @param  data           Current RunData information
+     * @param  context        Context to populate
+     * @exception  Exception  Thrown on error
+     */
+    @Override
+    public void doPerform(RunData data, Context context) throws Exception
+    {
+        log.debug("Calling doPerform(RunData)");
+		Turbine2LegacyAction.numberOfCalls++;
+		assertNotNull("RunData object was Null.", data);
+    }
+
+}

Propchange: turbine/core/trunk/src/test/org/apache/turbine/modules/actions/Turbine2LegacyAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: turbine/core/trunk/src/test/org/apache/turbine/services/intake/LoginForm.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/services/intake/LoginForm.java?rev=1709655&r1=1709654&r2=1709655&view=diff
==============================================================================
--- turbine/core/trunk/src/test/org/apache/turbine/services/intake/LoginForm.java (original)
+++ turbine/core/trunk/src/test/org/apache/turbine/services/intake/LoginForm.java Tue Oct 20 18:12:50 2015
@@ -27,10 +27,10 @@ package org.apache.turbine.services.inta
  */
 public class LoginForm
 {
-
     private String username;
+
     /**
-     * @return
+     * @return the user name
      */
     public String getUsername()
     {
@@ -38,7 +38,7 @@ public class LoginForm
     }
 
     /**
-     * @param username
+     * @param username the user name to set
      */
     public void setUsername(String username)
     {