You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by gv...@apache.org on 2006/10/16 04:16:24 UTC

svn commit: r464361 - in /shale/framework/trunk: shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/rolodex/ shale-clay/src/main/java/org/apache/shale/clay/component/chain/ shale-clay/src/main/java/org/apache/shale/clay/config/beans...

Author: gvanmatre
Date: Sun Oct 15 19:16:20 2006
New Revision: 464361

URL: http://svn.apache.org/viewvc?view=rev&rev=464361
Log:
A few fixes to move Clay in the direction of JSF 1.2 support (SHALE-67).

Added:
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java   (with props)
Modified:
    shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/rolodex/Rolodex.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/SequenceGenerator.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java
    shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml

Modified: shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/rolodex/Rolodex.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/rolodex/Rolodex.java?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/rolodex/Rolodex.java (original)
+++ shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/rolodex/Rolodex.java Sun Oct 15 19:16:20 2006
@@ -235,9 +235,9 @@
         // create an output Text
         ElementBean text = new ElementBean();
         text.setRenderId(generateId());
-        text.setJsfid("outputText");
+        text.setJsfid("f:verbatim");
         text.setComponentType("javax.faces.HtmlOutputText");
-
+             
         // add a value attribute
         AttributeBean attr = new AttributeBean();
         attr.setName("value");

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java Sun Oct 15 19:16:20 2006
@@ -33,6 +33,7 @@
 import org.apache.shale.clay.config.beans.AttributeBean;
 import org.apache.shale.clay.config.beans.Attributes;
 import org.apache.shale.clay.config.beans.ComponentBean;
+import org.apache.shale.clay.utils.JSFRuntimeTracker;
 
 /**
  * <p>
@@ -54,17 +55,12 @@
     }
 
     /**
-     * <p>Tests to see if myfaces runtime is installed by trying to load a known class.</p>
+     * <p>Tests to see if sun runtime 1.1.x is installed.</p>
      *
-     * @return <code>true</code> if myfaces runtime is loaded
+     * @return <code>true</code> if ri 1.1.x runtime is loaded
      */
