You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/11/08 20:22:09 UTC

svn commit: r833915 - in /tiles/sandbox/trunk/tiles3: tiles-portlet/src/main/java/org/apache/tiles/portlet/context/ tiles-test-pom/tiles-test/src/main/java/org/apache/tiles/test/portlet/

Author: apetrelli
Date: Sun Nov  8 19:22:08 2009
New Revision: 833915

URL: http://svn.apache.org/viewvc?rev=833915&view=rev
Log:
TILESSB-12
Preparing tiles-portlet to be moved in tiles-request.

Modified:
    tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/NotAPortletEnvironmentException.java
    tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletUtil.java
    tiles/sandbox/trunk/tiles3/tiles-test-pom/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java

Modified: tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/NotAPortletEnvironmentException.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/NotAPortletEnvironmentException.java?rev=833915&r1=833914&r2=833915&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/NotAPortletEnvironmentException.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/NotAPortletEnvironmentException.java Sun Nov  8 19:22:08 2009
@@ -30,7 +30,7 @@
  * @version $Rev$ $Date$
  * @since 2.1.4
  */
-public class NotAPortletEnvironmentException extends NotAvailableFeatureException {
+public class NotAPortletEnvironmentException extends RuntimeException {
 
     /**
      * Constructor.

Modified: tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletUtil.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletUtil.java?rev=833915&r1=833914&r2=833915&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletUtil.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletUtil.java Sun Nov  8 19:22:08 2009
@@ -21,17 +21,8 @@
 
 package org.apache.tiles.portlet.context;
 
-import javax.portlet.PortletContext;
 import javax.portlet.PortletRequest;
 
-import org.apache.tiles.ArrayStack;
-import org.apache.tiles.TilesContainer;
-import org.apache.tiles.access.TilesAccess;
-import org.apache.tiles.impl.NoSuchContainerException;
-import org.apache.tiles.servlet.context.ServletUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 
 /**
  * Utilities for Tiles portlet support.
@@ -76,146 +67,4 @@
 						org.apache.tiles.request.servlet.ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME,
 						retValue);
     }
-
-    /**
-     * Returns the default Tiles container.
-     *
-     * @param context The portlet context to use.
-     * @return The default Tiles container.
-     * @since 2.1.2
-     */
-    public static TilesContainer getContainer(PortletContext context) {
-        return getContainer(context, TilesAccess.CONTAINER_ATTRIBUTE);
-    }
-
-    /**
-     * Returns a specific Tiles container.
-     *
-     * @param context The portlet context to use.
-     * @param key The key under which the container is stored. If null, the
-     * default container will be returned.
-     * @return The requested Tiles container.
-     * @since 2.1.2
-     */
-    public static TilesContainer getContainer(PortletContext context, String key) {
-        if (key == null) {
-            key = TilesAccess.CONTAINER_ATTRIBUTE;
-        }
-        return (TilesContainer) context.getAttribute(key);
-    }
-
-    /**
-     * Configures the default container to be used in the application.
-     *
-     * @param context The portlet context object to use.
-     * @param container The container object to set.
-     * @since 2.1.2
-     */
-    public static void setContainer(PortletContext context,
-            TilesContainer container) {
-        setContainer(context, container, TilesAccess.CONTAINER_ATTRIBUTE);
-    }
-
-    /**
-     * Configures the container to be used in the application.
-     *
-     * @param context The portlet context object to use.
-     * @param container The container object to set.
-     * @param key The key under which the container will be stored.
-     * @since 2.1.2
-     */
-    public static void setContainer(PortletContext context,
-            TilesContainer container, String key) {
-        Logger log = LoggerFactory.getLogger(PortletUtil.class);
-        if (key == null) {
-            key = TilesAccess.CONTAINER_ATTRIBUTE;
-        }
-
-        if (container == null) {
-            if (log.isInfoEnabled()) {
-                log.info("Removing TilesContext for context: " + context.getClass().getName());
-            }
-            context.removeAttribute(key);
-        }
-        if (container != null && log.isInfoEnabled()) {
-            log.info("Publishing TilesContext for context: " + context.getClass().getName());
-        }
-        context.setAttribute(key, container);
-    }
-
-    /**
-     * Sets the current container to use in web pages.
-     *
-     * @param request The request to use.
-     * @param context The portlet context to use.
-     * @param key The key under which the container is stored.
-     * @since 2.1.0
-     */
-    public static void setCurrentContainer(PortletRequest request,
-            PortletContext context, String key) {
-        TilesContainer container = getContainer(context, key);
-        if (container != null) {
-            request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
-        } else {
-            throw new NoSuchContainerException("The container with the key '"
-                    + key + "' cannot be found");
-        }
-    }
-
-    /**
-     * Sets the current container to use in web pages.
-     *
-     * @param request The request to use.
-     * @param context The portlet context to use.
-     * @param container The container to use as the current container.
-     * @since 2.1.0
-     */
-    public static void setCurrentContainer(PortletRequest request,
-            PortletContext context, TilesContainer container) {
-        if (container != null) {
-            request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
-        } else {
-            throw new NoSuchContainerException("The container cannot be null");
-        }
-    }
-
-    /**
-     * Returns the current container that has been set, or the default one.
-     *
-     * @param request The request to use.
-     * @param context The portlet context to use.
-     * @return The current Tiles container to use in web pages.
-     * @since 2.1.0
-     */
-    public static TilesContainer getCurrentContainer(PortletRequest request,
-            PortletContext context) {
-        TilesContainer container = (TilesContainer) request
-                .getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME);
-        if (container == null) {
-            container = getContainer(context);
-            request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
-                    container);
-        }
-
-        return container;
-    }
-
-    /**
-     * Returns the compose stack, that is used by the tags to compose
-     * definitions, attributes, etc.
-     *
-     * @param request The portlet request.
-     * @return The compose stack.
-     * @since 2.2.0
-     */
-    @SuppressWarnings("unchecked")
-    public static ArrayStack<Object> getComposeStack(PortletRequest request) {
-        ArrayStack<Object> composeStack = (ArrayStack<Object>) request.getAttribute(
-                ServletUtil.COMPOSE_STACK_ATTRIBUTE_NAME);
-        if (composeStack == null) {
-            composeStack = new ArrayStack<Object>();
-            request.setAttribute(ServletUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
-        }
-        return composeStack;
-    }
 }

