Author: ehillenius
Date: Fri Feb 16 12:01:10 2007
New Revision: 508553

URL: http://svn.apache.org/viewvc?view=rev&rev=508553
Log:
javadoc for WICKET-287 and URL -> Url

Added:
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebCodingStrategy.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressor.java
Modified:
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/WebPage.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebRequestProcessor.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/request/IRequestCycleProcessor.java

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/WebPage.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/WebPage.java?view=diff&rev=508553&r1=508552&r2=508553
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/WebPage.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/WebPage.java
 Fri Feb 16 12:01:10 2007
@@ -41,8 +41,8 @@
 import wicket.model.Model;
 import wicket.protocol.http.WebRequestCycle;
 import wicket.protocol.http.WebResponse;
-import wicket.protocol.http.request.urlcompressing.URLCompressor;
 import 
wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor;
+import wicket.protocol.http.request.urlcompressing.UrlCompressor;
 import wicket.request.target.component.BookmarkablePageRequestTarget;
 import wicket.request.target.component.IBookmarkablePageRequestTarget;
 import wicket.util.lang.Objects;
@@ -86,7 +86,7 @@
         * The url compressor that will compress the urls by collapsing the
         * component path and listener interface
         */
-       private URLCompressor compressor;
+       private UrlCompressor compressor;
 
        /**
         * Constructor. Having this constructor public means that your page is
@@ -266,13 +266,13 @@
         * @since 1.2
         * 
         * @see UrlCompressingWebRequestProcessor
-        * @see URLCompressor
+        * @see UrlCompressor
         */
-       public final URLCompressor getUrlCompressor()
+       public final UrlCompressor getUrlCompressor()
        {
                if (compressor == null)
                {
-                       compressor = new URLCompressor();
+                       compressor = new UrlCompressor();
                }
                return compressor;
        }

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java?view=diff&rev=508553&r1=508552&r2=508553
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategy.java
 Fri Feb 16 12:01:10 2007
@@ -53,8 +53,13 @@
  * <pre>
  * protected IRequestCycleProcessor newRequestCycleProcessor()
  * {
- *     return new CompoundRequestCycleProcessor(new 
CryptedUrlWebRequestCodingStrategy(
- *                     new WebRequestCodingStrategy()), null, null, null, 
null);
+ *     return new WebRequestCycleProcessor()
+ *     {
+ *             protected IRequestCodingStrategy newRequestCodingStrategy()
+ *             {
+ *                     return new CryptedUrlWebRequestCodingStrategy(new 
WebRequestCodingStrategy());
+ *             }
+ *     };
  * }
  * </pre>
  * 
@@ -238,17 +243,17 @@
                                {
                                        secureParam = url.substring(startIndex, 
endIndex);
                                }
-       
-                               secureParam = URLDecoder.decode(secureParam, 
Application
-                                               
.get().getRequestCycleSettings().getResponseRequestEncoding());
-       
+
+                               secureParam = URLDecoder.decode(secureParam, 
Application.get()
+                                               
.getRequestCycleSettings().getResponseRequestEncoding());
+
                                // Get the crypt implementation from the 
application
                                final ICrypt urlCrypt = 
Application.get().getSecuritySettings().getCryptFactory()
                                                .newCrypt();
-       
+
                                // Decrypt the query string
                                String queryString = 
urlCrypt.decryptUrlSafe(secureParam);
-       
+
                                // The querystring might have been shortened 
(length reduced).
                                // In that case, lengthen the query string 
again.
                                queryString = rebuildUrl(queryString);
@@ -261,7 +266,7 @@
                }
                return null;
        }
