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;
039:
040: import java.io.Serializable;
041: import java.util.HashMap;
042: import java.util.Map;
043:
044: /**
045: * A collection of constants that represent the various ways a page can be
046: * submitted
047: *
048: * @version $Revision: 2132 $
049: * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
050: * @author Ahmed Ashour
051: * @author Marc Guillemot
052: */
053: public final class SubmitMethod implements Serializable {
054:
055: private static final long serialVersionUID = 6202782549629170616L;
056:
057: /**
058: * OPTIONS.
059: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
060: */
061: public static final SubmitMethod OPTIONS = new SubmitMethod(
062: "options");
063:
064: /**
065: * GET
066: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
067: */
068: public static final SubmitMethod GET = new SubmitMethod("get");
069:
070: /**
071: * HEAD.
072: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
073: */
074: public static final SubmitMethod HEAD = new SubmitMethod("head");
075:
076: /**
077: * POST
078: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
079: */
080: public static final SubmitMethod POST = new SubmitMethod("post");
081:
082: /**
083: * PUT
084: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
085: */
086: public static final SubmitMethod PUT = new SubmitMethod("put");
087:
088: /**
089: * DELETE.
090: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
091: */
092: public static final SubmitMethod DELETE = new SubmitMethod("delete");
093:
094: /**
095: * TRACE.
096: * @see <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
097: */
098: public static final SubmitMethod TRACE = new SubmitMethod("trace");
099:
100: private final String name_;
101: private static final Map methods_ = toMap(new SubmitMethod[] {
102: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE });
103:
104: private static Map toMap(final SubmitMethod[] methods) {
105: final HashMap map = new HashMap(methods.length);
106: for (int i = 0; i < methods.length; ++i) {
107: map.put(methods[i].getName(), methods[i]);
108: }
109: return map;
110: }
111:
112: private SubmitMethod(final String name) {
113: name_ = name;
114: }
115:
116: /**
117: * Return the name of this SubmitMethod
118: *
119: * @return See above
120: */
121: public String getName() {
122: return name_;
123: }
124:
125: /**
126: * Return the constant that matches the given name (case insensitive).
127: * @param name The name to search by
128: * @return see above
129: */
130: public static SubmitMethod getInstance(final String name) {
131: final SubmitMethod method = (SubmitMethod) methods_.get(name
132: .toLowerCase());
133: if (method == null) {
134: throw new IllegalArgumentException("No method found for ["
135: + name + "]");
136: }
137:
138: return method;
139: }
140:
141: /**
142: * Return a string representation of this object
143: *
144: * @return See above
145: */
146: public String toString() {
147: return "SubmitMethod[name=" + getName() + "]";
148: }
149: }
|