You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2011/04/16 21:56:44 UTC

svn commit: r1094038 - in /myfaces/extensions/cdi/trunk/jee-modules: jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/ jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/ jsf20-module/impl/src/main/java/...

Author: gpetracek
Date: Sat Apr 16 19:56:44 2011
New Revision: 1094038

URL: http://svn.apache.org/viewvc?rev=1094038&view=rev
Log:
EXTCDI-167 preserve view-parameters (first draft)

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/CodiViewHandler.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/StateCloner.java
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/CodiViewHandler.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/CodiViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/CodiViewHandler.java?rev=1094038&r1=1094037&r2=1094038&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/CodiViewHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/CodiViewHandler.java Sat Apr 16 19:56:44 2011
@@ -36,7 +36,7 @@ import javax.faces.context.FacesContext;
  */
 public class CodiViewHandler extends ViewHandlerWrapper implements Deactivatable
 {
-    private ViewHandler wrapped;
+    protected ViewHandler wrapped;
 
     private ViewHandler windowContextAwareViewHandler;
 
@@ -52,10 +52,15 @@ public class CodiViewHandler extends Vie
         if(isActivated())
         {
             this.windowContextAwareViewHandler = new WindowContextAwareViewHandler(this.wrapped);
-            this.securityAwareViewHandler = new SecurityAwareViewHandler(this.wrapped);
+            this.securityAwareViewHandler = createSecurityAwareViewHandler();
         }
     }
 
+    protected ViewHandler createSecurityAwareViewHandler()
+    {
+        return new SecurityAwareViewHandler(this.wrapped);
+    }
+
     /**
      * {@inheritDoc}
      */

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/CodiViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/CodiViewHandler.java?rev=1094038&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/CodiViewHandler.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/CodiViewHandler.java Sat Apr 16 19:56:44 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf2.impl;
+
+import org.apache.myfaces.extensions.cdi.jsf2.impl.security.SecurityAwareViewHandler;
+
+import javax.faces.application.ViewHandler;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class CodiViewHandler extends org.apache.myfaces.extensions.cdi.jsf.impl.CodiViewHandler
+{
+    /**
+     * {@inheritDoc}
+     */
+    public CodiViewHandler(ViewHandler wrapped)
+    {
+        super(wrapped);
+    }
+
+    @Override
+    protected ViewHandler createSecurityAwareViewHandler()
+    {
+        return new SecurityAwareViewHandler(this.wrapped);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java?rev=1094038&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java Sat Apr 16 19:56:44 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf2.impl.security;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class SecurityAwareViewHandler
+        extends org.apache.myfaces.extensions.cdi.jsf.impl.security.SecurityAwareViewHandler
+{
+    /**
+     * {@inheritDoc}
+     */
+    public SecurityAwareViewHandler(ViewHandler wrapped)
+    {
+        super(wrapped);
+    }
+
+    @Override
+    public UIViewRoot createView(FacesContext context, String viewId)
+    {
+        UIViewRoot originalViewRoot = context.getViewRoot();
+        UIViewRoot newViewRoot;
+
+        Map viewMap = null;
+        if(originalViewRoot != null)
+        {
+            viewMap = originalViewRoot.getViewMap(false);
+
+            if(viewMap instanceof Serializable)
+            {
+                viewMap = StateCloner.clone((Serializable)viewMap, Map.class);
+            }
+        }
+        newViewRoot = super.createView(context, viewId);
+
+        if(viewMap instanceof Serializable)
+        {
+            originalViewRoot.getViewMap(true).putAll(viewMap);
+        }
+        return newViewRoot;
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/StateCloner.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/StateCloner.java?rev=1094038&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/StateCloner.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/StateCloner.java Sat Apr 16 19:56:44 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf2.impl.security;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+/**
+ * @author Gerhard Petracek
+ */
+class StateCloner
+{
+    static <T> T clone(Serializable source, Class<T> targetClass)
+    {
+        ObjectOutputStream outputStream = null;
+        ObjectInputStream inputStream = null;
+        try
+        {
+            ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
+            outputStream = new ObjectOutputStream(arrayOutputStream);
+            outputStream.writeObject(source);
+            outputStream.flush();
+            ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(arrayOutputStream.toByteArray());
+            inputStream = new ObjectInputStream(arrayInputStream);
+            return (T) inputStream.readObject();
+        }
+        catch (Exception e)
+        {
+            throw new IllegalArgumentException("you provided an implementation which isn't serializable or" +
+                    "implemented as anonymous class" + e);
+        }
+        finally
+        {
+            try
+            {
+                if(inputStream != null)
+                {
+                    inputStream.close();
+                }
+
+                if(outputStream != null)
+                {
+                    outputStream.close();
+                }
+            }
+            catch (IOException e)
+            {
+                //noinspection ThrowFromFinallyBlock
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml?rev=1094038&r1=1094037&r2=1094038&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/resources/META-INF/faces-config.xml Sat Apr 16 19:56:44 2011
@@ -28,7 +28,7 @@
         <action-listener>org.apache.myfaces.extensions.cdi.jsf.impl.listener.action.CodiActionListener</action-listener>
         <navigation-handler>org.apache.myfaces.extensions.cdi.jsf2.impl.navigation.CodiNavigationHandler</navigation-handler>
 
-        <view-handler>org.apache.myfaces.extensions.cdi.jsf.impl.CodiViewHandler</view-handler>
+        <view-handler>org.apache.myfaces.extensions.cdi.jsf2.impl.CodiViewHandler</view-handler>
 
         <!-- currently not activated by default due to issues with specific jsf version -->
         <!--system-event-listener>