-       
+
        /**
         * @param ex
         * 
@@ -270,7 +275,7 @@
        protected String onError(final Exception ex)
        {
                log.error(ex);
-       
+
                throw new HackAttackException("Invalid URL");
        }
 
@@ -388,7 +393,8 @@
                        String decodedParamReplacement = 
encodedParamReplacement;
                        try
                        {
-                               decodedParamReplacement = 
URLDecoder.decode(encodedParamReplacement, 
Application.get().getRequestCycleSettings().getResponseRequestEncoding());
+                               decodedParamReplacement = 
URLDecoder.decode(encodedParamReplacement, Application
+                                               
.get().getRequestCycleSettings().getResponseRequestEncoding());
                        }
                        catch (UnsupportedEncodingException ex)
                        {

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebCodingStrategy.java?view=auto&rev=508553
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebCodingStrategy.java
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebCodingStrategy.java
 Fri Feb 16 12:01:10 2007
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package wicket.protocol.http.request.urlcompressing;
+
+import wicket.Component;
+import wicket.IPageMap;
+import wicket.IRedirectListener;
+import wicket.Page;
+import wicket.RequestCycle;
+import wicket.RequestListenerInterface;
+import wicket.markup.html.WebPage;
+import wicket.protocol.http.WebApplication;
+import wicket.protocol.http.request.WebRequestCodingStrategy;
+import wicket.request.RequestParameters;
+import 
wicket.request.target.component.listener.IListenerInterfaceRequestTarget;
+import wicket.util.string.AppendingStringBuffer;
+
+
+/**
+ * Use this CodingStategy with the [EMAIL PROTECTED] 
WebURLCompressingTargetResolverStrategy} to 
+ * minimize the wicket:interface urls. The component path and the interface 
name
+ * will be removed from the url and only an uid will be inserted into the url.
+ * 
+ * To use this url compressing behaviour you must override the 
+ * [EMAIL PROTECTED] WebApplication}'s newRequestCycleProcessor() method. To 
make a request cycle
+ * processor with this CodingStrategy and the [EMAIL PROTECTED] 
WebURLCompressingTargetResolverStrategy}
+ * 
+ * <pre>
+ * protected IRequestCycleProcessor newRequestCycleProcessor()
+ * {
+ *     return new CompoundRequestCycleProcessor(new 
WebURLCompressingCodingStrategy(),
+ *                     new WebURLCompressingTargetResolverStrategy(), null, 
null, null);
+ * }
+ * </pre>
+ * 
+ * @author jcompagner
+ * 
+ * @since 1.3
+ */
+public class UrlCompressingWebCodingStrategy extends WebRequestCodingStrategy
+{
+       /**
+        * Encode a listener interface target.
+        * 
+        * @param requestCycle
+        *            the current request cycle
+        * @param requestTarget
+        *            the target to encode
+        * @return the encoded url
+        */
+       protected CharSequence encode(RequestCycle requestCycle,
+                       IListenerInterfaceRequestTarget requestTarget)
+       {
+               final RequestListenerInterface rli = 
requestTarget.getRequestListenerInterface();
+
+               // Start string buffer for url
+               final AppendingStringBuffer url = new AppendingStringBuffer(64);
+               url.append('?');
+               url.append(INTERFACE_PARAMETER_NAME);
+               url.append('=');
+
+               // Get component and page for request target
+               final Component component = requestTarget.getTarget();
+               final Page page = component.getPage();
+
+               // Add pagemap
+               final IPageMap pageMap = page.getPageMap();
+               if (!pageMap.isDefault())
+               {
+                       url.append(pageMap.getName());
+               }
+               url.append(Component.PATH_SEPARATOR);
+
+               String listenerName = rli.getName();
+               // Add path to component
+               if (page instanceof WebPage && 
!"IResourceListener".equals(listenerName))
+               {
+                       url.append(page.getId());
+                       url.append(Component.PATH_SEPARATOR);
+                       
url.append(((WebPage)page).getUrlCompressor().getUIDForComponentAndInterface(component,listenerName));
+                       listenerName = null;
+               }
+               else
+               {
+                       url.append(component.getPath());
+               }
+               url.append(Component.PATH_SEPARATOR);
+
+               // Add version
+               final int versionNumber = 
component.getPage().getCurrentVersionNumber();
+               if (!rli.getRecordsPageVersion())
+               {
+                       url.append(Page.LATEST_VERSION);
+               }
+               else if (versionNumber > 0)
+               {
+                       url.append(versionNumber);
+               }
+               url.append(Component.PATH_SEPARATOR);
+
+               // Add listener interface
+               if (listenerName != null && 
!IRedirectListener.INTERFACE.getName().equals(listenerName))
+               {
+                       url.append(listenerName);
+               }
+               
+               url.append(Component.PATH_SEPARATOR);
+               
+               // Add behaviourId
+               RequestParameters params = requestTarget.getRequestParameters();
+               if (params != null && params.getBehaviorId() != null)
+               {
+                       url.append(params.getBehaviorId());
+               }
+               return requestCycle.getOriginalResponse().encodeURL(url);
+       }
+}

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebRequestProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebRequestProcessor.java?view=diff&rev=508553&r1=508552&r2=508553
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebRequestProcessor.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressingWebRequestProcessor.java
 Fri Feb 16 12:01:10 2007
