deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-454 cleanup
Date Thu, 09 Jan 2014 16:09:08 GMT
Updated Branches:
  refs/heads/master f4bada5b4 -> 277bd24ca


DELTASPIKE-454 cleanup


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/277bd24c
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/277bd24c
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/277bd24c

Branch: refs/heads/master
Commit: 277bd24ca3639b6580777b63be163d33bf9c1c7d
Parents: f4bada5
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Jan 9 17:04:17 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Jan 9 17:08:49 2014 +0100

----------------------------------------------------------------------
 .../jsf/spi/scope/window/ClientWindow.java      | 73 ++++----------------
 .../impl/scope/window/DefaultClientWindow.java  | 68 +++++++-----------
 2 files changed, 39 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/277bd24c/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
index dba12c9..8397c23 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
@@ -34,11 +34,8 @@ import javax.faces.context.FacesContext;
  * ClientWindow instances are most likely &#064;ApplicationScoped.
  * </p>
  */
-public abstract class ClientWindow
+public interface ClientWindow
 {
-    private static final String PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY =
-            ClientWindow.class.getName() + ".ClientWindowRenderModeEnablement";
-
     /**
      * Extract the windowId for the current request.
      * This method is intended to get executed at the start of the JSF lifecycle.
@@ -50,72 +47,28 @@ public abstract class ClientWindow
      * @param facesContext for the request
      * @return the extracted WindowId of the Request, or <code>null</code> if
there is no window assigned.
      */
-    public abstract String getWindowId(FacesContext facesContext);
+    String getWindowId(FacesContext facesContext);
 
     /**
-     * <p>Components that permit per-use disabling
-     * of the appending of the ClientWindow in generated URLs must call this method
-     * first before rendering those URLs.  The caller must call
-     * {@link #enableClientWindowRenderMode(javax.faces.context.FacesContext)}
-     * from a <code>finally</code> block after rendering the URL.  If
-     * {@link #CLIENT_WINDOW_MODE_PARAM_NAME} is "url" without the quotes, all generated
-     * URLs that cause a GET request must append the ClientWindow by default.
-     * This is specified as a static method because callsites need to access it
-     * without having access to an actual {@code ClientWindow} instance.</p>
-     *
-     * @param context the {@link FacesContext} for this request.
+     * Can be called to disable the window-id for an URL.
+     * Don't forget to call {@link #enableClientWindowRenderMode(javax.faces.context.FacesContext)}
+     * after rendering the markup for the current component, if {@link #isClientWindowRenderModeEnabled}
+     * returned <code>true</code> before calling this method.
      */
-    public void disableClientWindowRenderMode(FacesContext context)
-    {
-        Map<Object, Object> attrMap = context.getAttributes();
-        attrMap.put(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY, Boolean.TRUE);
-    }
+    void disableClientWindowRenderMode(FacesContext facesContext);
 
     /**
-     * <p>Components that permit per-use disabling
-     * of the appending of the ClientWindow in generated URLs must call this method
-     * first after rendering those URLs.  If
-     * {@link #CLIENT_WINDOW_MODE_PARAM_NAME} is "url" without the quotes, all generated
-     * URLs that cause a GET request must append the ClientWindow by default.
-     * This is specified as a static method because callsites need to access it
-     * without having access to an actual {@code ClientWindow} instance.</p>
-     *
-     * @param context the {@link FacesContext} for this request.
+     * Can be used to reset window-id rendering for a specific component.
      */
-    public void enableClientWindowRenderMode(FacesContext context)
-    {
-        Map<Object, Object> attrMap = context.getAttributes();
-        attrMap.remove(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY);
-    }
+    void enableClientWindowRenderMode(FacesContext facesContext);
 
     /**
-     * <p>Methods that append the ClientWindow to generated
-     * URLs must call this method to see if they are permitted to do so.  If
-     * {@link #CLIENT_WINDOW_MODE_PARAM_NAME} is "url" without the quotes, all generated
-     * URLs that cause a GET request must append the ClientWindow by default.
-     * This is specified as a static method because callsites need to access it
-     * without having access to an actual {@code ClientWindow} instance.</p>
-     *
-     * @param context the {@link FacesContext} for this request.
+     * @return true if the window-id should be appended during the rendering-process, false
otherwise
      */
-    public boolean isClientWindowRenderModeEnabled(FacesContext context)
-    {
-        Map<Object, Object> attrMap = context.getAttributes();
-        boolean result = !attrMap.containsKey(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY);
-        return result;
-    }
+    boolean isClientWindowRenderModeEnabled(FacesContext facesContext);
 
     /**
-     * <p>This method will be called whenever a URL
-     * is generated by the runtime where client window related parameters need
-     * to be inserted into the URL.  This guarantees custom {@code ClientWindow} implementations
-     * that they will have the opportunity to insert any additional client window specific
-     * information in any case where a URL is generated, such as the rendering
-     * of hyperlinks.  The returned map must be immutable.  The default implementation of
this method returns
-     * the empty map.</p>
-
-     * @param context the {@code FacesContext} for this request.
-     * @return {@code null} or a map of parameters to insert into the URL query string.
+     * @return meta-data for the current window which should get added to URLs, null otherwise
      */
-    public abstract Map<String, String> getQueryURLParameters(FacesContext context);
+    Map<String, String> getQueryURLParameters(FacesContext facesContext);
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/277bd24c/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
index 9f6762d..92378f9 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
@@ -18,7 +18,12 @@
  */
 package org.apache.deltaspike.jsf.impl.scope.window;
 
+import org.apache.deltaspike.core.spi.scope.window.WindowContext;
 import org.apache.deltaspike.jsf.impl.util.ClientWindowHelper;
+import org.apache.deltaspike.jsf.impl.util.JsfUtils;
+import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
+import org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig;
+
 import javax.enterprise.context.ApplicationScoped;
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
@@ -26,18 +31,11 @@ import javax.faces.context.FacesContext;
 import javax.inject.Inject;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
-import java.util.logging.Logger;
-
-import org.apache.deltaspike.core.spi.scope.window.WindowContext;
-import org.apache.deltaspike.jsf.impl.util.JsfUtils;
-import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
-import org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig;
 
 import static org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig.ClientWindowRenderMode;
 
@@ -48,13 +46,10 @@ import static org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig.Clie
  * ClientSideWindowHandler.
  *
  * It will act according to the configured {@link ClientWindowRenderMode}.
- *
- *
  */
 @ApplicationScoped
-public class DefaultClientWindow extends ClientWindow
+public class DefaultClientWindow implements ClientWindow
 {
-
     /**
      * Value which can be used as "window-id" by external clients which aren't aware of windows.
      * It deactivates e.g. the redirect for the initial request.
@@ -72,8 +67,8 @@ public class DefaultClientWindow extends ClientWindow
      */
     public static final String DELTASPIKE_WINDOW_ID_URL_PARAM = "dswid";
 
-    private static final Logger logger = Logger.getLogger(DefaultClientWindow.class.getName());
-
+    private static final String PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY =
+            ClientWindow.class.getName() + ".ClientWindowRenderModeEnablement";
 
     private static final String WINDOW_ID_COOKIE_PREFIX = "dsWindowId-";
     private static final String DELTASPIKE_REQUEST_TOKEN = "dsRid";
@@ -199,7 +194,6 @@ public class DefaultClientWindow extends ClientWindow
         return windowId;
     }
 
-
     private boolean isNoscriptRequest(ExternalContext externalContext)
     {
         String noscript = externalContext.getRequestParameterMap().get(NOSCRIPT_PARAMETER);
@@ -207,7 +201,6 @@ public class DefaultClientWindow extends ClientWindow
         return (noscript != null && "true".equals(noscript));
     }
 
-
     private void sendWindowHandlerHtml(ExternalContext externalContext, String windowId)
     {
         HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
@@ -304,73 +297,64 @@ public class DefaultClientWindow extends ClientWindow
         return "";
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public void disableClientWindowRenderMode(FacesContext context)
+    public void disableClientWindowRenderMode(FacesContext facesContext)
     {
-        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(context);
+        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(facesContext);
 
         if (ClientWindowRenderMode.DELEGATED.equals(clientWindowRenderMode))
         {
-            context.getExternalContext().getClientWindow().disableClientWindowRenderMode(context);
+            facesContext.getExternalContext().getClientWindow().disableClientWindowRenderMode(facesContext);
         }
         else if (ClientWindowRenderMode.URL.equals(clientWindowRenderMode))
         {
-            super.disableClientWindowRenderMode(context);
+            Map<Object, Object> attrMap = facesContext.getAttributes();
+            attrMap.put(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY, Boolean.TRUE);
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public void enableClientWindowRenderMode(FacesContext context)
+    public void enableClientWindowRenderMode(FacesContext facesContext)
     {
-        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(context);
+        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(facesContext);
 
         if (ClientWindowRenderMode.DELEGATED.equals(clientWindowRenderMode))
         {
-            context.getExternalContext().getClientWindow().enableClientWindowRenderMode(context);
+            facesContext.getExternalContext().getClientWindow().enableClientWindowRenderMode(facesContext);
         }
         else if (ClientWindowRenderMode.URL.equals(clientWindowRenderMode))
         {
-            super.enableClientWindowRenderMode(context);
+            Map<Object, Object> attrMap = facesContext.getAttributes();
+            attrMap.remove(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY);
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public boolean isClientWindowRenderModeEnabled(FacesContext context)
+    public boolean isClientWindowRenderModeEnabled(FacesContext facesContext)
     {
-        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(context);
+        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(facesContext);
 
         if (ClientWindowRenderMode.URL.equals(clientWindowRenderMode))
         {
-            return super.isClientWindowRenderModeEnabled(context);
+            Map<Object, Object> attrMap = facesContext.getAttributes();
+            return  !attrMap.containsKey(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY);
         }
 
         return false;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public Map<String, String> getQueryURLParameters(FacesContext context)
+    public Map<String, String> getQueryURLParameters(FacesContext facesContext)
     {
-        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(context);
+        ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(facesContext);
 
         if (ClientWindowRenderMode.URL.equals(clientWindowRenderMode))
         {
-            String windowId = getWindowId(context);
+            String windowId = getWindowId(facesContext);
             if (windowId != null)
             {
                 Map<String, String> params = new HashMap<String, String>();
-                params.put(DELTASPIKE_WINDOW_ID_URL_PARAM, getWindowId(context));
+                params.put(DELTASPIKE_WINDOW_ID_URL_PARAM, getWindowId(facesContext));
                 return params;
             }
         }


Mime
View raw message