You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by jw...@apache.org on 2007/03/28 22:40:29 UTC

svn commit: r523490 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal: skin/SkinStyleSheetParserUtils.java style/util/CSSUtils.java

Author: jwaldman
Date: Wed Mar 28 15:40:28 2007
New Revision: 523490

URL: http://svn.apache.org/viewvc?view=rev&rev=523490
Log:
fix bug I introduced recently in my url encoding refactoring
with skinning icons with absolute paths.
I was passing through absolute paths to URIImageIcon, but instead I should
only do that if it starts with http: and otherwise I resolve the absolute
paths relative to the skin's css file like we are supposed to do.
Thanks to Ted Farrell for reporting this to me.

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSUtils.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?view=diff&rev=523490&r1=523489&r2=523490
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Wed Mar 28 15:40:28 2007
@@ -56,6 +56,7 @@
 import org.apache.myfaces.trinidad.skin.Icon;
 import org.apache.myfaces.trinidadinternal.skin.icon.TextIcon;
 import org.apache.myfaces.trinidadinternal.skin.icon.URIImageIcon;
+import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
 import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
 import org.apache.myfaces.trinidadinternal.ui.laf.xml.parse.IconNode;
 import org.apache.myfaces.trinidadinternal.ui.laf.xml.parse.SkinPropertyNode;
@@ -189,6 +190,7 @@
     List<IconNode> iconNodeList = new ArrayList<IconNode>();
     List<SkinPropertyNode> skinPropertyNodeList = new ArrayList<SkinPropertyNode>();
     List<StyleSheetNode> ssNodeList = new ArrayList<StyleSheetNode>();
+    String baseSourceURI = CSSUtils.getBaseSkinStyleSheetURI(sourceName);
     
     for (SkinStyleSheetNode skinSSNode : skinSSNodeList) 
     {
@@ -229,7 +231,9 @@
             selectorName = selectorName.concat(StyleUtils.RTL_CSS_SUFFIX);
   
           // create an IconNode object and add it ot the iconNodeList
-          boolean addStyleNode = _addIconNode(selectorName,
+          boolean addStyleNode = _addIconNode(sourceName,
+                                              baseSourceURI,
+                                              selectorName,
                                               noTrPropertyList,
                                               iconNodeList);
           if (addStyleNode)
@@ -401,6 +405,8 @@
 
   /**
    * Create an IconNode and add it to the iconNodeList.
+   * @param sourceName
+   * @param baseSourceURI
    * @param selectorName
    * @param noTrPropertyNodeList
    * @param iconNodeList
@@ -408,6 +414,8 @@
    * property value of 'content:'. That means it is only css styles.
    */
   private static boolean _addIconNode(
+    String             sourceName,
+    String             baseSourceURI,
     String             selectorName,
     List<PropertyNode> noTrPropertyNodeList,
     List<IconNode>     iconNodeList)
@@ -531,8 +539,14 @@
         }
         else
         {
+          // a. if it has two slashes, strip off one.
+          // b. if it starts with http: don't do anything to the uri
+          // c. if it an absolute url, then it should be relative to
+          // the skin file since they wrote the absolute url in the skin file.
           if (startsWithTwoSlashes)
             uri = uri.substring(1);
+          else if (!(uri.startsWith("http:")))
+            uri = CSSUtils.getAbsoluteURIValue(sourceName, baseSourceURI, uri);
           icon =
             new URIImageIcon(uri, uri, width, height, null, inlineStyle);
         }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSUtils.java?view=diff&rev=523490&r1=523489&r2=523490
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSUtils.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSUtils.java Wed Mar 28 15:40:28 2007
@@ -168,6 +168,56 @@
       return buffer.toString();
     }
   }
