001: package com.meterware.httpunit;
002:
003: /********************************************************************************************************************
004: * $Id: ClientProperties.java,v 1.7 2003/08/20 12:06:15 russgold Exp $
005: *
006: * Copyright (c) 2002-2003, Russell Gold
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
009: * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
010: * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
011: * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included in all copies or substantial portions
014: * of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
017: * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
019: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
020: * DEALINGS IN THE SOFTWARE.
021: *
022: *******************************************************************************************************************/
023:
024: /**
025: * A class which represents the properties of a web client.
026: *
027: * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
028: **/
029: public class ClientProperties {
030:
031: /**
032: * Returns the current defaults for newly created web clients.
033: */
034: public static ClientProperties getDefaultProperties() {
035: return _defaultProperties;
036: }
037:
038: /**
039: * Specifies the ID information for a client.
040: */
041: public void setApplicationID(String applicationName,
042: String applicationCodeName, String applicationVersion) {
043: _applicationCodeName = applicationCodeName;
044: _applicationName = applicationName;
045: _applicationVersion = applicationVersion;
046: }
047:
048: public String getApplicationCodeName() {
049: return _applicationCodeName;
050: }
051:
052: public void setApplicationCodeName(String applicationCodeName) {
053: _applicationCodeName = applicationCodeName;
054: }
055:
056: public String getApplicationName() {
057: return _applicationName;
058: }
059:
060: public void setApplicationName(String applicationName) {
061: _applicationName = applicationName;
062: }
063:
064: public String getApplicationVersion() {
065: return _applicationVersion;
066: }
067:
068: public void setApplicationVersion(String applicationVersion) {
069: _applicationVersion = applicationVersion;
070: }
071:
072: /**
073: * Returns the user agent identification. Unless this has been set explicitly, it will default to the
074: * application code name followed by a slash and the application version.
075: */
076: public String getUserAgent() {
077: return _userAgent != null ? _userAgent : _applicationCodeName
078: + '/' + _applicationVersion;
079: }
080:
081: public void setUserAgent(String userAgent) {
082: _userAgent = userAgent;
083: }
084:
085: public String getPlatform() {
086: return _platform;
087: }
088:
089: public void setPlatform(String platform) {
090: _platform = platform;
091: }
092:
093: /**
094: * A shortcut for setting both availableScreenWidth and availableScreenHeight at one time.
095: */
096: public void setAvailableScreenSize(int width, int height) {
097: _availWidth = width;
098: _availHeight = height;
099: }
100:
101: public int getAvailableScreenWidth() {
102: return _availWidth;
103: }
104:
105: public void setAvailableScreenWidth(int availWidth) {
106: _availWidth = availWidth;
107: }
108:
109: public int getAvailHeight() {
110: return _availHeight;
111: }
112:
113: public void setAvailHeight(int availHeight) {
114: _availHeight = availHeight;
115: }
116:
117: /**
118: * Returns true if the client should accept and transmit cookies. The default is to accept them.
119: */
120: public boolean isAcceptCookies() {
121: return _acceptCookies;
122: }
123:
124: /**
125: * Specifies whether the client should accept and send cookies.
126: */
127: public void setAcceptCookies(boolean acceptCookies) {
128: _acceptCookies = acceptCookies;
129: }
130:
131: /**
132: * Returns true if the client will accept GZIP encoding of responses. The default is to accept GZIP encoding.
133: **/
134: public boolean isAcceptGzip() {
135: return _acceptGzip;
136: }
137:
138: /**
139: * Specifies whether the client will accept GZIP encoded responses. The default is true.
140: */
141: public void setAcceptGzip(boolean acceptGzip) {
142: _acceptGzip = acceptGzip;
143: }
144:
145: /**
146: * Returns true if the client should automatically follow page redirect requests (status 3xx).
147: * By default, this is true.
148: **/
149: public boolean isAutoRedirect() {
150: return _autoRedirect;
151: }
152:
153: /**
154: * Determines whether the client should automatically follow page redirect requests (status 3xx).
155: * By default, this is true in order to simulate normal browser operation.
156: **/
157: public void setAutoRedirect(boolean autoRedirect) {
158: _autoRedirect = autoRedirect;
159: }
160:
161: /**
162: * Returns true if the client should automatically follow page refresh requests.
163: * By default, this is false, so that programs can verify the redirect page presented
164: * to users before the browser switches to the new page.
165: **/
166: public boolean isAutoRefresh() {
167: return _autoRefresh;
168: }
169:
170: /**
171: * Specifies whether the client should automatically follow page refresh requests.
172: * By default, this is false, so that programs can verify the redirect page presented
173: * to users before the browser switches to the new page. Setting this to true can
174: * cause an infinite loop on pages that refresh themselves.
175: **/
176: public void setAutoRefresh(boolean autoRefresh) {
177: _autoRefresh = autoRefresh;
178: }
179:
180: public boolean isIframeSupported() {
181: return _iframeSupported;
182: }
183:
184: public void setIframeSupported(boolean iframeSupported) {
185: _iframeSupported = iframeSupported;
186: }
187:
188: /**
189: * Specifies a listener for DNS requests from the client.
190: */
191: public void setDnsListener(DNSListener dnsListener) {
192: _dnsListener = dnsListener;
193: }
194:
195: /**
196: * Returns the listener for DNS requests to be used by the client.
197: */
198: DNSListener getDnsListener() {
199: return _dnsListener;
200: }
201:
202: ClientProperties cloneProperties() {
203: return new ClientProperties(this );
204: }
205:
206: private String _applicationCodeName = "httpunit";
207: private String _applicationName = "HttpUnit";
208: private String _applicationVersion = "1.5";
209: private String _userAgent;
210: private String _platform = "Java";
211: private int _availWidth = 800;
212: private int _availHeight = 600;
213:
214: private boolean _iframeSupported = true;
215: private boolean _acceptCookies = true;
216: private boolean _acceptGzip = true;
217: private boolean _autoRedirect = true;
218: private boolean _autoRefresh = false;
219:
220: private DNSListener _dnsListener;
221:
222: private static ClientProperties _defaultProperties = new ClientProperties();
223:
224: private ClientProperties() {
225: }
226:
227: private ClientProperties(ClientProperties source) {
228: _applicationCodeName = source._applicationCodeName;
229: _applicationName = source._applicationName;
230: _applicationVersion = source._applicationVersion;
231: _userAgent = source._userAgent;
232: _platform = source._platform;
233: _iframeSupported = source._iframeSupported;
234: _acceptCookies = source._acceptCookies;
235: _acceptGzip = source._acceptGzip;
236: _autoRedirect = source._autoRedirect;
237: _autoRefresh = source._autoRefresh;
238: }
239: }
|