1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/message/HeaderValueParser.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.message; 1.32 + 1.33 +import ch.boye.httpclientandroidlib.HeaderElement; 1.34 +import ch.boye.httpclientandroidlib.NameValuePair; 1.35 +import ch.boye.httpclientandroidlib.ParseException; 1.36 +import ch.boye.httpclientandroidlib.util.CharArrayBuffer; 1.37 + 1.38 +/** 1.39 + * Interface for parsing header values into elements. 1.40 + * Instances of this interface are expected to be stateless and thread-safe. 1.41 + * 1.42 + * @since 4.0 1.43 + */ 1.44 +public interface HeaderValueParser { 1.45 + 1.46 + /** 1.47 + * Parses a header value into elements. 1.48 + * Parse errors are indicated as <code>RuntimeException</code>. 1.49 + * <p> 1.50 + * Some HTTP headers (such as the set-cookie header) have values that 1.51 + * can be decomposed into multiple elements. In order to be processed 1.52 + * by this parser, such headers must be in the following form: 1.53 + * </p> 1.54 + * <pre> 1.55 + * header = [ element ] *( "," [ element ] ) 1.56 + * element = name [ "=" [ value ] ] *( ";" [ param ] ) 1.57 + * param = name [ "=" [ value ] ] 1.58 + * 1.59 + * name = token 1.60 + * value = ( token | quoted-string ) 1.61 + * 1.62 + * token = 1*<any char except "=", ",", ";", <"> and 1.63 + * white space> 1.64 + * quoted-string = <"> *( text | quoted-char ) <"> 1.65 + * text = any char except <"> 1.66 + * quoted-char = "\" char 1.67 + * </pre> 1.68 + * <p> 1.69 + * Any amount of white space is allowed between any part of the 1.70 + * header, element or param and is ignored. A missing value in any 1.71 + * element or param will be stored as the empty {@link String}; 1.72 + * if the "=" is also missing <var>null</var> will be stored instead. 1.73 + * </p> 1.74 + * 1.75 + * @param buffer buffer holding the header value to parse 1.76 + * @param cursor the parser cursor containing the current position and 1.77 + * the bounds within the buffer for the parsing operation 1.78 + * 1.79 + * @return an array holding all elements of the header value 1.80 + * 1.81 + * @throws ParseException in case of a parse error 1.82 + */ 1.83 + HeaderElement[] parseElements( 1.84 + CharArrayBuffer buffer, 1.85 + ParserCursor cursor) throws ParseException; 1.86 + 1.87 + /** 1.88 + * Parses a single header element. 1.89 + * A header element consist of a semicolon-separate list 1.90 + * of name=value definitions. 1.91 + * 1.92 + * @param buffer buffer holding the element to parse 1.93 + * @param cursor the parser cursor containing the current position and 1.94 + * the bounds within the buffer for the parsing operation 1.95 + * 1.96 + * @return the parsed element 1.97 + * 1.98 + * @throws ParseException in case of a parse error 1.99 + */ 1.100 + HeaderElement parseHeaderElement( 1.101 + CharArrayBuffer buffer, 1.102 + ParserCursor cursor) throws ParseException; 1.103 + 1.104 + /** 1.105 + * Parses a list of name-value pairs. 1.106 + * These lists are used to specify parameters to a header element. 1.107 + * Parse errors are indicated as <code>ParseException</code>. 1.108 + * 1.109 + * @param buffer buffer holding the name-value list to parse 1.110 + * @param cursor the parser cursor containing the current position and 1.111 + * the bounds within the buffer for the parsing operation 1.112 + * 1.113 + * @return an array holding all items of the name-value list 1.114 + * 1.115 + * @throws ParseException in case of a parse error 1.116 + */ 1.117 + NameValuePair[] parseParameters( 1.118 + CharArrayBuffer buffer, 1.119 + ParserCursor cursor) throws ParseException; 1.120 + 1.121 + 1.122 + /** 1.123 + * Parses a name=value specification, where the = and value are optional. 1.124 + * 1.125 + * @param buffer the buffer holding the name-value pair to parse 1.126 + * @param cursor the parser cursor containing the current position and 1.127 + * the bounds within the buffer for the parsing operation 1.128 + * 1.129 + * @return the name-value pair, where the value is <code>null</code> 1.130 + * if no value is specified 1.131 + */ 1.132 + NameValuePair parseNameValuePair( 1.133 + CharArrayBuffer buffer, 1.134 + ParserCursor cursor) throws ParseException; 1.135 + 1.136 +} 1.137 +