You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/02/15 00:07:17 UTC

svn commit: r377873 - in /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo: DojoInitializer.java DojoInitializerRenderer.java DojoUtils.java

Author: werpu
Date: Tue Feb 14 15:07:14 2006
New Revision: 377873

URL: http://svn.apache.org/viewcvs?rev=377873&view=rev
Log:
fixed the djconfig, it now is a request singleton

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializerRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoUtils.java

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializer.java?rev=377873&r1=377872&r2=377873&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializer.java Tue Feb 14 15:07:14 2006
@@ -28,16 +28,21 @@
 public class DojoInitializer extends UIOutput
 {
     DojoConfig                 _dojoConfig           = new DojoConfig();
-    String                     _require             = null;
-    String                     _provide             = null;
-    Boolean                    _debugConsole        = null;
-    
+    String                     _require              = null;
+    String                     _provide              = null;
+    Boolean                    _debugConsole         = null;
+
+    //we handle that specifically to speed things up (we do not want an NxN runtime complexity via enforced
+    //reflection in the utils
+    boolean                    dojoConfigParamSet    = false;
+
     public static final String COMPONENT_TYPE        = "org.apache.myfaces.DojoInitializer";
     public static final String DEFAULT_RENDERER_TYPE = DojoInitializerRenderer.RENDERER_TYPE;
     public static final String COMPONENT_FAMILY      = "javax.faces.Output";
 
     public DojoInitializer()
     {
+        super();
         setRendererType(DEFAULT_RENDERER_TYPE);
     }
 
@@ -77,8 +82,8 @@
         _dojoConfig.setSearchIds((String) values[10]);
         _require = (String) values[11];
         _provide = (String) values[12];
-        _debugConsole = (Boolean)values[13];
-        _dojoConfig.setDebugAtAllCosts((Boolean)values[14]);
+        _debugConsole = (Boolean) values[13];
+        _dojoConfig.setDebugAtAllCosts((Boolean) values[14]);
     }
 
     public Object saveState(FacesContext context)
@@ -99,6 +104,7 @@
         values[12] = _provide;
         values[13] = _debugConsole;
         values[14] = _dojoConfig.getDebugAtAllCosts();
+
         return values;
     }
 
@@ -154,51 +160,106 @@
 
     public void setAllowQueryConfig(Boolean allowQueryConfig)
     {
+        if (allowQueryConfig != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setAllowQueryConfig(allowQueryConfig);
+        }
         _dojoConfig.setAllowQueryConfig(allowQueryConfig);
+       
     }
 
     public void setBaseScriptUri(String baseScriptUri)
     {
+        if (baseScriptUri != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setBaseScriptUri(baseScriptUri);
+        }
         _dojoConfig.setBaseScriptUri(baseScriptUri);
     }
 
     public void setBindEncoding(Boolean bindEncoding)
     {
+        if (bindEncoding != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setBindEncoding(bindEncoding);
+        }
+
         _dojoConfig.setBindEncoding(bindEncoding);
     }
 
     public void setDebug(Boolean debug)
     {
+        if (debug != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDebug(debug);
+        }
         _dojoConfig.setDebug(debug);
+    
     }
 
     public void setDebugContainerId(String debugContainerId)
     {
+        if (debugContainerId != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDebugContainerId(debugContainerId);
+        }
         _dojoConfig.setDebugContainerId(debugContainerId);
     }
 
     public void setIgnoreClassNames(Boolean ignoreClassNames)
     {
+        if (ignoreClassNames != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setIgnoreClassNames(ignoreClassNames);
+        }
         _dojoConfig.setIgnoreClassNames(ignoreClassNames);
     }
 
     public void setIoSendTransport(Boolean ioSendTransport)
     {
+        if (ioSendTransport != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setIoSendTransport(ioSendTransport);
+        }
         _dojoConfig.setIoSendTransport(ioSendTransport);
+      
     }
 
     public void setParseWidgets(Boolean parseWidgets)
     {
+        if (parseWidgets != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setParseWidgets(parseWidgets);
+        }
         _dojoConfig.setParseWidgets(parseWidgets);
     }
 
     public void setPreventBackButtonFix(Boolean preventBackButtonFix)
     {
+        if (preventBackButtonFix != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setPreventBackButtonFix(
+                    preventBackButtonFix);
+        }
         _dojoConfig.setPreventBackButtonFix(preventBackButtonFix);
     }
 
     public void setSearchIds(String searchIds)
     {
+        if (searchIds != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setSearchIds(searchIds);
+        }
         _dojoConfig.setSearchIds(searchIds);
     }
 
