Author: ate
Date: Thu Sep  6 04:08:08 2007
New Revision: 573219

URL: http://svn.apache.org/viewvc?rev=573219&view=rev
Log:
WICKET-654: New Wicket Portlet support: translating Wicket relative paths back 
to fully qualified paths for usage in a portlet context
See: https://issues.apache.org/jira/browse/WICKET-654
- adding support for src and href AttributeModifier usage (e.g. as used in the 
staticpages examples)
  Note: This can *only* work for initial static page access. If the rendered 
page itself contains wicket relative urls, those won't be translated!

Modified:
    
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/AttributeModifier.java

Modified: 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/AttributeModifier.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/AttributeModifier.java?rev=573219&r1=573218&r2=573219&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/AttributeModifier.java
 (original)
+++ 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/AttributeModifier.java
 Thu Sep  6 04:08:08 2007
@@ -21,6 +21,7 @@
 import org.apache.wicket.markup.parser.XmlTag;
 import org.apache.wicket.model.IComponentAssignedModel;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.protocol.http.portlet.PortletRequestContext;
 import org.apache.wicket.util.value.IValueMap;
 
 /**
@@ -281,7 +282,7 @@
                                                final String newValue = 
newValue(value, toStringOrNull(replacementValue));
                                                if (newValue != null)
                                                {
-                                                       
attributes.put(attribute, newValue);
+                                                       
attributes.put(attribute, getContextRelativeValue(newValue));
                                                }
                                        }
                                }
@@ -290,11 +291,31 @@
                                        final String newValue = newValue(null, 
toStringOrNull(replacementValue));
                                        if (newValue != null)
                                        {
-                                               attributes.put(attribute, 
newValue);
+                                               attributes.put(attribute, 
getContextRelativeValue(newValue));
                                        }
                                }
                        }
                }
+       }
+       
+       protected String getContextRelativeValue(String value)
+       {
+               if ("href".equals(attribute) || "src".equals(attribute))
+               {
+                       RequestContext rc = RequestContext.get();
+                       if (rc.isPortletRequest() && 
!(value.startsWith("http://";) || value.startsWith("https://";)))
+                       {
+                               if ("href".equals(attribute))
+                               {
+                                       value = 
((PortletRequestContext)rc).encodeRenderURL(value).toString();
+                               }
+                               else
+                               {
+                                       value = 
((PortletRequestContext)rc).encodeSharedResourceURL(value).toString();
+                               }
+                       }
+               }
+               return value;
        }
 
        /**


Reply via email to