You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by mw...@apache.org on 2007/08/28 02:01:33 UTC

svn commit: r570273 - in /mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util: ./ AsyncHttpClientException.java DateParseException.java DateUtil.java EncodingUtil.java LangUtils.java NameValuePair.java

Author: mwebb
Date: Mon Aug 27 17:01:32 2007
New Revision: 570273

URL: http://svn.apache.org/viewvc?rev=570273&view=rev
Log:
initial check-in.  much is left to do in the commenting section.  This will at least get the ball rolling and allow others to make updates.

Added:
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/AsyncHttpClientException.java
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateParseException.java
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateUtil.java
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/EncodingUtil.java
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/LangUtils.java
    mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/NameValuePair.java

Added: mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/AsyncHttpClientException.java
URL: http://svn.apache.org/viewvc/mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/AsyncHttpClientException.java?rev=570273&view=auto
==============================================================================
--- mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/AsyncHttpClientException.java (added)
+++ mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/AsyncHttpClientException.java Mon Aug 27 17:01:32 2007
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.mina.http.util;
+
+
+/**
+ * TODO AsyncHttpClientException.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AsyncHttpClientException extends Error
+{
+    private static final long serialVersionUID = 1L;
+
+
+    public AsyncHttpClientException()
+    {
+    }
+
+
+    public AsyncHttpClientException( String string )
+    {
+        super( string );
+    }
+
+
+    public AsyncHttpClientException( String string, Throwable throwable )
+    {
+        super( string, throwable );
+    }
+
+
+    public AsyncHttpClientException( Throwable throwable )
+    {
+        super( throwable );
+    }
+}

Added: mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateParseException.java
URL: http://svn.apache.org/viewvc/mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateParseException.java?rev=570273&view=auto
==============================================================================
--- mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateParseException.java (added)
+++ mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateParseException.java Mon Aug 27 17:01:32 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.mina.http.util;
+
+
+/**
+ * An exception to indicate an error parsing a date string.
+ *
+ * @see DateUtil
+ *
+ * @author Michael Becke
+ */
+public class DateParseException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     *
+     */
+    public DateParseException() {
+        super();
+    }
+
+    /**
+     * @param message the exception message
+     */
+    public DateParseException(String message) {
+        super(message);
+    }
+
+}
+