-    private boolean isMyfacesRuntimeInstalled() {
-        try {
-            Class.forName("org.apache.myfaces.application.jsp.JspViewHandlerImpl");
-            return true;
-        } catch (ClassNotFoundException e) {
-            return false;
-        }
+    private boolean isRI11Installed() {
+       return (JSFRuntimeTracker.getJsfRuntime() == JSFRuntimeTracker.RI_1_1);
     }
 
 
@@ -77,7 +73,7 @@
     private String createUniqueId(FacesContext facesContext) {
         String id = null;
 
-        if (isMyfacesRuntimeInstalled()) {
+        if (!isRI11Installed()) {
             Map requestMap = facesContext.getExternalContext().getRequestMap();
             SequenceGenerator generator = (SequenceGenerator) requestMap.get(Globals.CLAY_SEQUENCE_GENERATOR);
             if (generator == null) {

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/SequenceGenerator.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/SequenceGenerator.java?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/SequenceGenerator.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/SequenceGenerator.java Sun Oct 15 19:16:20 2006
@@ -19,21 +19,51 @@
  */
 package org.apache.shale.clay.component.chain;
 
+import javax.faces.component.UIViewRoot;
+
+import org.apache.shale.clay.utils.JSFRuntimeTracker;
+
 /**
  * <p>Generates a unique id used to identify each component in the component tree.
- * The id's will be prefixed with "_idsc" followed by a sequential incremented
- * number.  This class will be used outside of the implementation of the
- * <code>UIViewRoot</code>'s createUniqueId method.  This object will be cached
- * in request scope each time the view is rendered and the component tree contains
- * one or more {@link org.apache.shale.clay.component.Clay} components.<br/><br/>
+ * The id's will be prefixed with UIViewRoot.UNIQUE_ID_PREFIX + "sc" followed by
+ * a sequential incremented number.  This class will be used outside of the
+ * implementation of the <code>UIViewRoot</code>'s createUniqueId method.
+ * This object will be cached in request scope each time the view is rendered
+ * and the component tree contains one or more
+ * {@link org.apache.shale.clay.component.Clay} components.<br/><br/>
  * This class is only used with the myfaces implementation.</p>
  */
 public class SequenceGenerator {
+
+   /**
+    * <p>The constructor will look at the active JSF runtime to
+    * determine what the <code>uniqueIdPrefix</code> should be.
+    * There might be multiple implementations in the classpath.
+    * </p>
+    */
+   public SequenceGenerator() {
+
+       if (JSFRuntimeTracker.getJsfRuntime() == JSFRuntimeTracker.RI_1_2) {
+           uniqueIdPrefix = "j_id" + "sc";
+           buff.setLength(0);
+           buff.append(uniqueIdPrefix);
+       }
+
+   }
+
+    /**
+    * <p>Clay's unique view root prefix.  It must begin with the
+    * same prefix of the <code>UIViewRoot.UNIQUE_ID_PREFIX</code> to
+    * play nicely with the 1.2 RI.</p>
+    */
+   public static String uniqueIdPrefix = UIViewRoot.UNIQUE_ID_PREFIX + "sc";
+
    /**
-    * <p>Holds the id prefix of "_idsc".  The <code>uniqueId</code>
-    * is appended for each call to <code>createUniqueId</code>.</p>
+    * <p>Holds the id prefix of <code>UIViewRoot.UNIQUE_ID_PREFIX</code> + "sc".
+    * The <code>uniqueId</code> is appended for each call
+    * to <code>createUniqueId</code>.</p>
     */
-   private StringBuffer buff = new StringBuffer("_idsc");
+   private StringBuffer buff = new StringBuffer(uniqueIdPrefix);
 
    /**
     * <p>Sequencial generated unique number for the object instance.</p>
@@ -41,12 +71,13 @@
    private int uniqueId = 0;
 
    /**
-    * <p>Returns a unique component id prefixed with "_idsc".</p>
+    * <p>Returns a unique component id prefixed with
+    * <code>UIViewRoot.UNIQUE_ID_PREFIX</code> + "sc".</p>
     *
     * @return a unique id per object instance
     */
    public String createUniqueId() {
-       buff.setLength("_idsc".length());
+       buff.setLength(uniqueIdPrefix.length());
        buff.append(uniqueId++);
        return buff.toString();
    }

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java Sun Oct 15 19:16:20 2006
@@ -245,7 +245,7 @@
     private boolean isVerbatim(ComponentBean node) {
 
         AttributeBean attr = null;
-        if (node.getJsfid().equals("verbatim")
+        if ((node.getJsfid().equals("verbatim") || node.getJsfid().equals("f:verbatim"))
              && node.getComponentType().equals("javax.faces.HtmlOutputText")) {
             attr = node.getAttribute("isTransient");
             if (attr != null) {

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java Sun Oct 15 19:16:20 2006
@@ -38,6 +38,7 @@
 import org.apache.shale.clay.component.Clay;
 import org.apache.shale.clay.config.Globals;
 import org.apache.shale.clay.config.beans.PageNotFoundException;
+import org.apache.shale.clay.utils.JSFRuntimeTracker;
 
 /**
  * <p>This <code>ViewHandler</code> will handle full HTML template views using the
@@ -311,25 +312,26 @@
      * implementations.</p>
      */
     protected static final String[] FORM_MARKERS = {
-        "com.sun.faces.saveStateFieldMarker", "<!-...@-->"};
+        "com.sun.faces.saveStateFieldMarker",    // RI 1.1
+        "<!-...@-->",      // myfaces 1.1.x
+        "~com.sun.faces.saveStateFieldMarker~"}; // RI 1.2
 
     /**
      * <p>Returns an index into the <code>FORM_MAKKERS</code> array.  The index will be used to
      * get the form marker matching the JSF runtime. Only the myfaces and Sun RI are supported.
-     * The form marker is determined by trying to load the myfaces view handler.  The default
+     * The form marker is determined by trying to load the myfaces view handler.  Next,
+     * the Sun RI 1.2 JSPVersionTracker is attempted to be loaded.  The default
      * is the marker for the Sun RI.</p>
      *
      * @return index into the FORM_MARKERS array
      */
     protected int indexOfFormMarker() {
         int i = 0;
-        try {
-            Class.forName("org.apache.myfaces.application.jsp.JspViewHandlerImpl");
-            i = 1;
-        } catch (ClassNotFoundException e) {
-            i = 0;
+        if (JSFRuntimeTracker.getJsfRuntime() == JSFRuntimeTracker.MYFACES_1_1) {
+          i = 1;
+        } else if (JSFRuntimeTracker.getJsfRuntime() == JSFRuntimeTracker.RI_1_2) {
+          i = 2;
         }
-
         return i;
     }
 

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java Sun Oct 15 19:16:20 2006
@@ -44,7 +44,7 @@
      * @return jsfid
      */
     protected String getJsfid(Node node) {
-        return "verbatim";
+        return "f:verbatim";
     }
 
     /**
@@ -140,4 +140,16 @@
         }
     }
 
+    /**
+     * <p>Skip the processing of attributes for a verbatim node.  This
+     * was a bug uncovered with JSF RI 1.2.  The <code>TextRenderer</code>
+     * is sensitive to pass thru attributes.  If it finds a pass thru 
+     * attribute, it wraps the text in a HTML span tag.</p>
+     *
+     * @param node markup node
+     * @param target config bean built for the markup node
+     */
+    protected void assignAttributes(Node node, ComponentBean target) {
+       //NA for a verbatim
+    }
 }

Added: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java?view=auto&rev=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java (added)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java Sun Oct 15 19:16:20 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * $Id$
+ */
+
+package org.apache.shale.clay.utils;
+
+/**
+ * <p>This utility class is used to determine the
+ * JSF runtime that will take presidency.</p>
+ */
+public class JSFRuntimeTracker {
+    /**
+     * <p>This enumeration indicates the JSF RI 1.1.x runtime is installed.</p>
+     */
+    public static final int RI_1_1 = 0;
+
+    /**
+     * <p>This enumeration indicates the MyFaces 1.1.x runtime is installed.</p>
+     */
+    public static final int MYFACES_1_1 = 1;
+
+    /**
+     * <p>This enumeration indicates the JSF RI 1.2.x runtime is installed.</p>
+     */
+    public static final int RI_1_2 = 2;
+
+    /**
+     * <p>Captures the active runtime once determined.</p>
+     */
+    private static int activeRuntime = -1;
+
+    /**
+     * <p>This method will try to load some key classes in the various runtimes
+     * to determine the active runtime.  The enumerations are as follows:
+     * <code>RI_1_1</code>, <code>MYFACES_1_1</code>, <code>RI_1_2</code>.</p>
+     *
+     * @return an enumeration that indicates the active JSF runtime
+     */
+    public static int getJsfRuntime() {
+        if (activeRuntime > 0) {
+            return activeRuntime;
+        }
+        try {
+            // JSF RI 1.2
+            Class.forName("com.sun.faces.config.JSFVersionTracker");
+            activeRuntime = RI_1_2;
+        } catch (ClassNotFoundException e1) {
+            try {
+                Class.forName("org.apache.myfaces.application.jsp.JspViewHandlerImpl");
+                activeRuntime = MYFACES_1_1;  //myfaces 1.1.x
+            } catch (ClassNotFoundException e2) {
+                activeRuntime = RI_1_1; //JSF RI 1.1
+            }
+        }
+
+        return activeRuntime;
+    }
+}

Propchange: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/JSFRuntimeTracker.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml?view=diff&rev=464361&r1=464360&r2=464361
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml (original)
+++ shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml Sun Oct 15 19:16:20 2006
@@ -483,12 +483,18 @@
   </component>
   <component jsfid="f:selectItem" extends="selectItem"/>
   
-  <component jsfid="verbatim" extends="outputText">
+  <component jsfid="verbatim" extends="baseComponent" componentType="javax.faces.HtmlOutputText" >
     <description>Render plain text.</description>     
     <attributes>
       <set name="isTransient" bindingType="VB" value="true">
          <description></description>
       </set>
+      <set name="escape" bindingType="VB" value="false">
+         <description></description>
+      </set>
+      <set name="value" bindingType="VB">
+           <description></description>
+      </set>        
     </attributes>
   </component>
   <component jsfid="f:verbatim" extends="verbatim"/>