You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/03/13 21:14:52 UTC

svn commit: r385648 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces: component/html/util/StreamingAddResource.java renderkit/html/util/AddResource.java renderkit/html/util/DefaultAddResource.java

Author: imario
Date: Mon Mar 13 12:14:50 2006
New Revision: 385648

URL: http://svn.apache.org/viewcvs?rev=385648&view=rev
Log:
allow to add javascript without encoding (without sessionId) to workaround a dojo bug.
methods are deprecated as they might not stay for a long time here

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/StreamingAddResource.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/StreamingAddResource.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/StreamingAddResource.java?rev=385648&r1=385647&r2=385648&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/StreamingAddResource.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/StreamingAddResource.java Mon Mar 13 12:14:50 2006
@@ -272,6 +272,17 @@
         writer.endElement(HTML.SCRIPT_ELEM);
     }
 
+	public void addJavaScriptHerePlain(FacesContext context, String uri) throws IOException
+	{
+        ResponseWriter writer = context.getResponseWriter();
+
+        writer.startElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_ELEM, null);
+        writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_ATTR, org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+        String src = getResourceUri(context, uri);
+        writer.writeURIAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SRC_ATTR, src, null);
+        writer.endElement(HTML.SCRIPT_ELEM);
+	}
+
     /**
      * Insert a [script src="url"] entry at the current location in the response.
      *
@@ -361,7 +372,7 @@
     {
         addJavaScriptAtPosition(context, position, resourceHandler, false);
     }
-
+    
     /**
      * Insert a [script src="url"] entry into the document header at the
      * specified document position. If the script has already been
@@ -381,6 +392,13 @@
                 myfacesCustomComponent, resourceName));
     }
 
+	public void addJavaScriptAtPositionPlain(FacesContext context, ResourcePosition position, Class myfacesCustomComponent, String resourceName)
+	{
+        addJavaScriptAtPosition(context, position,
+        		new MyFacesResourceHandler(myfacesCustomComponent, resourceName),
+        		false, false);
+	}
+
     /**
      * Insert a [script src="url"] entry into the document header at the
      * specified document position. If the script has already been
@@ -444,11 +462,16 @@
      * Adds the given Javascript resource at the specified document position.
      * If the script has already been referenced, it's added only once.
      */
-    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
-            ResourceHandler resourceHandler, boolean defer)
+	public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position, ResourceHandler resourceHandler, boolean defer)
+	{
+		addJavaScriptAtPosition(context, position, resourceHandler, defer, false);
+	}
+
+    private void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
+            ResourceHandler resourceHandler, boolean defer, boolean encodeURL)
     {
         validateResourceHandler(resourceHandler);
-    	WritablePositionedInfo info = (WritablePositionedInfo) getScriptInstance(context, resourceHandler, defer);
+    	WritablePositionedInfo info = (WritablePositionedInfo) getScriptInstance(context, resourceHandler, defer, encodeURL);
     	if (checkAlreadyAdded(info))
     	{
     		return;
@@ -823,9 +846,9 @@
     }
 
     private PositionedInfo getScriptInstance(FacesContext context, ResourceHandler resourceHandler,
-            boolean defer)
+            boolean defer, boolean encodeUrl)
     {
-        return new ScriptPositionedInfo(getResourceUri(context, resourceHandler), defer);
+        return new ScriptPositionedInfo(getResourceUri(context, resourceHandler), defer, encodeUrl);
     }
 
     private StylePositionedInfo getStyleInstance(FacesContext context, String uri)
@@ -933,16 +956,27 @@
             WritablePositionedInfo
     {
         protected final boolean _defer;
+        protected final boolean _encodeUrl;
 
         public ScriptPositionedInfo(String resourceUri, boolean defer)
         {
+            this(resourceUri, defer, true);
+        }
+        
+        public ScriptPositionedInfo(String resourceUri, boolean defer, boolean encodeUrl)
+        {
             super(resourceUri);
             _defer = defer;
+            _encodeUrl = encodeUrl;
         }
 
         public int hashCode()
         {
-            return new HashCodeBuilder().append(this.getResourceUri()).append(_defer).toHashCode();
+            return new HashCodeBuilder()
+            	.append(this.getResourceUri())
+            	.append(_defer)
+            	.append(_encodeUrl)
+            	.toHashCode();
         }
 
         public boolean equals(Object obj)
@@ -952,7 +986,10 @@
                 if (obj instanceof ScriptPositionedInfo)
                 {
                     ScriptPositionedInfo other = (ScriptPositionedInfo) obj;
-                    return new EqualsBuilder().append(_defer, other._defer).isEquals();
+                    return new EqualsBuilder()
+                    	.append(_defer, other._defer)
+                    	.append(_encodeUrl, other._encodeUrl)
+                    	.isEquals();
                 }
             }
             return false;
