001: /*
002: * $Id: org.eclipse.jdt.ui.prefs 5004 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) eelco12 $
003: * $Revision: 5004 $
004: * $Date: 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) $
005: *
006: * ==============================================================================
007: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
008: * use this file except in compliance with the License. You may obtain a copy of
009: * the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
015: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
016: * License for the specific language governing permissions and limitations under
017: * the License.
018: */
019: package wicket.protocol.http.request.urlcompressing;
020:
021: import wicket.Component;
022: import wicket.IRedirectListener;
023: import wicket.Page;
024: import wicket.PageMap;
025: import wicket.RequestCycle;
026: import wicket.RequestListenerInterface;
027: import wicket.markup.html.WebPage;
028: import wicket.protocol.http.WebApplication;
029: import wicket.protocol.http.request.WebRequestCodingStrategy;
030: import wicket.request.target.component.listener.IListenerInterfaceRequestTarget;
031: import wicket.util.string.AppendingStringBuffer;
032:
033: /**
034: * Use this CodingStategy with the {@link WebURLCompressingTargetResolverStrategy} to
035: * minimize the wicket:interface urls. The component path and the interface name
036: * will be removed from the url and only an uid will be inserted into the url.
037: *
038: * To use this url compressing behaviour you must override the
039: * {@link WebApplication}'s newRequestCycleProcessor() method. To make a request cycle
040: * processor with this CodingStrategy and the {@link WebURLCompressingTargetResolverStrategy}
041: *
042: * <pre>
043: * protected IRequestCycleProcessor newRequestCycleProcessor()
044: * {
045: * return new CompoundRequestCycleProcessor(new WebURLCompressingCodingStrategy(),new WebURLCompressingTargetResolverStrategy(),null,null,null);
046: * }
047: * </pre>
048: *
049: * @author jcompagner
050: *
051: * @since 1.2
052: */
053: public class WebURLCompressingCodingStrategy extends
054: WebRequestCodingStrategy {
055: /**
056: * Encode a listener interface target.
057: *
058: * @param requestCycle
059: * the current request cycle
060: * @param requestTarget
061: * the target to encode
062: * @return the encoded url
063: */
064: protected CharSequence encode(RequestCycle requestCycle,
065: IListenerInterfaceRequestTarget requestTarget) {
066: final RequestListenerInterface rli = requestTarget
067: .getRequestListenerInterface();
068:
069: // Start string buffer for url
070: final AppendingStringBuffer url = new AppendingStringBuffer(64);
071: url.append(urlPrefix(requestCycle));
072: url.append('?');
073: url.append(INTERFACE_PARAMETER_NAME);
074: url.append('=');
075:
076: // Get component and page for request target
077: final Component component = requestTarget.getTarget();
078: final Page page = component.getPage();
079:
080: // Add pagemap
081: final PageMap pageMap = page.getPageMap();
082: if (!pageMap.isDefault()) {
083: url.append(pageMap.getName());
084: }
085: url.append(Component.PATH_SEPARATOR);
086:
087: String listenerName = rli.getName();
088: // Add path to component
089: if (page instanceof WebPage
090: && !"IResourceListener".equals(listenerName)) {
091: url.append(page.getId());
092: url.append(Component.PATH_SEPARATOR);
093: url.append(((WebPage) page).getUrlCompressor()
094: .getUIDForComponentAndInterface(component,
095: listenerName));
096: listenerName = null;
097: } else {
098: url.append(component.getPath());
099: }
100: url.append(Component.PATH_SEPARATOR);
101:
102: // Add version
103: final int versionNumber = component.getPage()
104: .getCurrentVersionNumber();
105: if (!rli.getRecordsPageVersion()) {
106: url.append(Page.LATEST_VERSION);
107: } else if (versionNumber > 0) {
108: url.append(versionNumber);
109: }
110: url.append(Component.PATH_SEPARATOR);
111:
112: // Add listener interface
113: if (listenerName != null
114: && !IRedirectListener.INTERFACE.getName().equals(
115: listenerName)) {
116: url.append(listenerName);
117: }
118:
119: return requestCycle.getOriginalResponse().encodeURL(url);
120: }
121: }
|