PrefixedRequestObject.java
/***************************************************************************
Copyright 2012 Emily Estes
Licensed 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 net.metanotion.web.concrete;
import java.io.InputStream;
import java.io.Reader;
import java.util.Date;
import net.metanotion.web.Cookie;
import net.metanotion.web.HttpMethod;
import net.metanotion.web.RequestObject;
/** Wrap a request object instance with one that removes a prefix from resources. */
public final class PrefixedRequestObject implements RequestObject {
private final RequestObject parent;
private final String resourcePrefix;
/** Create a new prefixed request object.
@param parent The request object to wrap.
@param resourcePrefix the prefix to remove when {@link net.metanotion.web.RequestObject#getResource} is called.
*/
public PrefixedRequestObject(final RequestObject parent, final String resourcePrefix) {
this.parent = parent;
this.resourcePrefix = resourcePrefix;
}
@Override public String getResource() {
final String r = this.parent.getResource();
if(r.startsWith(resourcePrefix)) { return r.substring(resourcePrefix.length()); }
return r;
}
@Override public Object get(final String name) { return this.parent.get(name); }
@Override public HttpMethod getMethod() { return this.parent.getMethod(); }
@Override public String getServer() { return this.parent.getServer(); }
@Override public String getQuery() { return this.parent.getQuery(); }
@Override public Reader getRawPost() { return this.parent.getRawPost(); }
@Override public InputStream getByteStream() { return this.parent.getByteStream(); }
@Override public String getRemoteAddr() { return this.parent.getRemoteAddr(); }
@Override public String getRemoteHost() { return this.parent.getRemoteHost(); }
@Override public String getHeader(final String name) { return this.parent.getHeader(name); }
@Override public Iterable<String> getHeaders() { return this.parent.getHeaders(); }
@Override public Date getDateHeader(final String name) { return this.parent.getDateHeader(name); }
@Override public Cookie getCookie(final String name) { return this.parent.getCookie(name); }
@Override public Iterable<String> getCookies() { return this.parent.getCookies(); }
@Override public String getRawResource() { return this.parent.getRawResource(); }
}