@@ -235,6 +296,30 @@
     public void setDebugConsole(Boolean debugConsole)
     {
         this._debugConsole = debugConsole;
+    }
+
+    public boolean isDojoConfigParamSet()
+    {
+        return dojoConfigParamSet;
+    }
+
+    public void setDojoConfigParamSet(boolean dojoConfigParamSet)
+    {
+        this.dojoConfigParamSet = dojoConfigParamSet;
+    }
+
+    public Boolean getDebugAtAllCosts() {
+        return _dojoConfig.getDebugAtAllCosts();
+    }
+    
+    public void setDebugAtAllCosts(Boolean debugAtAllCosts)
+    {
+        if (debugAtAllCosts != null)
+        {
+            dojoConfigParamSet = true;
+            DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDebugAtAllCosts(debugAtAllCosts);
+        }
+        _dojoConfig.setDebugAtAllCosts(debugAtAllCosts);
     }
 
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializerRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializerRenderer.java?rev=377873&r1=377872&r2=377873&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializerRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoInitializerRenderer.java Tue Feb 14 15:07:14 2006
@@ -32,8 +32,15 @@
  */
 public class DojoInitializerRenderer extends HtmlRenderer
 {
+
     public static final String RENDERER_TYPE = "org.apache.myfaces.DojoInitializerRenderer";
 
+    public void decode(FacesContext context, UIComponent component)
+    {
+        super.decode(context, component);
+
+    }
+
     /**
      * Encodes any stand-alone javascript functions that are needed. Uses either
      * the extension filter, or a user-supplied location for the javascript
@@ -47,17 +54,16 @@
     private void encodeJavascript(FacesContext context, UIComponent component) throws IOException
     {
         String javascriptLocation = (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
-        DojoUtils.addMainInclude(context, javascriptLocation, ((DojoInitializer) component).getDojoConfig());
+        DojoUtils.addMainInclude(context, javascriptLocation, DojoUtils.getDjConfigInstance(context));
         String require = (String) component.getAttributes().get("require");
         String provide = (String) component.getAttributes().get("provide");
-        
-        
+
         if (provide != null)
             DojoUtils.addProvide(context, component, provide);
- 
+
         if (require != null)
             DojoUtils.addRequire(context, component, require);
-        
+
     }
 
     public boolean getRendersChildren()
@@ -76,6 +82,7 @@
 
         if ((rendered != null) && (!rendered.booleanValue()))
             return;
+
         super.encodeBegin(context, component);
 
     }
@@ -87,9 +94,11 @@
     public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException
     {
         super.encodeEnd(facesContext, component);
-        
+
         encodeJavascript(facesContext, component);
-        if(((DojoInitializer)component).getDebugConsole() != null && ((DojoInitializer)component).getDebugConsole().booleanValue()) {
+        if (((DojoInitializer) component).getDebugConsole() != null
+                && ((DojoInitializer) component).getDebugConsole().booleanValue())
+        {
             DojoUtils.addDebugConsole(facesContext, component);
         }
     }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoUtils.java?rev=377873&r1=377872&r2=377873&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoUtils.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoUtils.java Tue Feb 14 15:07:14 2006
@@ -17,6 +17,9 @@
 package org.apache.myfaces.custom.dojo;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -25,6 +28,9 @@
 import javax.faces.context.ResponseWriter;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer;
 import org.apache.myfaces.renderkit.html.HTML;
 import org.apache.myfaces.renderkit.html.util.AddResource;
 import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
@@ -42,7 +48,7 @@
  */
 public final class DojoUtils
 {
-
+    private static final Log    log              = LogFactory.getLog(DojoUtils.class);
     private static final String DOJO_PROVIDE     = "dojo.provide:";
     private static final String DOJO_REQUIRE     = "dojo.require:";
     private static final String DJCONFIG_INITKEY = "/*djconfig init*/";
@@ -55,12 +61,98 @@
     private static final String BODY_SCRIPT_INFOS_ATTRIBUTE_NAME = "bodyScriptInfos";
     private static final String DOJO_FILE_UNCOMPRESSED           = "dojo.js.uncompressed.js";
     private static final String DOJO_FILE                        = "dojo.js";
+    private static final String DJCONFIG_REQ_KEY                 = "MYFACES_DJCONFIG";
 
     /**
      * dojo utils flag which can be altered for various states of the dojo lib
      */
     public static final boolean DOJO_COMPRESSED                  = false;
     public static final boolean DOJO_DEBUG                       = false;
+
+    /**
+     * Request singleton getter method for the djConfig object
+     * 
+     * @param context
+     * @return
+     */
+    public static DojoConfig getDjConfigInstance(FacesContext context)
+    {
+        //we wont have a need for a synchronized here, since 
+        //we are in a single request cycle anyway
+        //but take care if you use the djconfig in multiple threads!
+        DojoConfig djConfig = (DojoConfig) ((HttpServletRequest) context.getExternalContext().getRequest())
+                .getAttribute(DJCONFIG_REQ_KEY);
+        if (djConfig == null)
+        {
+            djConfig = new DojoConfig();
+            ((HttpServletRequest) context.getExternalContext().getRequest()).setAttribute(DJCONFIG_REQ_KEY, djConfig);
+        }
+        return djConfig;
+    }
+
+    /**
+     * helper to merge in an external dojo config instance
+     * the merge algorithm is that an existing entry is overwritten
+     * if a new config entry is set
+     * make sure that this is not called too often
+     * due to the fact that we do heavy reflection in here
+     * @param context
+     * @param config
+     */
+    public static void mergeExternalDjConfig(FacesContext context, DojoConfig config)
+    {
+        //we now do the same as beanutils, but for dependency reasons we code it
+            DojoConfig configSingleton = getDjConfigInstance(context);
+            Class dcConfigClass = DojoConfig.class;
+            Method[] djConfigFieldArr = dcConfigClass.getMethods();
+            for (int cnt = 0; cnt < djConfigFieldArr.length; cnt++)
+            {
+                
+                try
+                {
+                    Method configPropertyField = djConfigFieldArr[cnt];
+                    String methodCore = null;
+                    if(!configPropertyField.getName().startsWith("getClass") && configPropertyField.getName().startsWith("get") || configPropertyField.getName().startsWith("is"))
+                        methodCore = (configPropertyField.getName().startsWith("get")) ? configPropertyField.getName().substring(3) : configPropertyField.getName().substring(2);
+                        
+                    
+                    if (methodCore != null) {
+                        Object val = configPropertyField.invoke(config,null);
+                        if(val != null) {
+                            Class [] setterParams = new Class[1];
+                            setterParams[0] = val.getClass();
+                            Method setMethod = dcConfigClass.getMethod("set"+methodCore, setterParams);
+                            if(setMethod != null) {
+                                Object [] setterArgs = new Object[1];
+                                setterArgs[0] = val;
+                                setMethod.invoke(configSingleton, setterArgs);
+                            }    
+                        }
+                    }
+                }
+                catch (IllegalArgumentException e)
+                {
+                    log.error(e);
+                }
+                catch (SecurityException e)
+                {
+                    log.error(e);
+                }
+                catch (IllegalAccessException e)
+                {
+                    log.error(e);
+                }
+                catch (InvocationTargetException e)
+                {
+                    log.error(e);
+                }
+                catch (NoSuchMethodException e)
+                {
+                    log.error(e);
+                }    
+            }
+   
+    }
 
     public static void addMainInclude(FacesContext context, String javascriptLocation, DojoConfig config)
     {