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 2011/02/04 17:04:16 UTC

svn commit: r1067203 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/context/ tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/context/ tobago-theme/tobago-theme-scarborough/src/main/java/org/a...

Author: lofwyr
Date: Fri Feb  4 16:04:16 2011
New Revision: 1067203

URL: http://svn.apache.org/viewvc?rev=1067203&view=rev
Log:
TOBAGO-971: Resources should also detect HTTPS as protocol
 - also fixed some missing "ignore case"

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtils.java
    myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtils.java?rev=1067203&r1=1067202&r2=1067203&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtils.java Fri Feb  4 16:04:16 2011
@@ -23,6 +23,7 @@ import org.apache.myfaces.tobago.layout.
 import javax.faces.context.FacesContext;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 public class ResourceManagerUtils {
 
@@ -133,5 +134,23 @@ public class ResourceManagerUtils {
     return ResourceManagerFactory.getResourceManager(facesContext).getThemeMeasure(
         facesContext, configurable.getRendererType(), configurable.getCurrentMarkup(), name);
   }
-  
+
+  /**
+   * Detects if the value is an absolute resource or if the value has to be processed by the
+   * theme mechanism. A resource will be treated as absolute, if the value starts with HTTP:, HTTPS:, FTP: or a slash.
+   * The case will be ignored by this check. Null values will return true.
+   *
+   * @param value the given resource link.
+   * @return true if it is an external or absolute resource.
+   */
+  public static boolean isAbsoluteResource(String value) {
+    if (value == null) {
+      return true;
+    }
+    String upper = value.toUpperCase(Locale.ENGLISH);
+    return (upper.startsWith("/")
+        || upper.startsWith("HTTP:")
+        || upper.startsWith("HTTPS:")
+        || upper.startsWith("FTP:"));
+  }
 }

Modified: myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java?rev=1067203&r1=1067202&r2=1067203&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java (original)
+++ myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java Fri Feb  4 16:04:16 2011
@@ -183,4 +183,12 @@ public class ResourceManagerUtil {
     return ResourceManagerUtils.getThemeMeasure(facesContext, configurable, name);
   }
 
+  /**
+   * @deprecated please use {@link ResourceManagerUtils}
+   */
+  @Deprecated
+  public static boolean isAbsoluteResource(String value) {
+    return ResourceManagerUtils.isAbsoluteResource(value);
+  }
+  
 }

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java?rev=1067203&r1=1067202&r2=1067203&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java Fri Feb  4 16:04:16 2011
@@ -25,6 +25,7 @@ package org.apache.myfaces.tobago.render
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.UIButton;
 import org.apache.myfaces.tobago.config.Configurable;
+import org.apache.myfaces.tobago.context.ResourceManagerUtils;
 import org.apache.myfaces.tobago.internal.util.AccessKeyMap;
 import org.apache.myfaces.tobago.layout.Measure;
 import org.apache.myfaces.tobago.renderkit.CommandRendererBase;
@@ -79,15 +80,12 @@ public class ButtonRenderer extends Comm
     writer.writeClassAttribute(Classes.create(button));
     writer.flush(); // force closing the start tag
 
-    String imageName = (String) button.getAttributes().get(Attributes.IMAGE);
-    if (imageName != null) {
-      String image;
-      if (imageName.startsWith("HTTP:") || imageName.startsWith("FTP:")
-          || imageName.startsWith("/")) {
-        image = imageName;
+    String image = (String) button.getAttributes().get(Attributes.IMAGE);
+    if (image != null) {
+      if (ResourceManagerUtils.isAbsoluteResource(image)) {
         // absolute Path to image : nothing to do
       } else {
-        image = getImageWithPath(facesContext, imageName, helper.isDisabled());
+        image = getImageWithPath(facesContext, image, helper.isDisabled());
       }
       writer.startElement(HtmlElements.IMG, null);
       writer.writeAttribute(HtmlAttributes.SRC, image, true);
@@ -96,7 +94,7 @@ public class ButtonRenderer extends Comm
     }
 
     if (label.getText() != null) {
-      if (imageName != null) {
+      if (image != null) {
         writer.writeText(" "); // separator: e.g.  
       }
       HtmlRendererUtils.writeLabelWithAccessKey(writer, label);

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java?rev=1067203&r1=1067202&r2=1067203&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java Fri Feb  4 16:04:16 2011
@@ -34,7 +34,6 @@ import org.slf4j.LoggerFactory;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import java.io.IOException;
-import java.util.Locale;
 
 public class ImageRenderer extends LayoutComponentRendererBase {
 
@@ -53,9 +52,7 @@ public class ImageRenderer extends Layou
     final String value = image.getUrl();
     String src = value;
     if (src != null) {
-      final String ucSrc = src.toUpperCase(Locale.ENGLISH);
-      if (ucSrc.startsWith("HTTP:") || ucSrc.startsWith("FTP:")
-          || ucSrc.startsWith("/")) {
+      if (ResourceManagerUtils.isAbsoluteResource(src)) {
         // absolute Path to image : nothing to do
       } else {
         src = null;

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java?rev=1067203&r1=1067202&r2=1067203&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java Fri Feb  4 16:04:16 2011
@@ -25,6 +25,7 @@ package org.apache.myfaces.tobago.render
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.UICommand;
 import org.apache.myfaces.tobago.component.UILink;
+import org.apache.myfaces.tobago.context.ResourceManagerUtils;
 import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
 import org.apache.myfaces.tobago.internal.util.AccessKeyMap;
 import org.apache.myfaces.tobago.internal.util.Deprecation;
@@ -94,7 +95,7 @@ public class LinkRenderer extends Comman
 //  image
     String image = (String) link.getAttributes().get(Attributes.IMAGE);
     if (image != null) {
-      if (image.startsWith("HTTP:") || image.startsWith("FTP:") || image.startsWith("/")) {
+      if (ResourceManagerUtils.isAbsoluteResource(image)) {
         // absolute Path to image : nothing to do
       } else {
         image = getImageWithPath(facesContext, image, helper.isDisabled());

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=1067203&r1=1067202&r2=1067203&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Fri Feb  4 16:04:16 2011
@@ -220,8 +220,7 @@ public class PageRenderer extends PageRe
       String icon = page.getApplicationIcon();
       if (icon != null) {
         // XXX unify with image renderer
-        if (icon.startsWith("HTTP:") || icon.startsWith("FTP:")
-            || icon.startsWith("/")) {
+        if (ResourceManagerUtils.isAbsoluteResource(icon)) {
           // absolute Path to image : nothing to do
         } else {
           icon = ResourceManagerUtils.getImageWithPath(facesContext, icon);
@@ -680,9 +679,7 @@ public class PageRenderer extends PageRe
 
   private void encodeScript(FacesContext facesContext, TobagoResponseWriter writer, String script) throws IOException {
     List<String> list;
-    if (StringUtils.startsWith(script, "/") 
-        || StringUtils.startsWithIgnoreCase(script, "HTTP:")
-        || StringUtils.startsWithIgnoreCase(script, "FTP:")) {
+    if (ResourceManagerUtils.isAbsoluteResource(script)) {
       list = new ArrayList<String>();
       list.add(script);
     } else {