Author: dolander
Date: Fri Nov 19 08:25:09 2004
New Revision: 105828

Modified:
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/rendering/TagRenderingBase.java
   incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
   
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
Log:
Add support to the netui-config file to turn on the id transparency.  This is 
off by default and 
explicitly off in the DRT webapp.

Additional cleanup and comments.




Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
  (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
  Fri Nov 19 08:25:09 2004
@@ -1,8 +1,9 @@
 package org.apache.beehive.netui.pageflow;
 
+import org.apache.beehive.netui.util.config.ConfigUtil;
+import org.apache.beehive.netui.util.config.bean.JspTagConfig;
 import org.apache.xmlbeans.impl.util.Base64;
 
-import javax.servlet.ServletContext;
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 
@@ -10,72 +11,115 @@
  * This class creates and process and ID to Expression map.  The map is used 
to store the mapping between
  * the ID/Name elements in a form and the expression referencing the object 
the form element value maps to when
  * the form is posted.  The basic reason for this mapping, is that expression 
may contain invalid characters for
- * and NMTOKEN attribute.  In XHTML and HTML the id
+ * and NMTOKEN attribute.
  */
 public class IdMapper
 {
-    // This is the character
-    private static final String SPLIT = "\0";
+    // This is the character that is used as a separator between the name, 
expression pairs in the id map string.
+    public static final String SPLIT_CHAR = "\0";
+
+    // Constant for the encoding...
     private static final String CHARSET = "ISO-8859-1";
 
+    private static final String TRAN_ON_VAL = "Transparent On";
+    private static final String TRAN_OFF_VAL = "Transparent Off";
+
     private StringBuilder _idString;
 
-    /**
-     * Web.xml initialization parameter for attribute transparency
-     */
-    private static final String ID_TRANSPARENCY = "netui.ID_TRANSPARENCY";
-    private static Boolean _transparent = Boolean.FALSE;
+    private static final int TRAN_UNKNOWN = 0;
+    private static final int TRAN_DEFAULT = 1;
+    private static final int TRAN_ON = 2;
+    private static final int TRAN_OFF = 3;
 
+    private static int _transparent = TRAN_UNKNOWN;
 
-    public static boolean isIdTransparency(ServletContext ctxt)
+    /**
+     * Return a boolean value indicating if Id transparency is on or not.
+     * @return true of Id Transarency is being supported
+     */
+    public static boolean isIdTransparency()
     {
-        if (_transparent != null)
-            return _transparent.booleanValue();
+        // initialize the state if it has not been initialized yet.
+        if (_transparent == TRAN_UNKNOWN) {
+            JspTagConfig tagConfig = ConfigUtil.getConfig().getJspTagConfig();
+            if (tagConfig != null) {
+                String tran = tagConfig.getIdTransparency();
+                if (tran != null) {
+                    if (tran.equals(TRAN_ON_VAL)) {
+                        _transparent = TRAN_ON;
+                    }
+                    else if (tran.equals(TRAN_OFF_VAL)) {
+                        _transparent = TRAN_OFF;
+                    }
+                    else {
+                        _transparent = TRAN_DEFAULT;
+                    }
+                }
+                else {
+                    _transparent = TRAN_DEFAULT;
+                }
+            }
+            else {
+                _transparent = TRAN_DEFAULT;
+            }
+            System.err.println("Transparency:" + _transparent);
+        }
 
-        String s = ctxt.getInitParameter(ID_TRANSPARENCY);
-        System.err.println("Id Transparency:" + s);
-        _transparent = new Boolean(s);
-        return _transparent.booleanValue();
+        // return true of Transparency is on
+        return (_transparent == TRAN_ON);
     }
 
+    /**
+     * Given a Base64 encoded string that has name/value pair separated by the 
<code>SPLIT_CHAR</code>
+     * return a <code>HashMap</code> of the values.  The expression is Base64 
encoded.
+     * @param expressions a Base64 encoded string containing the name/value 
pairs
+     * @return a HashMap of the name/value pairs.
+     */
     public static HashMap getExpressionMap(String expressions)
     {
         assert(expressions != null) : "Parameter 'expressions' must not be 
null";
 
         try {
             String ex = new 
String(Base64.decode(expressions.getBytes(CHARSET)), CHARSET);
-            String[] expr = ex.split(SPLIT);
+            String[] expr = ex.split(SPLIT_CHAR);
             assert((expr.length % 2) == 0) : "Verify that there is an even 
number of values failed";
             HashMap map = new HashMap(expr.length * 2 + 3);
             for (int i = 1; i < expr.length; i += 2) {
                 map.put(expr[i - 1], expr[i]);
-                //System.err.println("Expand key '" + expr[i-1] + "' value '" 
+ expr[i] + "'");
             }
             return map;
         }
         catch (UnsupportedEncodingException ex) {
+            // @todo: need to do the error reporting here.
             System.err.println("Unexpected Exception:" + ex);
         }
         return null;
-
     }
 
+    /**
+     * @param id
+     * @param expression
+     * @return
+     */
     public String writeId(String id, String expression)
     {
-        if (!_transparent.booleanValue())
+        if (!isIdTransparency())
             return expression;
 
         if (_idString == null)
             _idString = new StringBuilder(64);
 
         if (_idString.length() > 0)
-            _idString.append(SPLIT);
+            _idString.append(SPLIT_CHAR);
         _idString.append(id);
-        _idString.append(SPLIT);
+        _idString.append(SPLIT_CHAR);
         _idString.append(expression);
         return id;
     }
 
+    /**
+     * @return
+     */
     public String getExpressions()
     {
         String nameExpressions = _idString.toString();
@@ -85,10 +129,10 @@
             return encoded;
         }
         catch (UnsupportedEncodingException ex) {
+            // @todo: error reporting here
             System.err.println("Unexpected Exception:" + ex);
 
         }
         return null;
-
     }
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
        (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
        Fri Nov 19 08:25:09 2004
@@ -17,10 +17,15 @@
  */
 package org.apache.beehive.netui.tags;
 
+/**
+ * Define an interface for creating and handling id values in HTML elements.
+ */
 public interface IHtmlIdWriter
 {
+    /**
+     * This is the prefix for all generated id values.
+     */
     public final String ID_PREFIX = "netui";
-    public final String ID_REQUEST_ATTRIBUTE = "netuiIdGenerator";
 
     /**
      * This method will add a id and expression to the map maintained by the 
implementor.  This map should be
@@ -32,7 +37,8 @@
     String writeId(String id, String expression);
 
     /**
-     * Return the next id
+     * This will return a unique id across the request.
+     * @return the next id
      */
     String getNextId();
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    Fri Nov 19 08:25:09 2004
@@ -189,9 +189,20 @@
 public class Form extends HtmlBaseTag
         implements URLParams, IHtmlIdWriter
 {
+    /**
+     * This is the name of the counter stored in the request used to genereate 
the
+     * next autogenerated id.  This is used by the IHtmlIdWriter.getNextId() 
method implemented
+     * by the form.
+     */
+    public final String ID_REQUEST_ATTRIBUTE = "netuiIdGenerator";
+
+    // unique name of the form
     private static String FORM_ID = "Netui_Form_";
 
+    // The form state
     private FormTag.State _state = new FormTag.State();
+
+    // state variable for any hidden values
     private InputHiddenTag.State _hiddenState = new InputHiddenTag.State();
 
     private String _focus = null;                  // The name of the field to 
receive focus, if any.
@@ -520,6 +531,7 @@
         return _beanName;
     }
 
+    //*********************************************  IHtmlIdWriter interface 
*******************************************
     /**
      * This method will add a id and expression to the map maintained by the 
implementor.  This map should be
      * written to the form as a set of hidden fields that will contain the id.
@@ -543,6 +555,7 @@
     }
 
 
+    //********************************************* Do the Work  
*******************************************************
     /**
      * Render the beginning of this form.
      * @throws JspException if a JSP exception has occurred
@@ -777,7 +790,7 @@
         ImplicitObjectUtil.unloadActionForm(pageContext);
 
         // output the hidden fields for id transparency if this is turned on
-        if (IdMapper.isIdTransparency(servletContext) && _idMapper != null) {
+        if (IdMapper.isIdTransparency() && _idMapper != null) {
             String encoded = _idMapper.getExpressions();
             writeHiddenParam(ProcessPopulate.IDMAP_PARAMETER_NAME, encoded, 
writer, request,false);
             writer.append("\n");

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
     (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
     Fri Nov 19 08:25:09 2004
@@ -151,7 +151,6 @@
         // JSP 2.0 EL will convert a null into a empty string "". If we get a 
"" we will display an error.
         AbstractHtmlState tsh = getState();
         tsh.id = setRequiredValueAttribute(tagId, "tagId");
-        ;
     }
 
     /**

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/rendering/TagRenderingBase.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/rendering/TagRenderingBase.java
   (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/rendering/TagRenderingBase.java
   Fri Nov 19 08:25:09 2004
@@ -351,6 +351,19 @@
             return (TagRenderingBase) o;
         }
 
+        public static boolean isXHTML(ServletRequest req)
+        {
+            Html html = (Html) req.getAttribute(Html.HTML_TAG_ID);
+
+            // the default is html 4.0
+            int renderingType = _defaultDocType;
+            if (html != null) {
+                renderingType = html.getTargetDocumentType();
+            }
+
+            return (renderingType == XHTML_RENDERING);
+        }
+
         /**
          * @param req
          * @return ConstantRendering

Modified: incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
==============================================================================
--- incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd      
(original)
+++ incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd      Fri Nov 
19 08:25:09 2004
@@ -79,7 +79,7 @@
     <xsd:complexType name="jsp-tag-config">
         <xsd:sequence>
             <xsd:element name="doctype" type="xsd:string" minOccurs="0" 
maxOccurs="1"/>
-            <xsd:element name="id-transparency" type="xsd:boolean" 
minOccurs="0" maxOccurs="1" default="false"/>
+            <xsd:element name="id-transparency" type="xsd:string" 
minOccurs="0" maxOccurs="1" default="false"/>
         </xsd:sequence>
     </xsd:complexType>
        

Modified: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
       (original)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
       Fri Nov 19 08:25:09 2004
@@ -53,6 +53,7 @@
 
     <jsp-tag-config>
        <doctype>html4-loose</doctype>
+       <id-transparency>Transparent Off</id-transparency>
     </jsp-tag-config>
 
     <iterator-factories>

Reply via email to