Author: ivaynberg
Date: Fri Sep 26 09:36:55 2008
New Revision: 699402

URL: http://svn.apache.org/viewvc?rev=699402&view=rev
Log:
consolidate context-relative path prfixing instead of doing it all over the 
place

Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/HeaderContributor.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/image/ContextPathGenerator.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/IRequestCodingStrategy.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/RedirectRequestTarget.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/HeaderContributor.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/HeaderContributor.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/HeaderContributor.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/HeaderContributor.java
 Fri Sep 26 09:36:55 2008
@@ -52,7 +52,7 @@
         *            The path
         * @return the new header contributor instance
         */
-       public static final HeaderContributor forCss(final Class< ? > scope, 
final String path)
+       public static final HeaderContributor forCss(final Class<?> scope, 
final String path)
        {
                return new HeaderContributor(new IHeaderContributor()
                {
@@ -78,7 +78,7 @@
         *            The media type for this CSS ("print", "screen", etc.)
         * @return the new header contributor instance
         */
-       public static final HeaderContributor forCss(final Class< ? > scope, 
final String path,
+       public static final HeaderContributor forCss(final Class<?> scope, 
final String path,
                final String media)
        {
                return new HeaderContributor(new IHeaderContributor()
@@ -203,7 +203,7 @@
         *            The path
         * @return the new header contributor instance
         */
-       public static final HeaderContributor forJavaScript(final Class< ? > 
scope, final String path)
+       public static final HeaderContributor forJavaScript(final Class<?> 
scope, final String path)
        {
                return new HeaderContributor(new IHeaderContributor()
                {
@@ -276,7 +276,10 @@
                }
                else
                {
-                       return 
RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot() + location;
+                       return RequestCycle.get()
+                               .getProcessor()
+                               .getRequestCodingStrategy()
+                               .rewriteStaticRelativeUrl(location);
                }
        }
 

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/image/ContextPathGenerator.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/image/ContextPathGenerator.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/image/ContextPathGenerator.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/image/ContextPathGenerator.java
 Fri Sep 26 09:36:55 2008
@@ -21,7 +21,6 @@
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
-import org.apache.wicket.util.string.Strings;
 
 /**
  * A behavior that converts the provider url fragment to a context-relative 
url. For example if the
@@ -62,24 +61,15 @@
        @Override
        public void onComponentTag(Component component, ComponentTag tag)
        {
-               // get the path
+               // get path
                final String path = contextRelativePath.getObject();
 
-               // generate prefix that will make path context relative
-               final String prefix = 
component.getRequest().getRelativePathPrefixToContextRoot();
+               final String rewritten = component.getRequestCycle()
+                       .getProcessor()
+                       .getRequestCodingStrategy()
+                       .rewriteStaticRelativeUrl(path);
 
-               final String contextRelativePath;
-               if (!Strings.isEmpty(prefix))
-               {
-                       // join the two path pieces
-                       contextRelativePath = Strings.join("/", prefix, path);
-               }
-               else
-               {
-                       contextRelativePath = path;
-               }
-
-               tag.put("src", contextRelativePath);
+               tag.put("src", rewritten);
        }
 
        /** [EMAIL PROTECTED] **/

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java
 Fri Sep 26 09:36:55 2008
@@ -161,8 +161,10 @@
                                        {
                                                url = url.substring(1);
                                        }
-                                       url = 
RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot() +
-                                               url;
+                                       url = RequestCycle.get()
+                                               .getProcessor()
+                                               .getRequestCodingStrategy()
+                                               .rewriteStaticRelativeUrl(url);
                                }
 
                                // if the tag is an anchor proper

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
 Fri Sep 26 09:36:55 2008
@@ -31,6 +31,7 @@
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.parser.AbstractMarkupFilter;
 import org.apache.wicket.markup.resolver.IComponentResolver;
+import org.apache.wicket.request.IRequestCodingStrategy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -80,7 +81,9 @@
                @Override
                public void onComponentTag(Component component, ComponentTag 
tag)
                {
-                       String prefix = null;
+                       IRequestCodingStrategy coder = RequestCycle.get()
+                               .getProcessor()
+                               .getRequestCodingStrategy();
 
                        // Modify all relevant attributes
                        for (int i = 0; i < attributeNames.length; i++)
@@ -88,17 +91,11 @@
                                String attrName = attributeNames[i];
                                String attrValue = 
tag.getAttributes().getString(attrName);
 
+
                                if ((attrValue != null) && 
(attrValue.startsWith("/") == false) &&
                                        (attrValue.indexOf(":") < 0) && 
!(attrValue.startsWith("#")))
                                {
-                                       if (prefix == null)
-                                       {
-                                               prefix = RequestCycle.get()
-                                                       .getRequest()
-                                                       
.getRelativePathPrefixToContextRoot();
-                                       }
-                                       attrValue = prefix + attrValue;
-                                       tag.getAttributes().put(attrName, 
attrValue);
+                                       tag.getAttributes().put(attrName, 
coder.rewriteStaticRelativeUrl(attrValue));
                                }
                        }
                }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
 Fri Sep 26 09:36:55 2008
@@ -27,14 +27,15 @@
 import org.apache.wicket.RequestCycle;
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.protocol.http.RequestUtils;
-import org.apache.wicket.protocol.http.WicketURLEncoder;
 import org.apache.wicket.protocol.http.WicketURLDecoder;
+import org.apache.wicket.protocol.http.WicketURLEncoder;
 import org.apache.wicket.request.IRequestCodingStrategy;
 import org.apache.wicket.request.RequestParameters;
 import org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy;
 import org.apache.wicket.util.crypt.ICrypt;
 import org.apache.wicket.util.string.AppendingStringBuffer;
 import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.string.UrlUtils;
 import org.apache.wicket.util.value.ValueMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -122,8 +123,7 @@
        }
 
        /**
-        * @see org.apache.wicket.request.IRequestTargetMounter#mount(
-        *      
org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy)
+        * @see 
org.apache.wicket.request.IRequestTargetMounter#mount(org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy)
         */
        public void mount(IRequestTargetUrlCodingStrategy urlCodingStrategy)
        {
@@ -205,7 +205,7 @@
                                        // encrypt the query string
                                        String encryptedQueryString = 
urlCrypt.encryptUrlSafe(queryString);
 
-                    encryptedQueryString = 
WicketURLEncoder.QUERY_INSTANCE.encode(encryptedQueryString);
+                                       encryptedQueryString = 
WicketURLEncoder.QUERY_INSTANCE.encode(encryptedQueryString);
 
                                        // build the new complete url
                                        return new 
AppendingStringBuffer(urlPrefix).append("?x=").append(
@@ -387,7 +387,7 @@
                        // Remove the 'x' parameter which contains ALL the 
encoded params
                        parameterMap.remove("x");
                        String decodedParamReplacement = 
encodedParamReplacement;
-            decodedParamReplacement = 
WicketURLDecoder.QUERY_INSTANCE.decode(encodedParamReplacement);
+                       decodedParamReplacement = 
WicketURLDecoder.QUERY_INSTANCE.decode(encodedParamReplacement);
 
                        // Add ALL of the params from the decoded 'x' param
                        ValueMap params = new ValueMap();
@@ -573,4 +573,10 @@
                        return getMessage();
                }
        }
+
+       /** [EMAIL PROTECTED] */
+       public String rewriteStaticRelativeUrl(String string)
+       {
+               return UrlUtils.rewriteToContextRelative(string, 
RequestCycle.get().getRequest());
+       }
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
 Fri Sep 26 09:36:55 2008
@@ -61,6 +61,7 @@
 import org.apache.wicket.util.string.AppendingStringBuffer;
 import org.apache.wicket.util.string.PrependingStringBuffer;
 import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.string.UrlUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1216,4 +1217,10 @@
                }
        }
 
+       /** [EMAIL PROTECTED] */
+       public String rewriteStaticRelativeUrl(String string)
+       {
+               return UrlUtils.rewriteToContextRelative(string, 
RequestCycle.get().getRequest());
+       }
+
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/IRequestCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/IRequestCodingStrategy.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/IRequestCodingStrategy.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/IRequestCodingStrategy.java
 Fri Sep 26 09:36:55 2008
@@ -19,6 +19,7 @@
 import org.apache.wicket.IRequestTarget;
 import org.apache.wicket.Request;
 import org.apache.wicket.RequestCycle;
+import org.apache.wicket.util.string.UrlUtils;
 
 /**
  * Implementations of this interface are responsible for digesting the 
incoming request and creating
@@ -56,4 +57,22 @@
         * @return the url to the provided target
         */
        CharSequence encode(RequestCycle requestCycle, IRequestTarget 
requestTarget);
+
+
+       /**
+        * Rewrites relative paths found in static markup attributes 
(<code>src,href,background</code>)
+        * of wicket pages. Since we do not know the url depth at which the 
page will be rendered the
+        * implementations should usually simply append a prefix, eg 
<code>../../</code>, to make the
+        * path context-relative. If the url is not relative it is returned 
intact.
+        * 
+        * Implementations can be as simple as delegating to
+        * [EMAIL PROTECTED] UrlUtils#rewriteToContextRelative(String, Request)}
+        * 
+        * @see Request#getRelativePathPrefixToContextRoot()
+        * @see UrlUtils#rewriteToContextRelative(String, Request)
+        * 
+        * @param string
+        * @return rewritten path
+        */
+       String rewriteStaticRelativeUrl(String string);
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/RedirectRequestTarget.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/RedirectRequestTarget.java?rev=699402&r1=699401&r2=699402&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/RedirectRequestTarget.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/RedirectRequestTarget.java
 Fri Sep 26 09:36:55 2008
@@ -81,15 +81,15 @@
                        }
                        else
                        {
-                               String location = RequestCycle.get() 
-                                               .getRequest() 
-                                               
.getRelativePathPrefixToContextRoot() + 
-                                               this.redirectUrl.substring(1); 
+                               String location = RequestCycle.get()
+                                       .getProcessor()
+                                       .getRequestCodingStrategy()
+                                       
.rewriteStaticRelativeUrl(redirectUrl.substring(1));
                                if (location.startsWith("./"))
-                               { 
-                                       location = location.substring(2); 
-                               } 
-                               response.redirect(location); 
+                               {
+                                       location = location.substring(2);
+                               }
+                               response.redirect(location);
                        }
                }
                else if (redirectUrl.contains("://"))


Reply via email to