001: /*
002: * Copyright 2005-2007 Noelios Consulting.
003: *
004: * The contents of this file are subject to the terms of the Common Development
005: * and Distribution License (the "License"). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the license at
009: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010: * language governing permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL HEADER in each file and
013: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014: * applicable, add the following below this CDDL HEADER, with the fields
015: * enclosed by brackets "[]" replaced with your own identifying information:
016: * Portions Copyright [yyyy] [name of copyright owner]
017: */
018:
019: package org.restlet.service;
020:
021: import org.restlet.data.ClientInfo;
022:
023: /**
024: * Service tunnelling method names or client preferences via query parameters.
025: * Clients applications such as browsers can easily override the default values
026: * of their client connector by specifying additional query parameters. Here is
027: * the list of the default parameter names supported: <table>
028: * <tr>
029: * <th>Property</th>
030: * <th>Default name</th>
031: * <th>Value type</th>
032: * <th>Description</th>
033: * </tr>
034: * <tr>
035: * <td>methodParameter</td>
036: * <td>method</td>
037: * <td>See values in org.restlet.data.Method</td>
038: * <td>For POST requests, specify the actual method to use (DELETE, PUT, etc.).</td>
039: * </tr>
040: * <tr>
041: * <td>characterSetParameter</td>
042: * <td>charset</td>
043: * <td>Use extension names defined in org.restlet.service.MetadataService</td>
044: * <td>For GET requests, replaces the accepted character set by the given
045: * value.</td>
046: * </tr>
047: * <tr>
048: * <td>encodingParameter</td>
049: * <td>encoding</td>
050: * <td>Use extension names defined in org.restlet.service.MetadataService</td>
051: * <td>For GET requests, replaces the accepted encoding by the given value.</td>
052: * </tr>
053: * <tr>
054: * <td>languageParameter</td>
055: * <td>language</td>
056: * <td>Use extension names defined in org.restlet.service.MetadataService</td>
057: * <td>For GET requests, replaces the accepted language by the given value.</td>
058: * </tr>
059: * <tr>
060: * <td>mediaTypeParameter</td>
061: * <td>media</td>
062: * <td>Use extension names defined in org.restlet.service.MetadataService</td>
063: * <td>For GET requests, replaces the accepted media type set by the given
064: * value.</td>
065: * </tr>
066: * </table>
067: *
068: * @author Jerome Louvel (contact@noelios.com)
069: */
070: public class TunnelService {
071: /** Indicates if the service has been enabled. */
072: private boolean enabled;
073:
074: /** Indicates if the method name can be tunneled. */
075: private boolean methodTunnel;
076:
077: /** The name of the parameter containing the method name. */
078: private String methodParameter;
079:
080: /** Indicates if the client preferences can be tunneled. */
081: private boolean preferencesTunnel;
082:
083: /** The name of the parameter containing the accepted character set. */
084: private String characterSetParameter;
085:
086: /** The name of the parameter containing the accepted encoding. */
087: private String encodingParameter;
088:
089: /** The name of the parameter containing the accepted language. */
090: private String languageParameter;
091:
092: /** The name of the parameter containing the accepted media type. */
093: private String mediaTypeParameter;
094:
095: /**
096: * Constructor.
097: *
098: * @param enabled
099: * True if the service has been enabled.
100: * @param methodTunnel
101: * Indicates if the method name can be tunneled.
102: * @param preferencesTunnel
103: * Indicates if the client preferences can be tunneled.
104: */
105: public TunnelService(boolean enabled, boolean methodTunnel,
106: boolean preferencesTunnel) {
107: this .enabled = enabled;
108: this .methodTunnel = methodTunnel;
109: this .methodParameter = "method";
110: this .preferencesTunnel = preferencesTunnel;
111: this .characterSetParameter = "charset";
112: this .encodingParameter = "encoding";
113: this .languageParameter = "language";
114: this .mediaTypeParameter = "media";
115: }
116:
117: /**
118: * Indicates if the request from a given client can be tunnelled. The
119: * default implementation always return true. This could be customize to
120: * restrict the usage of the tunnel service.
121: *
122: * @param client
123: * The client to test.
124: * @return True if the request from a given client can be tunnelled.
125: */
126: public boolean allowClient(ClientInfo client) {
127: return true;
128: }
129:
130: /**
131: * Returns the character set parameter name.
132: *
133: * @return The character set parameter name.
134: */
135: public String getCharacterSetAttribute() {
136: return this .characterSetParameter;
137: }
138:
139: /**
140: * Returns the name of the parameter containing the accepted encoding.
141: *
142: * @return The name of the parameter containing the accepted encoding.
143: */
144: public String getEncodingAttribute() {
145: return this .encodingParameter;
146: }
147:
148: /**
149: * Returns the name of the parameter containing the accepted language.
150: *
151: * @return The name of the parameter containing the accepted language.
152: */
153: public String getLanguageAttribute() {
154: return this .languageParameter;
155: }
156:
157: /**
158: * Returns the name of the parameter containing the accepted media type.
159: *
160: * @return The name of the parameter containing the accepted media type.
161: */
162: public String getMediaTypeAttribute() {
163: return this .mediaTypeParameter;
164: }
165:
166: /**
167: * Returns the method parameter name.
168: *
169: * @return The method parameter name.
170: */
171: public String getMethodParameter() {
172: return this .methodParameter;
173: }
174:
175: /**
176: * Indicates if the service should be enabled.
177: *
178: * @return True if the service should be enabled.
179: */
180: public boolean isEnabled() {
181: return this .enabled;
182: }
183:
184: /**
185: * Indicates if the method name can be tunneled.
186: *
187: * @return True if the method name can be tunneled.
188: */
189: public boolean isMethodTunnel() {
190: return this .methodTunnel;
191: }
192:
193: /**
194: * Indicates if the client preferences can be tunneled.
195: *
196: * @return True if the client preferences can be tunneled.
197: */
198: public boolean isPreferencesTunnel() {
199: return this .preferencesTunnel;
200: }
201:
202: /**
203: * Sets the character set parameter name.
204: *
205: * @param parameterName
206: * The character set parameter name.
207: */
208: public void setCharacterSetAttribute(String parameterName) {
209: this .characterSetParameter = parameterName;
210: }
211:
212: /**
213: * Indicates if the service should be enabled.
214: *
215: * @param enabled
216: * True if the service should be enabled.
217: */
218: public void setEnabled(boolean enabled) {
219: this .enabled = enabled;
220: }
221:
222: /**
223: * Sets the name of the parameter containing the accepted encoding.
224: *
225: * @param parameterName
226: * The name of the parameter containing the accepted encoding.
227: */
228: public void setEncodingAttribute(String parameterName) {
229: this .encodingParameter = parameterName;
230: }
231:
232: /**
233: * Sets the name of the parameter containing the accepted language.
234: *
235: * @param parameterName
236: * The name of the parameter containing the accepted language.
237: */
238: public void setLanguageAttribute(String parameterName) {
239: this .languageParameter = parameterName;
240: }
241:
242: /**
243: * Sets the name of the parameter containing the accepted media type.
244: *
245: * @param parameterName
246: * The name of the parameter containing the accepted media type.
247: */
248: public void setMediaTypeAttribute(String parameterName) {
249: this .mediaTypeParameter = parameterName;
250: }
251:
252: /**
253: * Sets the method parameter name.
254: *
255: * @param parameterName
256: * The method parameter name.
257: */
258: public void setMethodParameter(String parameterName) {
259: this .methodParameter = parameterName;
260: }
261:
262: /**
263: * Indicates if the method name can be tunneled.
264: *
265: * @param methodTunnel
266: * True if the method name can be tunneled.
267: */
268: public void setMethodTunnel(boolean methodTunnel) {
269: this .methodTunnel = methodTunnel;
270: }
271:
272: /**
273: * Indicates if the client preferences can be tunneled.
274: *
275: * @param preferencesTunnel
276: * True if the client preferences can be tunneled.
277: */
278: public void setPreferencesTunnel(boolean preferencesTunnel) {
279: this.preferencesTunnel = preferencesTunnel;
280: }
281:
282: }
|