001: /*
002: * Copyright (c) 2002-2008 Gargoyle Software Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: * 2. Redistributions in binary form must reproduce the above copyright notice,
010: * this list of conditions and the following disclaimer in the documentation
011: * and/or other materials provided with the distribution.
012: * 3. The end-user documentation included with the redistribution, if any, must
013: * include the following acknowledgment:
014: *
015: * "This product includes software developed by Gargoyle Software Inc.
016: * (http://www.GargoyleSoftware.com/)."
017: *
018: * Alternately, this acknowledgment may appear in the software itself, if
019: * and wherever such third-party acknowledgments normally appear.
020: * 4. The name "Gargoyle Software" must not be used to endorse or promote
021: * products derived from this software without prior written permission.
022: * For written permission, please contact info@GargoyleSoftware.com.
023: * 5. Products derived from this software may not be called "HtmlUnit", nor may
024: * "HtmlUnit" appear in their name, without prior written permission of
025: * Gargoyle Software Inc.
026: *
027: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
028: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
029: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
030: * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
031: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
032: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
033: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
036: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: */
038: package com.gargoylesoftware.htmlunit.util;
039:
040: import java.io.IOException;
041: import java.io.InputStream;
042: import java.net.URL;
043: import java.util.List;
044:
045: import com.gargoylesoftware.htmlunit.SubmitMethod;
046: import com.gargoylesoftware.htmlunit.WebResponse;
047:
048: /**
049: * Provides a convenient implementation of the {@link WebResponse} interface that can be subclassed
050: * by developers wishing to adapt a particular WebResponse.
051: * This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped
052: * web connection object.
053: *
054: * @version $Revision: 2132 $
055: * @author Marc Guillemot
056: */
057: public class WebResponseWrapper implements WebResponse {
058: private final WebResponse wrappedWebResponse_;
059:
060: /**
061: * Constructs a WebResponse object wrapping provided WebResponse.
062: * @param webResponse the webResponse that does the real work
063: * @throws IllegalArgumentException if the connection is <code>null</code>
064: */
065: public WebResponseWrapper(final WebResponse webResponse)
066: throws IllegalArgumentException {
067: if (webResponse == null) {
068: throw new IllegalArgumentException(
069: "Wrapped WebResponse can't be null");
070: }
071: wrappedWebResponse_ = webResponse;
072: }
073:
074: /**
075: * {@inheritDoc}
076: * The default behavior of this method is to return getContentAsStream() on the wrapped connection object.
077: */
078: public InputStream getContentAsStream() throws IOException {
079: return wrappedWebResponse_.getContentAsStream();
080: }
081:
082: /**
083: * {@inheritDoc}
084: * The default behavior of this method is to return getContentAsString() on the wrapped connection object.
085: */
086: public String getContentAsString() {
087: return wrappedWebResponse_.getContentAsString();
088: }
089:
090: /**
091: * {@inheritDoc}
092: * The default behavior of this method is to return getContentCharSet() on the wrapped connection object.
093: */
094: public String getContentCharSet() {
095: return wrappedWebResponse_.getContentCharSet();
096: }
097:
098: /**
099: * {@inheritDoc}
100: * The default behavior of this method is to return getContentType() on the wrapped connection object.
101: */
102: public String getContentType() {
103: return wrappedWebResponse_.getContentType();
104: }
105:
106: /**
107: * {@inheritDoc}
108: * The default behavior of this method is to return getLoadTimeInMilliSeconds() on the wrapped connection object.
109: */
110: public long getLoadTimeInMilliSeconds() {
111: return wrappedWebResponse_.getLoadTimeInMilliSeconds();
112: }
113:
114: /**
115: * {@inheritDoc}
116: * The default behavior of this method is to return getRequestMethod() on the wrapped connection object.
117: */
118: public SubmitMethod getRequestMethod() {
119: return wrappedWebResponse_.getRequestMethod();
120: }
121:
122: /**
123: * {@inheritDoc}
124: * The default behavior of this method is to return getResponseBody() on the wrapped connection object.
125: */
126: public byte[] getResponseBody() {
127: return wrappedWebResponse_.getResponseBody();
128: }
129:
130: /**
131: * {@inheritDoc}
132: * The default behavior of this method is to return getResponseHeaders() on the wrapped connection object.
133: */
134: public List getResponseHeaders() {
135: return wrappedWebResponse_.getResponseHeaders();
136: }
137:
138: /**
139: * {@inheritDoc}
140: * The default behavior of this method is to return getResponseHeaderValue() on the wrapped connection object.
141: */
142: public String getResponseHeaderValue(final String headerName) {
143: return wrappedWebResponse_.getResponseHeaderValue(headerName);
144: }
145:
146: /**
147: * {@inheritDoc}
148: * The default behavior of this method is to return getStatusCode() on the wrapped connection object.
149: */
150: public int getStatusCode() {
151: return wrappedWebResponse_.getStatusCode();
152: }
153:
154: /**
155: * {@inheritDoc}
156: * The default behavior of this method is to return getStatusMessage() on the wrapped connection object.
157: */
158: public String getStatusMessage() {
159: return wrappedWebResponse_.getStatusMessage();
160: }
161:
162: /**
163: * {@inheritDoc}
164: * The default behavior of this method is to return getUrl() on the wrapped connection object.
165: */
166: public URL getUrl() {
167: return wrappedWebResponse_.getUrl();
168: }
169:
170: }
|