Added: mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateUtil.java
URL: http://svn.apache.org/viewvc/mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateUtil.java?rev=570273&view=auto
==============================================================================
--- mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateUtil.java (added)
+++ mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/DateUtil.java Mon Aug 27 17:01:32 2007
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.mina.http.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.TimeZone;
+
+
+/**
+ * A utility class for parsing and formatting HTTP dates as used in cookies and
+ * other headers.  This class handles dates as defined by RFC 2616 section
+ * 3.3.1 as well as some other common non-standard formats.
+ *
+ * @author Christopher Brown
+ * @author Michael Becke
+ */
+public class DateUtil {
+
+    /**
+     * Date format pattern used to parse HTTP date headers in RFC 1123 format.
+     */
+    public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
+
+    /**
+     * Date format pattern used to parse HTTP date headers in RFC 1036 format.
+     */
+    public static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz";
+
+    /**
+     * Date format pattern used to parse HTTP date headers in ANSI C
+     * <code>asctime()</code> format.
+     */
+    public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
+
+    private static final Collection DEFAULT_PATTERNS = Arrays.asList(
+    		new String[] { PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123 } );
+
+    private static final Date DEFAULT_TWO_DIGIT_YEAR_START;
+
+    static {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(2000, Calendar.JANUARY, 1, 0, 0);
+        DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime();
+    }
+
+    private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
+    /**
+     * Parses a date value.  The formats used for parsing the date value are retrieved from
+     * the default http params.
+     *
+     * @param dateValue the date value to parse
+     *
+     * @return the parsed date
+     *
+     * @throws DateParseException if the value could not be parsed using any of the
+     * supported date formats
+     */
+    public static Date parseDate(String dateValue) throws DateParseException {
+        return parseDate(dateValue, null, null);
+    }
+
+    /**
+     * Parses the date value using the given date formats.
+     *
+     * @param dateValue the date value to parse
+     * @param dateFormats the date formats to use
+     *
+     * @return the parsed date
+     *
+     * @throws DateParseException if none of the dataFormats could parse the dateValue
+     */
+    public static Date parseDate(String dateValue, Collection dateFormats)
+        throws DateParseException {
+        return parseDate(dateValue, dateFormats, null);
+    }
+
+    /**
+     * Parses the date value using the given date formats.
+     *
+     * @param dateValue the date value to parse
+     * @param dateFormats the date formats to use
+     * @param startDate During parsing, two digit years will be placed in the range
+     * <code>startDate</code> to <code>startDate + 100 years</code>. This value may
+     * be <code>null</code>. When <code>null</code> is given as a parameter, year
+     * <code>2000</code> will be used.
+     *
+     * @return the parsed date
+     *
+     * @throws DateParseException if none of the dataFormats could parse the dateValue
+     */
+    public static Date parseDate(
+        String dateValue,
+        Collection dateFormats,
+        Date startDate
+    ) throws DateParseException {
+
+        if (dateValue == null) {
+            throw new IllegalArgumentException("dateValue is null");
+        }
+        if (dateFormats == null) {
+        	dateFormats = DEFAULT_PATTERNS;
+        }
+        if (startDate == null) {
+            startDate = DEFAULT_TWO_DIGIT_YEAR_START;
+        }
+        // trim single quotes around date if present
+        // see issue #5279
+        if (dateValue.length() > 1
+            && dateValue.startsWith("'")
+            && dateValue.endsWith("'")
+        ) {
+            dateValue = dateValue.substring (1, dateValue.length() - 1);
+        }
+
+        SimpleDateFormat dateParser = null;
+        Iterator formatIter = dateFormats.iterator();
+
+        while (formatIter.hasNext()) {
+            String format = (String) formatIter.next();
+            if (dateParser == null) {
+                dateParser = new SimpleDateFormat(format, Locale.US);
+                dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
+                dateParser.set2DigitYearStart(startDate);
+            } else {
+                dateParser.applyPattern(format);
+            }
+            try {
+                return dateParser.parse(dateValue);
+            } catch (ParseException pe) {
+                // ignore this exception, we will try the next format
+            }
+        }
+
+        // we were unable to parse the date
+        throw new DateParseException("Unable to parse the date " + dateValue);
+    }
+
+    /**
+     * Formats the given date according to the RFC 1123 pattern.
+     *
+     * @param date The date to format.
+     * @return An RFC 1123 formatted date string.
+     *
+     * @see #PATTERN_RFC1123
+     */
+    public static String formatDate(Date date) {
+        return formatDate(date, PATTERN_RFC1123);
+    }
+
+    /**
+     * Formats the given date according to the specified pattern.  The pattern
+     * must conform to that used by the {@link SimpleDateFormat simple date
+     * format} class.
+     *
+     * @param date The date to format.
+     * @param pattern The pattern to use for formatting the date.
+     * @return A formatted date string.
+     *
+     * @throws IllegalArgumentException If the given date pattern is invalid.
+     *
+     * @see SimpleDateFormat
+     */
+    public static String formatDate(Date date, String pattern) {
+        if (date == null) throw new IllegalArgumentException("date is null");
+        if (pattern == null) throw new IllegalArgumentException("pattern is null");
+
+        SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
+        formatter.setTimeZone(GMT);
+        return formatter.format(date);
+    }
+
+    /** This class should not be instantiated. */
+    private DateUtil() { }
+
+}

Added: mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/EncodingUtil.java
URL: http://svn.apache.org/viewvc/mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/EncodingUtil.java?rev=570273&view=auto
==============================================================================
--- mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/EncodingUtil.java (added)
+++ mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/EncodingUtil.java Mon Aug 27 17:01:32 2007
@@ -0,0 +1,274 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.mina.http.util;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.codec.net.URLCodec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The home for utility methods that handle various encoding tasks.
+ *
+ * @author Michael Becke
+ * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 2.0 final
+ */
+public class EncodingUtil {
+
+    final static Logger LOG = LoggerFactory.getLogger(EncodingUtil.class);
+
+    /** Default content encoding chatset */
+    private static final String DEFAULT_CHARSET = "ISO-8859-1";
+
+    /**
+     * Form-urlencoding routine.
+     *
+     * The default encoding for all forms is `application/x-www-form-urlencoded'.
+     * A form data set is represented in this media type as follows:
+     *
+     * The form field names and values are escaped: space characters are replaced
+     * by `+', and then reserved characters are escaped as per [URL]; that is,
+     * non-alphanumeric characters are replaced by `%HH', a percent sign and two
+     * hexadecimal digits representing the ASCII code of the character. Line breaks,
+     * as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
+     *
+     * <p>
+     * if the given charset is not supported, ISO-8859-1 is used instead.
+     * </p>
+     *
+     * @param pairs the values to be encoded
+     * @param charset the character set of pairs to be encoded
+     *
+     * @return the urlencoded pairs
+     *
+     * @since 2.0 final
+     */
+     public static String formUrlEncode(NameValuePair[] pairs, String charset) {
+        try {
+            return doFormUrlEncode(pairs, charset);
+        } catch (UnsupportedEncodingException e) {
+            LOG.error("Encoding not supported: " + charset);
+            try {
+                return doFormUrlEncode(pairs, DEFAULT_CHARSET);
+            } catch (UnsupportedEncodingException fatal) {
+                // Should never happen. ISO-8859-1 must be supported on all JVMs
+                throw new AsyncHttpClientException("Encoding not supported: " +
+                    DEFAULT_CHARSET);
+            }
+        }
+    }
+
+    /**
+     * Form-urlencoding routine.
+     *
+     * The default encoding for all forms is `application/x-www-form-urlencoded'.
+     * A form data set is represented in this media type as follows:
+     *
+     * The form field names and values are escaped: space characters are replaced
+     * by `+', and then reserved characters are escaped as per [URL]; that is,
+     * non-alphanumeric characters are replaced by `%HH', a percent sign and two
+     * hexadecimal digits representing the ASCII code of the character. Line breaks,
+     * as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
+     *
+     * @param pairs the values to be encoded
+     * @param charset the character set of pairs to be encoded
+     *
+     * @return the urlencoded pairs
+     * @throws UnsupportedEncodingException if charset is not supported
+     *
+     * @since 2.0 final
+     */
+     private static String doFormUrlEncode(NameValuePair[] pairs, String charset)
+        throws UnsupportedEncodingException
+     {
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < pairs.length; i++) {
+            URLCodec codec = new URLCodec();
+            NameValuePair pair = pairs[i];
+            if (pair.getName() != null) {
+                if (i > 0) {
+                    buf.append("&");
+                }
+                buf.append(codec.encode(pair.getName(), charset));
+                buf.append("=");
+                if (pair.getValue() != null) {
+                    buf.append(codec.encode(pair.getValue(), charset));
+                }
+            }
+        }
+        return buf.toString();
+    }
+
+    /**
+     * Converts the byte array of HTTP content characters to a string. If
+     * the specified charset is not supported, default system encoding
+     * is used.
+     *
+     * @param data the byte array to be encoded
+     * @param offset the index of the first byte to encode
+     * @param length the number of bytes to encode
+     * @param charset the desired character encoding
+     * @return The result of the conversion.
+     *
+     * @since 3.0
+     */
+    public static String getString(
+        final byte[] data,
+        int offset,
+        int length,
+        String charset
+    ) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+
+        if (charset == null || charset.length() == 0) {
+            throw new IllegalArgumentException("charset may not be null or empty");
+        }
+
+        try {
+            return new String(data, offset, length, charset);
+        } catch (UnsupportedEncodingException e) {
+
+            if (LOG.isWarnEnabled()) {
+                LOG.warn("Unsupported encoding: " + charset + ". System encoding used");
+            }
+            return new String(data, offset, length);
+        }
+    }
+
+
+    /**
+     * Converts the byte array of HTTP content characters to a string. If
+     * the specified charset is not supported, default system encoding
+     * is used.
+     *
+     * @param data the byte array to be encoded
+     * @param charset the desired character encoding
+     * @return The result of the conversion.
+     *
+     * @since 3.0
+     */
+    public static String getString(final byte[] data, String charset) {
+        return getString(data, 0, data.length, charset);
+    }
+
+    /**
+     * Converts the specified string to a byte array.  If the charset is not supported the
+     * default system charset is used.
+     *
+     * @param data the string to be encoded
+     * @param charset the desired character encoding
+     * @return The resulting byte array.
+     *
+     * @since 3.0
+     */
+    public static byte[] getBytes(final String data, String charset) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("data may not be null");
+        }
+
+        if (charset == null || charset.length() == 0) {
+            throw new IllegalArgumentException("charset may not be null or empty");
+        }
+
+        try {
+            return data.getBytes(charset);
+        } catch (UnsupportedEncodingException e) {
+
+            if (LOG.isWarnEnabled()) {
+                LOG.warn("Unsupported encoding: " + charset + ". System encoding used.");
+            }
+
+            return data.getBytes();
+        }
+    }
+
+    /**
+     * Converts the specified string to byte array of ASCII characters.
+     *
+     * @param data the string to be encoded
+     * @return The string as a byte array.
+     *
+     * @since 3.0
+     */
+    public static byte[] getAsciiBytes(final String data) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+
+        try {
+            return data.getBytes("US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            throw new AsyncHttpClientException("HttpClient requires ASCII support");
+        }
+    }
+
+    /**
+     * Converts the byte array of ASCII characters to a string. This method is
+     * to be used when decoding content of HTTP elements (such as response
+     * headers)
+     *
+     * @param data the byte array to be encoded
+     * @param offset the index of the first byte to encode
+     * @param length the number of bytes to encode
+     * @return The string representation of the byte array
+     *
+     */
+    public static String getAsciiString(final byte[] data, int offset, int length) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+
+        try {
+            return new String(data, offset, length, "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            throw new AsyncHttpClientException("HttpClient requires ASCII support");
+        }
+    }
+
+    /**
+     * Converts the byte array of ASCII characters to a string. This method is
+     * to be used when decoding content of HTTP elements (such as response
+     * headers)
+     *
+     * @param data the byte array to be encoded
+     * @return The string representation of the byte array
+     *
+     */
+    public static String getAsciiString(final byte[] data) {
+        return getAsciiString(data, 0, data.length);
+    }
+
+    /**
+     * This class should not be instantiated.
+     */
+    private EncodingUtil() {
+    }
+
+}
+

Added: mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/LangUtils.java
URL: http://svn.apache.org/viewvc/mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/LangUtils.java?rev=570273&view=auto
==============================================================================
--- mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/LangUtils.java (added)
+++ mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/LangUtils.java Mon Aug 27 17:01:32 2007
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.mina.http.util;
+
+/**
+ * A set of utility methods to help produce consistent Object#equals(Object) and
+ * Object#hashCode methods.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ */
+public class LangUtils {
+
+    public static final int HASH_SEED = 17;
+    public static final int HASH_OFFSET = 37;
+
+    private LangUtils() {
+        super();
+    }
+
+    public static int hashCode(final int seed, final int hashcode) {
+        return seed * HASH_OFFSET + hashcode;
+    }
+
+    public static int hashCode(final int seed, final Object obj) {
+        return hashCode(seed, obj != null ? obj.hashCode() : 0);
+    }
+
+    public static int hashCode(final int seed, final boolean b) {
+        return hashCode(seed, b ? 1 : 0);
+    }
+
+    public static boolean equals(final Object obj1, final Object obj2) {
+        return obj1 == null ? obj2 == null : obj1.equals(obj2);
+    }
+
+}
+

Added: mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/NameValuePair.java
URL: http://svn.apache.org/viewvc/mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/NameValuePair.java?rev=570273&view=auto
==============================================================================
--- mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/NameValuePair.java (added)
+++ mina/trunk/mina-filter-codec-http/src/main/java/org/apache/mina/http/util/NameValuePair.java Mon Aug 27 17:01:32 2007
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.mina.http.util;
+
+import java.io.Serializable;
+
+
+public class NameValuePair  implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    
+    // ----------------------------------------------------------- Constructors
+
+    /**
+     * Default constructor.
+     *
+     */
+    public NameValuePair() {
+        this (null, null);
+    }
+
+    /**
+     * Constructor.
+     * @param name The name.
+     * @param value The value.
+     */
+    public NameValuePair(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    // ----------------------------------------------------- Instance Variables
+
+    /**
+     * Name.
+     */
+    private String name = null;
+
+    /**
+     * Value.
+     */
+    private String value = null;
+
+    // ------------------------------------------------------------- Properties
+
+    /**
+     * Set the name.
+     *
+     * @param name The new name
+     * @see #getName()
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    /**
+     * Return the name.
+     *
+     * @return String name The name
+     * @see #setName(String)
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * Set the value.
+     *
+     * @param value The new value.
+     */
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+
+    /**
+     * Return the current value.
+     *
+     * @return String value The current value.
+     */
+    public String getValue() {
+        return value;
+    }
+
+    // --------------------------------------------------------- Public Methods
+
+    /**
+     * Get a String representation of this pair.
+     * @return A string representation.
+     */
+    public String toString() {
+        return ("name=" + name + ", " + "value=" + value);
+    }
+
+    public boolean equals(final Object object) {
+        if (object == null) return false;
+        if (this == object) return true;
+        if (object instanceof NameValuePair) {
+            NameValuePair that = (NameValuePair) object;
+            return LangUtils.equals(this.name, that.name)
+                  && LangUtils.equals(this.value, that.value);
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        int hash = LangUtils.HASH_SEED;
+        hash = LangUtils.hashCode(hash, this.name);
+        hash = LangUtils.hashCode(hash, this.value);
+        return hash;
+    }
+}
+