@@ -963,7 +1000,14 @@
         {
             writer.startElement(HTML.SCRIPT_ELEM, null);
             writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-            writer.writeAttribute(HTML.SRC_ATTR, response.encodeURL(this.getResourceUri()), null);
+            if (_encodeUrl)
+            {
+            	writer.writeAttribute(HTML.SRC_ATTR, response.encodeURL(this.getResourceUri()), null);
+            }
+            else
+            {
+            	writer.writeAttribute(HTML.SRC_ATTR, this.getResourceUri(), null);
+            }
 
             if (_defer)
             {

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java?rev=385648&r1=385647&r2=385648&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java Mon Mar 13 12:14:50 2006
@@ -66,6 +66,17 @@
     public void addJavaScriptHere(FacesContext context, String uri) throws IOException;
 
     /**
+     * Insert a [script src="url"] entry at the current location in the response.<br />
+     * In constrast to the other methods this will not encode the url. So
+     * ,depending on the use case, it wont work in cookie-only environments.
+     *
+     * @param uri is the location of the desired resource, relative to the base
+     * directory of the webapp (ie its contextPath).
+     * @deprecated just to help to workaround a dojo bug
+     */
+    public void addJavaScriptHerePlain(FacesContext context, String uri) throws IOException;
+    
+    /**
      * Insert a [script src="url"] entry at the current location in the response.
      *
      * @param context
@@ -156,6 +167,17 @@
     public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
             ResourceHandler resourceHandler, boolean defer);
 
+    /**
+     * Adds the given Javascript resource at the specified document position.
+     * If the script has already been referenced, it's added only once.<br />
+     * In constrast to the other methods this will not encode the url. So
+     * ,depending on the use case, it wont work in cookie-only environments.
+     * 
+     * @deprecated just to help to workaround a dojo bug
+     */
+    public void addJavaScriptAtPositionPlain(FacesContext context, ResourcePosition position,
+    		Class myfacesCustomComponent, String resourceName);
+    
     /**
      * Adds the given Style Sheet at the specified document position.
      * If the style sheet has already been referenced, it's added only once.

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java?rev=385648&r1=385647&r2=385648&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java Mon Mar 13 12:14:50 2006
@@ -150,6 +150,17 @@
         writer.endElement(HTML.SCRIPT_ELEM);
     }
 
+	public void addJavaScriptHerePlain(FacesContext context, String uri) throws IOException
+	{
+        ResponseWriter writer = context.getResponseWriter();
+
+        writer.startElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_ELEM, null);
+        writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_ATTR, org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+        String src = getResourceUri(context, uri);
+        writer.writeURIAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SRC_ATTR, src, null);
+        writer.endElement(HTML.SCRIPT_ELEM);
+	}
+	
     /**
      * Insert a [script src="url"] entry at the current location in the response.
      *
@@ -256,6 +267,14 @@
         addJavaScriptAtPosition(context, position, new MyFacesResourceHandler(
                 myfacesCustomComponent, resourceName));
     }
+    
+	public void addJavaScriptAtPositionPlain(FacesContext context, ResourcePosition position, Class myfacesCustomComponent, String resourceName)
+	{
+        addJavaScriptAtPosition(context, position,
+        		new MyFacesResourceHandler(myfacesCustomComponent, resourceName),
+        		false, false);
+	}
+	
 
     /**
      * Insert a [script src="url"] entry into the document header at the
@@ -318,6 +337,13 @@
         addPositionedInfo(position, getScriptInstance(context, resourceHandler, defer));
     }
 
+    private void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
+            ResourceHandler resourceHandler, boolean defer, boolean encodeUrl)
+	{
+		validateResourceHandler(resourceHandler);
+		addPositionedInfo(position, getScriptInstance(context, resourceHandler, defer, encodeUrl));
+	}
+    
     /**
      * Adds the given Style Sheet at the specified document position.
      * If the style sheet has already been referenced, it's added only once.
@@ -795,6 +821,12 @@
         return new ScriptPositionedInfo(getResourceUri(context, resourceHandler), defer);
     }
 
+    private PositionedInfo getScriptInstance(FacesContext context, ResourceHandler resourceHandler,
+            boolean defer, boolean encodeURL)
+    {
+   		return new ScriptPositionedInfo(getResourceUri(context, resourceHandler), defer, encodeURL);
+    }
+    
     private PositionedInfo getStyleInstance(FacesContext context, String uri)
     {
         return new StylePositionedInfo(getResourceUri(context, uri));
@@ -911,11 +943,18 @@
             WritablePositionedInfo
     {
         protected final boolean _defer;
+        protected final boolean _encode;
 
         public ScriptPositionedInfo(String resourceUri, boolean defer)
         {
+            this(resourceUri, defer, true);
+        }
+        
+        public ScriptPositionedInfo(String resourceUri, boolean defer, boolean encodeUrl)
+        {
             super(resourceUri);
             _defer = defer;
+            _encode = encodeUrl;
         }
 
         public int hashCode()
@@ -930,7 +969,10 @@
                 if (obj instanceof ScriptPositionedInfo)
                 {
                     ScriptPositionedInfo other = (ScriptPositionedInfo) obj;
-                    return new EqualsBuilder().append(_defer, other._defer).isEquals();
+                    return new EqualsBuilder()
+	                    .append(_defer, other._defer)
+	                    .append(_encode, other._encode)
+	                    .isEquals();
                 }
             }
             return false;
@@ -941,7 +983,14 @@
         {
             writer.startElement(HTML.SCRIPT_ELEM, null);
             writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-            writer.writeAttribute(HTML.SRC_ATTR, response.encodeURL(this.getResourceUri()), null);
+            if (_encode)
+            {
+            	writer.writeAttribute(HTML.SRC_ATTR, response.encodeURL(this.getResourceUri()), null);
+            }
+            else
+            {
+            	writer.writeAttribute(HTML.SRC_ATTR, this.getResourceUri(), null);
+            }
 
             if (_defer)
             {