myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwald...@apache.org
Subject svn commit: r638062 - in /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin: RequestSkinWrapper.java SkinImpl.java SkinUtils.java
Date Mon, 17 Mar 2008 20:54:06 GMT
Author: jwaldman
Date: Mon Mar 17 13:54:02 2008
New Revision: 638062

URL: http://svn.apache.org/viewvc?rev=638062&view=rev
Log:
TRINIDAD-1009 ReferenceIcon referring to declarative icon not resolved
on trunk
patch provided by Andy Schwartz

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java?rev=638062&r1=638061&r2=638062&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java
Mon Mar 17 13:54:02 2008
@@ -31,6 +31,7 @@
 import org.apache.myfaces.trinidad.skin.SkinAddition;
 import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
 import org.apache.myfaces.trinidadinternal.skin.icon.NullIcon;
+import org.apache.myfaces.trinidadinternal.skin.icon.ReferenceIcon;
 import org.apache.myfaces.trinidadinternal.style.StyleContext;
 import org.apache.myfaces.trinidadinternal.style.StyleProvider;
 import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetDocument;
@@ -180,19 +181,24 @@
     
     if (icon == null)
     {  
-      icon = _skin.getIcon(iconName, resolveIcon);
-      
-      // We ended up having to do two lookups for icons
-      // which are not available in the StyleProvider
-      // icon map.  To avoid having to do two lookups
-      // the next time this icon is requested, we promote
-      // the icon up from the wrapped skin into the
-      // StyleProvider icon map.
-      //
-      // resolveIcon should always be true here, but just
-      // to be totally safe, avoid caching unresolved icons
+      icon = _skin.getIcon(iconName, false);
+
+      // Resolve ReferenceIcons if necessary
       if (resolveIcon)
+      {
+        if (icon instanceof ReferenceIcon)
+          icon = SkinUtils.resolveReferenceIcon(this, (ReferenceIcon)icon);
+
+        // We ended up having to do two lookups for icons
+        // which are not available in the StyleProvider
+        // icon map.  To avoid having to do two lookups
+        // the next time this icon is requested, we promote
+        // the icon up from the wrapped skin into the
+        // StyleProvider icon map.  Note that we only cache
+        // resolved icons in this way - we don't want to 
+        // pollute our cache with unresolved ReferenceIcons.
         registerIcon(iconName, icon);
+      }
     }
 
     return (icon == _NULL_ICON) ? null : icon;

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java?rev=638062&r1=638061&r2=638062&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
Mon Mar 17 13:54:02 2008
@@ -28,7 +28,6 @@
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import java.util.Set;
-import java.util.Stack;
 
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -220,8 +219,7 @@
       if (icon instanceof ReferenceIcon)
       {
         // find the true icon, not a ReferenceIcon
-        icon = _resolveReferenceIcon((ReferenceIcon)icon,
-                                     null);
+        icon = SkinUtils.resolveReferenceIcon(this, (ReferenceIcon)icon);
       }
     }
 
@@ -489,56 +487,6 @@
   * value expression. If they do, then the bundleName takes precedence.
   */
   abstract protected ValueBinding getTranslationSourceValueBinding();
