You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ap...@apache.org on 2007/02/12 12:22:18 UTC

svn commit: r506417 - in /struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2: ActionPreparer.java TilesPlugin.java preparer/ActionPreparer.java preparer/StrutsPreparerFactory.java preparer/UrlPreparer.java

Author: apetrelli
Date: Mon Feb 12 03:22:17 2007
New Revision: 506417

URL: http://svn.apache.org/viewvc?view=rev&rev=506417
Log:
Modified the configuration of the PreparerFactory, so that it can load URLs and actions as preparers.

Added:
    struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java   (contents, props changed)
      - copied, changed from r506396, struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/ActionPreparer.java
    struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java   (with props)
    struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java   (with props)
Removed:
    struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/ActionPreparer.java
Modified:
    struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/TilesPlugin.java   (contents, props changed)

Modified: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/TilesPlugin.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/TilesPlugin.java?view=diff&rev=506417&r1=506416&r2=506417
==============================================================================
--- struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/TilesPlugin.java (original)
+++ struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/TilesPlugin.java Mon Feb 12 03:22:17 2007
@@ -36,6 +36,7 @@
 import org.apache.struts.config.ControllerConfig;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.config.PlugInConfig;
+import org.apache.struts.tiles2.preparer.StrutsPreparerFactory;
 import org.apache.struts.tiles2.util.PlugInConfigContextAdapter;
 import org.apache.struts.util.ModuleUtils;
 import org.apache.struts.util.RequestUtils;
@@ -52,7 +53,6 @@
 import org.apache.tiles.impl.BasicTilesContainer;
 import org.apache.tiles.impl.KeyedDefinitionsFactoryTilesContainer;
 import org.apache.tiles.impl.KeyedDefinitionsFactoryTilesContainer.KeyExtractor;
-import org.apache.tiles.preparer.BasicPreparerFactory;
 
 /**
  * Tiles Plugin used to initialize Tiles.
@@ -85,23 +85,28 @@
     private static final Map<String, String> MODULE_AWARE_DEFAULTS =
         new HashMap<String, String>();
 
+    private static final Map<String, String> NO_MODULE_DEFAULTS =
+        new HashMap<String, String>();
+
     static {
-        MODULE_AWARE_DEFAULTS.put(TilesContainerFactory
-                .CONTAINER_FACTORY_INIT_PARAM,
-                KeyedDefinitionsFactoryTilesContainerFactory.class.getName());
-        MODULE_AWARE_DEFAULTS.put(TilesContainerFactory
+        NO_MODULE_DEFAULTS.put(TilesContainerFactory
                 .CONTEXT_FACTORY_INIT_PARAM,
                 BasicTilesContextFactory.class.getName());
-        MODULE_AWARE_DEFAULTS.put(TilesContainerFactory
+        NO_MODULE_DEFAULTS.put(TilesContainerFactory
                 .DEFINITIONS_FACTORY_INIT_PARAM,
                 UrlDefinitionsFactory.class.getName());
-        MODULE_AWARE_DEFAULTS.put(TilesContainerFactory
+        NO_MODULE_DEFAULTS.put(TilesContainerFactory
                 .PREPARER_FACTORY_INIT_PARAM,
-                BasicPreparerFactory.class.getName());
+                StrutsPreparerFactory.class.getName());
+
+        MODULE_AWARE_DEFAULTS.putAll(NO_MODULE_DEFAULTS);
         MODULE_AWARE_DEFAULTS.put(
                 KeyedDefinitionsFactoryTilesContainerFactory
                 .KEY_EXTRACTOR_CLASS_INIT_PARAM,
                 ModuleKeyExtractor.class.getName());
+        MODULE_AWARE_DEFAULTS.put(TilesContainerFactory
+                .CONTAINER_FACTORY_INIT_PARAM,
+                KeyedDefinitionsFactoryTilesContainerFactory.class.getName());
     }
 
     /**

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/TilesPlugin.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Feb 12 03:22:17 2007
@@ -1 +1 @@
-date author id rev
+Date Author Id Revision HeadURL

Copied: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java (from r506396, struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/ActionPreparer.java)
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java?view=diff&rev=506417&p1=struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/ActionPreparer.java&r1=506396&p2=struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java&r2=506417
==============================================================================
--- struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/ActionPreparer.java (original)
+++ struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java Mon Feb 12 03:22:17 2007
@@ -19,7 +19,7 @@
  * under the License.
  */
 
-package org.apache.struts.tiles2;
+package org.apache.struts.tiles2.preparer;
 
 import org.apache.struts.action.Action;
 import org.apache.tiles.ComponentContext;

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/ActionPreparer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java?view=auto&rev=506417
==============================================================================
--- struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java (added)
+++ struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java Mon Feb 12 03:22:17 2007
@@ -0,0 +1,53 @@
+/*
+ * $Id$
+ *
+ * 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.
+ *
+ */
+package org.apache.struts.tiles2.preparer;
+
+import org.apache.struts.action.Action;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.preparer.BasicPreparerFactory;
+import org.apache.tiles.preparer.ViewPreparer;
+import org.apache.tiles.util.ClassUtil;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StrutsPreparerFactory extends BasicPreparerFactory {
+
+    @Override
+    protected ViewPreparer createPreparer(String name) throws TilesException {
+        ViewPreparer retValue;
+        
+        if (name.startsWith("/")) {
+            retValue = new UrlPreparer(name);
+        } else {
+            Object instance = ClassUtil.instantiate(name, true);
+            if (instance instanceof Action) {
+                retValue = new ActionPreparer((Action) instance);
+            } else {
+                retValue = super.createPreparer(name);
+            }
+        }
+        
+        return retValue;
+    }
+
+}

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/StrutsPreparerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java?view=auto&rev=506417
==============================================================================
--- struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java (added)
+++ struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java Mon Feb 12 03:22:17 2007
@@ -0,0 +1,67 @@
+/*
+ * $Id$
+ *
+ * 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.
+ *
+ */
+package org.apache.struts.tiles2.preparer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.ComponentContext;
+import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.context.servlet.ServletTilesRequestContext;
+import org.apache.tiles.preparer.ViewPreparer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class UrlPreparer implements ViewPreparer {
+    
+    private String url;
+
+    public UrlPreparer(String url) {
+        this.url = url;
+    }
+
+    public void execute(TilesRequestContext tilesContext,
+            ComponentContext componentContext) throws Exception {
+        
+        if (tilesContext instanceof ServletTilesRequestContext) {
+            ServletTilesRequestContext servletTilesContext =
+                (ServletTilesRequestContext) tilesContext; 
+            HttpServletRequest request = servletTilesContext.getRequest();
+            HttpServletResponse response = servletTilesContext.getResponse();
+            RequestDispatcher rd = request.getSession().getServletContext()
+                    .getRequestDispatcher(url);
+            if (rd == null) {
+                throw new ServletException(
+                    "Controller can't find url '" + url + "'.");
+            }
+    
+            rd.include(request, response);
+        } else {
+            throw new ServletException("Cannot dispatch url '" + url
+                    + "' since this preparer has not been called under a servlet environment");
+        }
+    }
+
+}

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/struts1/trunk/tiles2/src/main/java/org/apache/struts/tiles2/preparer/UrlPreparer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL