Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | * ==================================================================== |
michael@0 | 3 | * Licensed to the Apache Software Foundation (ASF) under one |
michael@0 | 4 | * or more contributor license agreements. See the NOTICE file |
michael@0 | 5 | * distributed with this work for additional information |
michael@0 | 6 | * regarding copyright ownership. The ASF licenses this file |
michael@0 | 7 | * to you under the Apache License, Version 2.0 (the |
michael@0 | 8 | * "License"); you may not use this file except in compliance |
michael@0 | 9 | * with the License. You may obtain a copy of the License at |
michael@0 | 10 | * |
michael@0 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 12 | * |
michael@0 | 13 | * Unless required by applicable law or agreed to in writing, |
michael@0 | 14 | * software distributed under the License is distributed on an |
michael@0 | 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
michael@0 | 16 | * KIND, either express or implied. See the License for the |
michael@0 | 17 | * specific language governing permissions and limitations |
michael@0 | 18 | * under the License. |
michael@0 | 19 | * ==================================================================== |
michael@0 | 20 | * |
michael@0 | 21 | * This software consists of voluntary contributions made by many |
michael@0 | 22 | * individuals on behalf of the Apache Software Foundation. For more |
michael@0 | 23 | * information on the Apache Software Foundation, please see |
michael@0 | 24 | * <http://www.apache.org/>. |
michael@0 | 25 | * |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | package ch.boye.httpclientandroidlib.message; |
michael@0 | 29 | |
michael@0 | 30 | import ch.boye.httpclientandroidlib.HeaderElement; |
michael@0 | 31 | import ch.boye.httpclientandroidlib.NameValuePair; |
michael@0 | 32 | import ch.boye.httpclientandroidlib.ParseException; |
michael@0 | 33 | import ch.boye.httpclientandroidlib.util.CharArrayBuffer; |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Interface for parsing header values into elements. |
michael@0 | 37 | * Instances of this interface are expected to be stateless and thread-safe. |
michael@0 | 38 | * |
michael@0 | 39 | * @since 4.0 |
michael@0 | 40 | */ |
michael@0 | 41 | public interface HeaderValueParser { |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Parses a header value into elements. |
michael@0 | 45 | * Parse errors are indicated as <code>RuntimeException</code>. |
michael@0 | 46 | * <p> |
michael@0 | 47 | * Some HTTP headers (such as the set-cookie header) have values that |
michael@0 | 48 | * can be decomposed into multiple elements. In order to be processed |
michael@0 | 49 | * by this parser, such headers must be in the following form: |
michael@0 | 50 | * </p> |
michael@0 | 51 | * <pre> |
michael@0 | 52 | * header = [ element ] *( "," [ element ] ) |
michael@0 | 53 | * element = name [ "=" [ value ] ] *( ";" [ param ] ) |
michael@0 | 54 | * param = name [ "=" [ value ] ] |
michael@0 | 55 | * |
michael@0 | 56 | * name = token |
michael@0 | 57 | * value = ( token | quoted-string ) |
michael@0 | 58 | * |
michael@0 | 59 | * token = 1*<any char except "=", ",", ";", <"> and |
michael@0 | 60 | * white space> |
michael@0 | 61 | * quoted-string = <"> *( text | quoted-char ) <"> |
michael@0 | 62 | * text = any char except <"> |
michael@0 | 63 | * quoted-char = "\" char |
michael@0 | 64 | * </pre> |
michael@0 | 65 | * <p> |
michael@0 | 66 | * Any amount of white space is allowed between any part of the |
michael@0 | 67 | * header, element or param and is ignored. A missing value in any |
michael@0 | 68 | * element or param will be stored as the empty {@link String}; |
michael@0 | 69 | * if the "=" is also missing <var>null</var> will be stored instead. |
michael@0 | 70 | * </p> |
michael@0 | 71 | * |
michael@0 | 72 | * @param buffer buffer holding the header value to parse |
michael@0 | 73 | * @param cursor the parser cursor containing the current position and |
michael@0 | 74 | * the bounds within the buffer for the parsing operation |
michael@0 | 75 | * |
michael@0 | 76 | * @return an array holding all elements of the header value |
michael@0 | 77 | * |
michael@0 | 78 | * @throws ParseException in case of a parse error |
michael@0 | 79 | */ |
michael@0 | 80 | HeaderElement[] parseElements( |
michael@0 | 81 | CharArrayBuffer buffer, |
michael@0 | 82 | ParserCursor cursor) throws ParseException; |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Parses a single header element. |
michael@0 | 86 | * A header element consist of a semicolon-separate list |
michael@0 | 87 | * of name=value definitions. |
michael@0 | 88 | * |
michael@0 | 89 | * @param buffer buffer holding the element to parse |
michael@0 | 90 | * @param cursor the parser cursor containing the current position and |
michael@0 | 91 | * the bounds within the buffer for the parsing operation |
michael@0 | 92 | * |
michael@0 | 93 | * @return the parsed element |
michael@0 | 94 | * |
michael@0 | 95 | * @throws ParseException in case of a parse error |
michael@0 | 96 | */ |
michael@0 | 97 | HeaderElement parseHeaderElement( |
michael@0 | 98 | CharArrayBuffer buffer, |
michael@0 | 99 | ParserCursor cursor) throws ParseException; |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Parses a list of name-value pairs. |
michael@0 | 103 | * These lists are used to specify parameters to a header element. |
michael@0 | 104 | * Parse errors are indicated as <code>ParseException</code>. |
michael@0 | 105 | * |
michael@0 | 106 | * @param buffer buffer holding the name-value list to parse |
michael@0 | 107 | * @param cursor the parser cursor containing the current position and |
michael@0 | 108 | * the bounds within the buffer for the parsing operation |
michael@0 | 109 | * |
michael@0 | 110 | * @return an array holding all items of the name-value list |
michael@0 | 111 | * |
michael@0 | 112 | * @throws ParseException in case of a parse error |
michael@0 | 113 | */ |
michael@0 | 114 | NameValuePair[] parseParameters( |
michael@0 | 115 | CharArrayBuffer buffer, |
michael@0 | 116 | ParserCursor cursor) throws ParseException; |
michael@0 | 117 | |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Parses a name=value specification, where the = and value are optional. |
michael@0 | 121 | * |
michael@0 | 122 | * @param buffer the buffer holding the name-value pair to parse |
michael@0 | 123 | * @param cursor the parser cursor containing the current position and |
michael@0 | 124 | * the bounds within the buffer for the parsing operation |
michael@0 | 125 | * |
michael@0 | 126 | * @return the name-value pair, where the value is <code>null</code> |
michael@0 | 127 | * if no value is specified |
michael@0 | 128 | */ |
michael@0 | 129 | NameValuePair parseNameValuePair( |
michael@0 | 130 | CharArrayBuffer buffer, |
michael@0 | 131 | ParserCursor cursor) throws ParseException; |
michael@0 | 132 | |
michael@0 | 133 | } |
michael@0 | 134 |