01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import java.util.List;
18:
19: import org.apache.tapestry.Link;
20: import org.apache.tapestry.services.Response;
21:
22: /**
23: * Starting implementation of {@link Link}. Currently does not support query parameters.
24: */
25: public class LinkImpl implements Link {
26: private final Response _response;
27:
28: private final String _contextPath;
29:
30: private final ComponentInvocation _invocation;
31:
32: private final boolean _forForm;
33:
34: public LinkImpl(Response encoder, String contextPath,
35: String targetPath) {
36: this (encoder, contextPath, targetPath, false);
37: }
38:
39: public LinkImpl(Response encoder, String contextPath,
40: String targetPath, boolean forForm) {
41: this (encoder, contextPath, new ComponentInvocation(
42: new OpaqueConstantTarget(targetPath), new String[0],
43: null), forForm);
44: }
45:
46: public LinkImpl(Response encoder, String contextPath,
47: ComponentInvocation invocation, boolean forForm) {
48: _contextPath = contextPath;
49: _response = encoder;
50: _invocation = invocation;
51: _forForm = forForm;
52: }
53:
54: public void addParameter(String parameterName, String value) {
55: _invocation.addParameter(parameterName, value);
56: }
57:
58: public List<String> getParameterNames() {
59: return _invocation.getParameterNames();
60: }
61:
62: public String getParameterValue(String name) {
63: return _invocation.getParameterValue(name);
64: }
65:
66: public String toURI() {
67: return _response.encodeURL(buildURI());
68: }
69:
70: private String buildURI() {
71: StringBuilder builder = new StringBuilder();
72: builder.append(_contextPath);
73: builder.append("/");
74: builder.append(_invocation.buildURI(_forForm));
75: return builder.toString();
76: }
77:
78: public String toRedirectURI() {
79: return _response.encodeRedirectURL(buildURI());
80: }
81:
82: public ComponentInvocation getInvocation() {
83: return _invocation;
84: }
85:
86: @Override
87: public String toString() {
88: return toURI();
89: }
90: }
|