+  
+  /**
+   * Convert a relative URI values to an absolute URI value.
+   * For example, if the baseURI is "/trinidad-context/skins/purple" and 
+   * the uri is "../../skins/purple/xyz.gif", we return 
+   * @param styleSheetName - the name of the Skin's stylesheet. We use this in any warning 
+   * messages.
+   * @param baseURI - absolute base URI pointing to the directory 
+   * which contains the skin style sheet. This is used to figure out the absolute uri of the uri
+   * parameter.
+   * @param uri - a uri. If this is an uri that begins with "../", then
+   * we convert it to be an absolute url that has no "../" at the start.
+
+   * @return An uri that does not begin with one or more "../" strings.
+   */
+  public static String getAbsoluteURIValue(
+    String styleSheetName,
+    String baseURI,
+    String uri)
+  {
+    String strippedURI = uri;
+    String strippedBaseURI = baseURI;
+
+    // Strip off leading "../" segments from the uri
+    while (strippedURI.startsWith("../"))
+    {
+      int lastSepIndex = strippedBaseURI.lastIndexOf('/');
+      if (lastSepIndex < 0)
+      {
+        _LOG.warning("Invalid image uri '" +
+                     uri +
+                     "' in style sheet '" +
+                     styleSheetName);
+
+        break;
+      }
+
+      strippedURI = strippedURI.substring(3);
+      strippedBaseURI = strippedBaseURI.substring(0, lastSepIndex);
+    }
+
+    StringBuilder builder = new StringBuilder(strippedBaseURI.length() +
+                                             strippedURI.length() +
+                                             2);
+    builder.append(strippedBaseURI);
+    builder.append("/");
+    builder.append(strippedURI);
+
+    return builder.toString();
+  }
 
   /**
    * Parse an inline style into a CSSStyle object.
@@ -863,7 +913,7 @@
       // e.g., if uri is "../../skins/purple/xyz.gif" and baseURI is /trinidad-context/skins/purple 
       // we get "/trinidad-context/skins/purple/xyz.gif"
       // 
-      resolvedURI = _getAbsoluteURIValue(styleSheetName, baseURI, uri);
+      resolvedURI = getAbsoluteURIValue(styleSheetName, baseURI, uri);
     }
     return externalContext.encodeResourceURL(resolvedURI);
 
@@ -880,56 +930,7 @@
     return ((uri.charAt(0) != '/') && (uri.indexOf(':') < 0));
   }
 
-  /**
-   * Convert a relative URI values to an absolute URI value.
-   * For example, if the baseURI is "/trinidad-context/skins/purple" and 
-   * the uri is "../../skins/purple/xyz.gif", we return 
-   * @param styleSheetName - the name of the Skin's stylesheet. We use this in any warning 
-   * messages.
-   * @param baseURI - absolute base URI pointing to the directory 
-   * which contains the skin style sheet. This is used to figure out the absolute uri of the uri
-   * parameter.
-   * @param uri - a uri. If this is an uri that begins with "../", then
-   * we convert it to be an absolute url that has no "../" at the start.
-
-   * @return An uri that does not begin with one or more "../" strings.
-   */
-  private static String _getAbsoluteURIValue(
-    String styleSheetName,
-    String baseURI,
-    String uri)
-  {
-    String strippedURI = uri;
-    String strippedBaseURI = baseURI;
-
-    // Strip off leading "../" segments from the uri
-    while (strippedURI.startsWith("../"))
-    {
-      int lastSepIndex = strippedBaseURI.lastIndexOf('/');
-      if (lastSepIndex < 0)
-      {
-        _LOG.warning("Invalid image uri '" +
-                     uri +
-                     "' in style sheet '" +
-                     styleSheetName);
-
-        break;
-      }
-
-      strippedURI = strippedURI.substring(3);
-      strippedBaseURI = strippedBaseURI.substring(0, lastSepIndex);
-    }
-
-    StringBuilder builder = new StringBuilder(strippedBaseURI.length() +
-                                             strippedURI.length() +
-                                             2);
-    builder.append(strippedBaseURI);
-    builder.append("/");
-    builder.append(strippedURI);
 
-    return builder.toString();
-  }
-  
   /**
    * Determines if the specified value contains a CSS url. The URLs are
    * detected by finding usage of url() function.