001 // Copyright Jul 10, 2006 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014 package org.apache.tapestry.portlet;
015
016 import org.apache.tapestry.IEngine;
017 import org.apache.tapestry.IRequestCycle;
018 import org.apache.tapestry.engine.EngineServiceLink;
019 import org.apache.tapestry.engine.IEngineService;
020 import org.apache.tapestry.engine.ILink;
021 import org.apache.tapestry.engine.ServiceEncoding;
022 import org.apache.tapestry.services.impl.LinkFactoryImpl;
023 import org.apache.tapestry.util.QueryParameterMap;
024
025 import java.util.Map;
026
027
028 /**
029 * Creates {@link EngineServiceLink}s that will re-encode asset URL's
030 * using {@link IRequestCycle#encodeURL(String)}.
031 *
032 */
033 public class PortletAssetLinkFactoryImpl extends LinkFactoryImpl
034 {
035
036 public ILink constructLink(IEngineService service, boolean post, Map parameters,
037 boolean stateful)
038 {
039 finalizeParameters(service, parameters);
040
041 IEngine engine = _requestCycle.getEngine();
042
043 QueryParameterMap qmap = new QueryParameterMap(parameters);
044
045 ServiceEncoding serviceEncoding = createServiceEncoding(qmap);
046
047 // Give persistent property strategies a chance to store extra data
048 // into the link.
049
050 if (stateful)
051 _persistenceStrategySource.addParametersForPersistentProperties(serviceEncoding, post);
052
053 String fullServletPath = _request.getContextPath() + serviceEncoding.getServletPath();
054
055 return new EngineServiceLink(_requestCycle, fullServletPath, engine.getOutputEncoding(),
056 _codec, _request, qmap, stateful);
057 }
058 }