@@ -28,7 +28,7 @@
 import wicket.markup.html.INewBrowserWindowListener;
 import wicket.markup.html.WebPage;
 import wicket.protocol.http.WebRequestCycleProcessor;
-import 
wicket.protocol.http.request.urlcompressing.URLCompressor.ComponentAndInterface;
+import 
wicket.protocol.http.request.urlcompressing.UrlCompressor.ComponentAndInterface;
 import wicket.request.IRequestCodingStrategy;
 import wicket.request.RequestParameters;
 import wicket.request.target.component.listener.RedirectPageRequestTarget;
@@ -41,7 +41,7 @@
  * 
  * To use this url compressing behaviour you must override the
  * [EMAIL PROTECTED] Application}'s newRequestCycleProcessor() method and 
return an
- * instance of this
+ * instance of this.
  * 
  * @author jcompagner
  * 
@@ -61,7 +61,7 @@
         */
        protected IRequestCodingStrategy newRequestCodingStrategy()
        {
-               return new URLCompressingWebCodingStrategy();
+               return new UrlCompressingWebCodingStrategy();
        }
 
        /**

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressor.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressor.java?view=auto&rev=508553
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressor.java
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/urlcompressing/UrlCompressor.java
 Fri Feb 16 12:01:10 2007
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package wicket.protocol.http.request.urlcompressing;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.Iterator;
+
+import wicket.Component;
+import wicket.util.collections.IntHashMap;
+import wicket.util.collections.IntHashMap.Entry;
+
+/**
+ * This class generates UID for Component/Interface combinations when used in
+ * conjunction with [EMAIL PROTECTED] UrlCompressingWebCodingStrategy}
+ * 
+ * Use it like this:
+ * 
+ * <pre>
+ * protected IRequestCycleProcessor newRequestCycleProcessor()
+ * {
+ *     return new UrlCompressingWebRequestProcessor();
+ * }
+ * </pre>
+ * 
+ * @since 1.2
+ * 
+ * @see URLCompressingWebCodingStrategy
+ * @see UrlCompressingWebRequestProcessor
+ * 
+ * @author jcompagner
+ */
+public class UrlCompressor implements Serializable
+{
+       /**
+        * @author jcompagner
+        */
+       public static class ComponentAndInterface
+       {
+               private static final long serialVersionUID = 1L;
+
+               private final IntKeyWeakReference ref;
+               private final String interfaceName;
+
+               private ComponentAndInterface(IntKeyWeakReference ref, String 
interfaceName)
+               {
+                       this.ref = ref;
+                       this.interfaceName = interfaceName;
+               }
+
+               /**
+                * @return Component The component that should be used to call 
the
+                *         interface
+                */
+               public Component getComponent()
+               {
+                       return (Component)ref.get();
+               }
+
+               /**
+                * @return String The interface name which should be called on 
the
+                *         component
+                */
+               public String getInterfaceName()
+               {
+                       return interfaceName;
+               }
+       }
+
+       private static class IntKeyWeakReference extends WeakReference
+       {
+               private int uid;
+
+               /**
+                * @param uid
+                * @param referent
+                * @param q
+                */
+               public IntKeyWeakReference(int uid, Object referent, 
ReferenceQueue q)
+               {
+                       super(referent, q);
+                       this.uid = uid;
+               }
+       }
+
+       private static final long serialVersionUID = 1L;
+
+       private transient ReferenceQueue queue = new ReferenceQueue();
+
+       private transient IntHashMap directComponentRefs = new IntHashMap(); // 
uid->component/interface
+
+       private int uid = 1;
+
+       /**
+        * Gets the combination
+        * 
+        * @param uidString
+        * @return ComponentAndInterface
+        */
+       public ComponentAndInterface getComponentAndInterfaceForUID(String 
uidString)
+       {
+               IntKeyWeakReference ref = null;
+               while ((ref = (IntKeyWeakReference)queue.poll()) != null)
+               {
+                       directComponentRefs.remove(ref.uid);
+               }
+               int uid = Integer.parseInt(uidString);
+               ComponentAndInterface cai = 
(ComponentAndInterface)directComponentRefs.get(uid);
+               return cai;
+       }
+
+       /**
+        * @return the next uid for this url compressor
+        */
+       public int getNewUID()
+       {
+               return uid++;
+       }
+
+       /**
+        * Returns a uid for the combination component and the to call 
interface.
+        * Will return the same uid if it was already called for this specific
+        * combination.
+        * 
+        * @param component
+        *            The Component
+        * @param interfaceName
+        *            The interface name
+        * @return int The uid for the component/interfaceName combination
+        */
+       public int getUIDForComponentAndInterface(Component component, String 
interfaceName)
+       {
+               int uid = 0;
+               Iterator it = directComponentRefs.entrySet().iterator();
+               while (it.hasNext())
+               {
+                       IntHashMap.Entry entry = (IntHashMap.Entry)it.next();
+                       ComponentAndInterface cai = 
(ComponentAndInterface)entry.getValue();
+                       if (cai.getInterfaceName().equals(interfaceName) && 
cai.getComponent() == component)
+                       {
+                               uid = entry.getKey();
+                               break;
+                       }
+               }
+               if (uid == 0)
+               {
+                       uid = getNewUID();
+                       IntKeyWeakReference ref = new IntKeyWeakReference(uid, 
component, queue);
+                       directComponentRefs.put(uid, new 
ComponentAndInterface(ref, interfaceName));
+               }
+               return uid;
+       }
+
+       private void readObject(java.io.ObjectInputStream s) throws 
IOException, ClassNotFoundException
+       {
+               s.defaultReadObject();
+
+               int size = s.readInt();
+               queue = new ReferenceQueue();
+               directComponentRefs = new IntHashMap((int)(size * 1.25));
+
+               while (--size >= 0)
+               {
+                       int uid = s.readInt();
+                       Component component = (Component)s.readObject();
+                       String interfaceName = s.readUTF();
+
+                       IntKeyWeakReference ref = new IntKeyWeakReference(uid, 
component, queue);
+                       directComponentRefs.put(uid, new 
ComponentAndInterface(ref, interfaceName));
+               }
+
+       }
+
+       private void writeObject(java.io.ObjectOutputStream s) throws 
IOException
+       {
+               IntKeyWeakReference ref = null;
+               while ((ref = (IntKeyWeakReference)queue.poll()) != null)
+               {
+                       directComponentRefs.remove(ref.uid);
+               }
+
+               s.defaultWriteObject();
+
+               s.writeInt(directComponentRefs.size());
+
+               Iterator it = directComponentRefs.entrySet().iterator();
+               while (it.hasNext())
+               {
+                       IntHashMap.Entry entry = (Entry)it.next();
+
+                       s.writeInt(entry.getKey());
+                       ComponentAndInterface cai = 
(ComponentAndInterface)entry.getValue();
+                       s.writeObject(cai.getComponent());
+                       s.writeUTF(cai.getInterfaceName());
+               }
+       }
+}

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/request/IRequestCycleProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/request/IRequestCycleProcessor.java?view=diff&rev=508553&r1=508552&r2=508553
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/request/IRequestCycleProcessor.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/request/IRequestCycleProcessor.java
 Fri Feb 16 12:01:10 2007