Modified: tiles/sandbox/trunk/tiles3/tiles-test-pom/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-test-pom/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java?rev=833915&r1=833914&r2=833915&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-test-pom/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-test-pom/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java Sun Nov  8 19:22:08 2009
@@ -26,7 +26,9 @@
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.GenericPortlet;
+import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
 import javax.portlet.PortletRequestDispatcher;
 import javax.portlet.PortletSession;
 import javax.portlet.PortletURL;
@@ -35,7 +37,8 @@
 import javax.portlet.RenderResponse;
 
 import org.apache.tiles.TilesContainer;
-import org.apache.tiles.portlet.context.PortletUtil;
+import org.apache.tiles.access.TilesAccess;
+import org.apache.tiles.servlet.context.ServletUtil;
 
 /**
  * Test Portlet.
@@ -52,8 +55,8 @@
         String definition = (String) portletSession.getAttribute("definition");
         if (definition != null) {
             portletSession.removeAttribute("definition");
-            TilesContainer container = PortletUtil.getCurrentContainer(request,
-                    getPortletContext());
+			TilesContainer container = getCurrentContainer(request,
+					getPortletContext());
             if (container.isValidDefinition(definition, request, response,
                     getPortletContext())) {
                 container.render(definition, request, response,
@@ -99,4 +102,52 @@
         writer.append(url.toString());
         writer.append("\"> Back to definition selection</a>");
     }
+
+    /**
+     * Returns the current container that has been set, or the default one.
+     *
+     * @param request The request to use.
+     * @param context The portlet context to use.
+     * @return The current Tiles container to use in web pages.
+     * @since 2.1.0
+     */
+    private static TilesContainer getCurrentContainer(PortletRequest request,
+            PortletContext context) {
+        TilesContainer container = (TilesContainer) request
+                .getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME);
+        if (container == null) {
+            container = getContainer(context);
+            request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
+                    container);
+        }
+
+        return container;
+    }
+
+    /**
+     * Returns a specific Tiles container.
+     *
+     * @param context The portlet context to use.
+     * @param key The key under which the container is stored. If null, the
+     * default container will be returned.
+     * @return The requested Tiles container.
+     * @since 2.1.2
+     */
+    private static TilesContainer getContainer(PortletContext context, String key) {
+        if (key == null) {
+            key = TilesAccess.CONTAINER_ATTRIBUTE;
+        }
+        return (TilesContainer) context.getAttribute(key);
+    }
+
+    /**
+     * Returns the default Tiles container.
+     *
+     * @param context The portlet context to use.
+     * @return The default Tiles container.
+     * @since 2.1.2
+     */
+    private static TilesContainer getContainer(PortletContext context) {
+        return getContainer(context, TilesAccess.CONTAINER_ATTRIBUTE);
+    }
 }