You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/09/21 11:51:29 UTC

svn commit: r999295 - in /myfaces/test/trunk/test12: ./ src/main/java/org/apache/myfaces/test/mock/lifecycle/ src/main/java/org/apache/myfaces/test/util/

Author: lofwyr
Date: Tue Sep 21 09:51:28 2010
New Revision: 999295

URL: http://svn.apache.org/viewvc?rev=999295&view=rev
Log:
MYFACESTEST-35: Support for JSF 1.1
 - put the JSF 1.2 stuff in classes that will only be loaded when there is JSF 1.2 available.

Added:
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf11Utils.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf12Utils.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/JsfVersion.java
Modified:
    myfaces/test/trunk/test12/pom.xml
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java

Modified: myfaces/test/trunk/test12/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/pom.xml?rev=999295&r1=999294&r2=999295&view=diff
==============================================================================
--- myfaces/test/trunk/test12/pom.xml (original)
+++ myfaces/test/trunk/test12/pom.xml Tue Sep 21 09:51:28 2010
@@ -29,7 +29,7 @@
 
     <artifactId>myfaces-test12</artifactId>
     <packaging>jar</packaging>
-    <name>Myfaces Test Framework for JSF 1.2</name>
+    <name>Myfaces Test Framework for JSF 1.2 (and 1.1)</name>
 
     <dependencies>
 

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java?rev=999295&r1=999294&r2=999295&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java Tue Sep 21 09:51:28 2010
@@ -17,18 +17,20 @@
 
 package org.apache.myfaces.test.mock.lifecycle;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.test.util.Jsf11Utils;
+import org.apache.myfaces.test.util.Jsf12Utils;
+import org.apache.myfaces.test.util.JsfVersion;
+
 import javax.faces.FacesException;
 import javax.faces.application.Application;
-import javax.faces.application.ViewExpiredException;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseId;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
  * Implements the Restore View Phase (JSF Spec 2.2.1)
  * 
@@ -53,7 +55,11 @@ class RestoreViewExecutor implements Pha
         // init the View
         Application application = facesContext.getApplication();
         ViewHandler viewHandler = application.getViewHandler();
-        viewHandler.initView(facesContext);
+        if (JsfVersion.supports12()) {
+          Jsf12Utils.initView(facesContext, viewHandler);
+        } else {
+          // nothing to do
+        }
 
         UIViewRoot viewRoot = facesContext.getViewRoot();
 
@@ -81,9 +87,11 @@ class RestoreViewExecutor implements Pha
             viewRoot = viewHandler.restoreView(facesContext, viewId);
             if (viewRoot == null)
             {
-                throw new ViewExpiredException(
-                        "The expected view was not returned "
-                                + "for the view identifier: " + viewId, viewId);
+              if (JsfVersion.supports12()) {
+                Jsf12Utils.throwViewExpiredException(viewId);
+              } else {
+                Jsf11Utils.throwViewExpiredException(viewId);
+              }
             }
             restoreViewSupport.processComponentBinding(facesContext, viewRoot);
         }

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf11Utils.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf11Utils.java?rev=999295&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf11Utils.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf11Utils.java Tue Sep 21 09:51:28 2010
@@ -0,0 +1,27 @@
+/*
+ * 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.test.util;
+
+public class Jsf11Utils {
+
+  public static void throwViewExpiredException(String viewId)
+  {
+    throw new RuntimeException(
+            "The expected view was not returned for the view identifier: " + viewId);
+  }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf12Utils.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf12Utils.java?rev=999295&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf12Utils.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/Jsf12Utils.java Tue Sep 21 09:51:28 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.test.util;
+
+import javax.faces.application.ViewExpiredException;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+
+public class Jsf12Utils
+{
+
+  public static void initView(FacesContext facesContext, ViewHandler viewHandler)
+  {
+    viewHandler.initView(facesContext);
+  }
+
+  public static void throwViewExpiredException(String viewId)
+  {
+    throw new ViewExpiredException(
+        "The expected view was not returned for the view identifier: " + viewId, viewId);
+  }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/JsfVersion.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/JsfVersion.java?rev=999295&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/JsfVersion.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/util/JsfVersion.java Tue Sep 21 09:51:28 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.test.util;
+
+import javax.faces.application.Application;
+
+public class JsfVersion
+{
+  private static boolean supports12;
+  private static boolean supports20;
+
+  static
+  {
+    try
+    {
+      Application.class.getMethod("getExpressionFactory");
+      supports12 = true;
+
+      try
+      {
+        Application.class.getMethod("getExceptionHandler");
+        supports20 = true;
+
+      } catch (NoSuchMethodException e) {
+        // ignore
+      }
+
+    } catch (NoSuchMethodException e) {
+      // ignore
+    }
+  }
+
+  private JsfVersion() {
+    // avoid instantiation
+  }
+
+  /**
+   * Does the JSF is version 1.2 or higher
+   *
+   * @return Supports 1.2 or higher
+   */
+  public static boolean supports12()
+  {
+    return supports12;
+  }
+
+  /**
+   * Does the JSF is version 2.0 or higher
+   *
+   * @return Supports 2.0 or higher
+   */
+  public static boolean supports20()
+  {
+    return supports20;
+  }
+}