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:01:39 UTC

svn commit: r1067202 - in /myfaces/tobago/branches/tobago-1.0.x: core/src/main/java/org/apache/myfaces/tobago/context/ theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/

Author: lofwyr
Date: Fri Feb  4 16:01:39 2011
New Revision: 1067202

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

Modified:
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java?rev=1067202&r1=1067201&r2=1067202&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java Fri Feb  4 16:01:39 2011
@@ -23,6 +23,7 @@ import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 public class ResourceManagerUtil {
 
@@ -147,4 +148,23 @@ public class ResourceManagerUtil {
   public static String getPageWithoutContextPath(FacesContext facesContext, String name) {
     return ResourceManagerFactory.getResourceManager(facesContext).getImage(facesContext.getViewRoot(), 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/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java?rev=1067202&r1=1067201&r2=1067202&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java Fri Feb  4 16:01:39 2011
@@ -24,9 +24,6 @@ package org.apache.myfaces.tobago.render
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DEFAULT_COMMAND;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TRANSITION;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIButtonCommand;
 import org.apache.myfaces.tobago.context.ResourceManagerUtil;
@@ -45,6 +42,10 @@ import javax.faces.component.UIComponent
 import javax.faces.context.FacesContext;
 import java.io.IOException;
 
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DEFAULT_COMMAND;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TRANSITION;
+
 public class ButtonRenderer extends CommandRendererBase {
 
   private static final Log LOG = LogFactory.getLog(ButtonRenderer.class);
@@ -91,15 +92,12 @@ public class ButtonRenderer extends Comm
     writer.flush(); // force closing the start tag
 
 
-    String imageName = (String) command.getAttributes().get(ATTR_IMAGE);
-    if (imageName != null) {
-      String image;
-      if (imageName.startsWith("HTTP:") || imageName.startsWith("FTP:")
-          || imageName.startsWith("/")) {
-        image = imageName;
+    String image = (String) command.getAttributes().get(ATTR_IMAGE);
+    if (image != null) {
+      if (ResourceManagerUtil.isAbsoluteResource(image)) {
         // absolute Path to image : nothing to do
       } else {
-        image = ResourceManagerUtil.getImageWithPath(facesContext, imageName, helper);
+        image = ResourceManagerUtil.getImageWithPath(facesContext, image, helper);
       }
       writer.startElement(HtmlConstants.IMG, null);
       writer.writeAttribute(HtmlAttributes.SRC, image, true);
@@ -108,7 +106,7 @@ public class ButtonRenderer extends Comm
     }
 
     if (label.getText() != null) {
-      if (imageName != null) {
+      if (image != null) {
         writer.writeText(" "); // separator: e.g.  
       }
       HtmlRendererUtil.writeLabelWithAccessKey(writer, label);

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java?rev=1067202&r1=1067201&r2=1067202&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ImageRenderer.java Fri Feb  4 16:01:39 2011
@@ -24,10 +24,6 @@ package org.apache.myfaces.tobago.render
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALT;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_BORDER;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.context.ResourceManagerUtil;
 import org.apache.myfaces.tobago.renderkit.LayoutableRendererBase;
@@ -41,7 +37,11 @@ import javax.faces.component.UIComponent
 import javax.faces.component.UIGraphic;
 import javax.faces.context.FacesContext;
 import java.io.IOException;
-import java.util.Locale;
+
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALT;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_BORDER;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
 
 public class ImageRenderer extends LayoutableRendererBase {
   
@@ -58,9 +58,7 @@ public class ImageRenderer extends Layou
     final String value = graphic.getUrl();
     String src = value;
     if (src != null) {
-      final String ucSrc = src.toUpperCase(Locale.ENGLISH);
-      if (ucSrc.startsWith("HTTP:") || ucSrc.startsWith("FTP:")
-          || ucSrc.startsWith("/")) {
+      if (ResourceManagerUtil.isAbsoluteResource(src)) {
         // absolute Path to image : nothing to do
       } else {
         src = null;

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java?rev=1067202&r1=1067201&r2=1067202&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java Fri Feb  4 16:01:39 2011
@@ -24,8 +24,6 @@ package org.apache.myfaces.tobago.render
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UICommand;
 import org.apache.myfaces.tobago.component.UILinkCommand;
@@ -44,6 +42,9 @@ import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import java.io.IOException;
 
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
+
 public class LinkRenderer extends CommandRendererBase {
 
   private static final Log LOG = LogFactory.getLog(LinkRenderer.class);
@@ -90,7 +91,7 @@ public class LinkRenderer extends Comman
 //  image
     String image = (String) command.getAttributes().get(ATTR_IMAGE);
     if (image != null) {
-      if (image.startsWith("HTTP:") || image.startsWith("FTP:") || image.startsWith("/")) {
+      if (ResourceManagerUtil.isAbsoluteResource(image)) {
         // absolute Path to image : nothing to do
       } else {
         image = ResourceManagerUtil.getImageWithPath(facesContext, image, helper);

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=1067202&r1=1067201&r2=1067202&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Fri Feb  4 16:01:39 2011
@@ -57,7 +57,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -255,8 +254,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 (ResourceManagerUtil.isAbsoluteResource(icon)) {
         // absolute Path to image : nothing to do
       } else {
         icon = ResourceManagerUtil.getImageWithPath(facesContext, icon);
@@ -609,12 +607,9 @@ public class PageRenderer extends PageRe
     }
   }
 
-  private void addScripts(TobagoResponseWriter writer, FacesContext facesContext,
-      String script) throws IOException {
+  private void addScripts(TobagoResponseWriter writer, FacesContext facesContext, String script) throws IOException {
     List<String> scripts;
-    final String ucScript = script.toUpperCase(Locale.ENGLISH);
-    if (ucScript.startsWith("HTTP:") || ucScript.startsWith("FTP:")
-        || ucScript.startsWith("/")) {
+    if (ResourceManagerUtil.isAbsoluteResource(script)) {
       scripts = new ArrayList<String>();
       scripts.add(script);
     } else {