@@ -18,6 +18,7 @@
 
 import wicket.IRequestTarget;
 import wicket.RequestCycle;
+import wicket.protocol.http.WebRequestCycleProcessor;
 
 /**
  * <p>
@@ -40,19 +41,16 @@
  * requesting client. Typically, the actual response handling is to be (or
  * delegated) by the request target implementation, but different strategies
  * might do as they seem fit. </li>
- * <li> [EMAIL PROTECTED] #respond(RuntimeException, RequestCycle)} is called 
whenever an uncaught
- * exception occurs during the event handling or response phase so that an
- * appropriate exception response can be generated. This method is guaranteed 
to
- * be called whenever such an exception happens, but will never be called
+ * <li> [EMAIL PROTECTED] #respond(RuntimeException, RequestCycle)} is called 
whenever an
+ * uncaught exception occurs during the event handling or response phase so 
that
+ * an appropriate exception response can be generated. This method is 
guaranteed
+ * to be called whenever such an exception happens, but will never be called
  * otherwise. </li>
  * </ul>
  * </p>
- * <p>
- * A convience implementation that makes breaking up this processor in smaller
- * delegate strategies easier can be found as
- * [EMAIL PROTECTED] wicket.request.compound.CompoundRequestCycleProcessor} (or
- * [EMAIL PROTECTED] 
wicket.request.compound.AbstractCompoundRequestCycleProcessor}).
- * </p>
+ * 
+ * @see AbstractRequestCycleProcessor
+ * @see WebRequestCycleProcessor
  * 
  * @author hillenius
  */


Reply via email to