-
-  /**
-   * Find the actual icon
-   * @param refIcon a ReferenceIcon instance
-   * @param referencedIconStack  The stack of reference icon names which have
-   *          already been visited.  Used to detect circular dependencies.
-   * @return icon which is resolved. i.e., it is not a ReferenceIcon.
-   */
-  private Icon _resolveReferenceIcon(
-    ReferenceIcon refIcon,
-    Stack<String> referencedIconStack)
-  {
-    String refName = refIcon.getName();
-
-    // make sure we don't have a circular dependency
-    if ( _stackContains(referencedIconStack, refName))
-    {
-      if (_LOG.isWarning())
-        _LOG.warning("CANNOT_GET_SKIN_FROM_SKINFACTORY", refName);
-      return null;
-    }
-
-    if (referencedIconStack == null)
-    {
-      referencedIconStack = new Stack<String>();
-    }
-
-    referencedIconStack.push(refName);
-
-    Icon icon = getIcon(refName, false);
-
-    if ((icon instanceof ReferenceIcon) && (icon != null))
-    {
-
-      return _resolveReferenceIcon((ReferenceIcon)icon,
-                                    referencedIconStack);
-
-    }
-
-    return icon;
-  }
-
-  // Tests whether the value is present in the (possibly null) stack.
-  private static boolean _stackContains(Stack<String> stack, Object value)
-  {
-    if (stack == null)
-      return false;
-
-    return stack.contains(value);
-  }
 
   // Checks to see whether any of our style sheets have been updated
   private boolean _checkStylesModified(

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java?rev=638062&r1=638061&r2=638062&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java
Mon Mar 17 13:54:02 2008
@@ -31,6 +31,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import java.util.Stack;
+
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
@@ -41,7 +43,7 @@
 import org.apache.myfaces.trinidad.skin.SkinFactory;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
-
+import org.apache.myfaces.trinidad.skin.Icon;
 import org.apache.myfaces.trinidad.skin.Skin;
 import org.apache.myfaces.trinidad.skin.SkinAddition;
 import org.apache.myfaces.trinidadinternal.config.LazyValueBinding;
@@ -64,6 +66,7 @@
 import org.apache.myfaces.trinidadinternal.share.xml.XMLProvider;
 import org.apache.myfaces.trinidadinternal.share.xml.XMLUtils;
 
+import org.apache.myfaces.trinidadinternal.skin.icon.ReferenceIcon;
 import org.apache.myfaces.trinidadinternal.skin.parse.XMLConstants;
 import org.apache.myfaces.trinidadinternal.skin.parse.SkinAdditionNode;
 import org.apache.myfaces.trinidadinternal.skin.parse.SkinNode;
@@ -124,6 +127,65 @@
 
     _registerSkinExtensionsAndAdditions(context, skinFactory);
 
+  }
+
+  /**
+   * Returns the actual Icon referenced by the ReferenceIcon.
+   * @param skin the Skin to use when resolving the ReferenceIcon
+   * @param refIcon a ReferenceIcon instance
+   * @return icon which is resolved. i.e., it is not a ReferenceIcon.
+   */
+   static public Icon resolveReferenceIcon(
+     Skin          skin,
+     ReferenceIcon refIcon)
+   {
+     return _resolveReferenceIcon(skin, refIcon, null);
+   }
+
+  /**
+   * Helper for resolveReferenceIcon which uses a Stack of icon names
+   * to detect circular dependencies.
+   *
+   * @param skin the Skin to use when resolving the ReferenceIcon
+   * @param refIcon a ReferenceIcon instance
+   * @param referencedIconStack  The stack of reference icon names which have
+   *          already been visited.  Used to detect circular dependencies.
+   * @return icon which is resolved. i.e., it is not a ReferenceIcon.
+   */
+  static private Icon _resolveReferenceIcon(
+    Skin          skin,
+    ReferenceIcon refIcon,
+    Stack<String> referencedIconStack)
+  {
+    String refName = refIcon.getName();
+
+    // make sure we don't have a circular dependency
+    if ((referencedIconStack != null) && referencedIconStack.contains(refName))
+    {
+      if (_LOG.isWarning())
+        _LOG.warning("SKIN_CIRCULAR_INCLUDE_ERROR", refName);
+      return null;
+    }
+
+    if (referencedIconStack == null)
+    {
+      referencedIconStack = new Stack<String>();
+    }
+
+    referencedIconStack.push(refName);
+
+    Icon icon = skin.getIcon(refName, false);
+
+    if ((icon instanceof ReferenceIcon) && (icon != null))
+    {
+
+      return _resolveReferenceIcon(skin,
+                                  (ReferenceIcon)icon,
+                                  referencedIconStack);
+
+    }
+
+    return icon;
   }
 
   /**



Mime
View raw message