1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.http.message; 29 30 import org.apache.http.HeaderElement; 31 import org.apache.http.NameValuePair; 32 import org.apache.http.util.CharArrayBuffer; 33 34 /** 35 * Interface for formatting elements of a header value. 36 * This is the complement to {@link HeaderValueParser}. 37 * Instances of this interface are expected to be stateless and thread-safe. 38 * 39 * <p> 40 * All formatting methods accept an optional buffer argument. 41 * If a buffer is passed in, the formatted element will be appended 42 * and the modified buffer is returned. If no buffer is passed in, 43 * a new buffer will be created and filled with the formatted element. 44 * In both cases, the caller is allowed to modify the returned buffer. 45 * </p> 46 * 47 * @since 4.0 48 */ 49 public interface HeaderValueFormatter { 50 51 /** 52 * Formats an array of header elements. 53 * 54 * @param buffer the buffer to append to, or 55 * {@code null} to create a new buffer 56 * @param elems the header elements to format 57 * @param quote {@code true} to always format with quoted values, 58 * {@code false} to use quotes only when necessary 59 * 60 * @return a buffer with the formatted header elements. 61 * If the {@code buffer} argument was not {@code null}, 62 * that buffer will be used and returned. 63 */ 64 CharArrayBufferg/apache/http/util/CharArrayBuffer.html#CharArrayBuffer">CharArrayBuffer formatElements(CharArrayBuffer buffer, 65 HeaderElement[] elems, 66 boolean quote); 67 68 /** 69 * Formats one header element. 70 * 71 * @param buffer the buffer to append to, or 72 * {@code null} to create a new buffer 73 * @param elem the header element to format 74 * @param quote {@code true} to always format with quoted values, 75 * {@code false} to use quotes only when necessary 76 * 77 * @return a buffer with the formatted header element. 78 * If the {@code buffer} argument was not {@code null}, 79 * that buffer will be used and returned. 80 */ 81 CharArrayBufferche/http/util/CharArrayBuffer.html#CharArrayBuffer">CharArrayBuffer formatHeaderElement(CharArrayBuffer buffer, 82 HeaderElement elem, 83 boolean quote); 84 85 /** 86 * Formats the parameters of a header element. 87 * That's a list of name-value pairs, to be separated by semicolons. 88 * This method will <i>not</i> generate a leading semicolon. 89 * 90 * @param buffer the buffer to append to, or 91 * {@code null} to create a new buffer 92 * @param nvps the parameters (name-value pairs) to format 93 * @param quote {@code true} to always format with quoted values, 94 * {@code false} to use quotes only when necessary 95 * 96 * @return a buffer with the formatted parameters. 97 * If the {@code buffer} argument was not {@code null}, 98 * that buffer will be used and returned. 99 */ 100 CharArrayBufferapache/http/util/CharArrayBuffer.html#CharArrayBuffer">CharArrayBuffer formatParameters(CharArrayBuffer buffer, 101 NameValuePair[] nvps, 102 boolean quote); 103 104 /** 105 * Formats one name-value pair, where the value is optional. 106 * 107 * @param buffer the buffer to append to, or 108 * {@code null} to create a new buffer 109 * @param nvp the name-value pair to format 110 * @param quote {@code true} to always format with a quoted value, 111 * {@code false} to use quotes only when necessary 112 * 113 * @return a buffer with the formatted name-value pair. 114 * If the {@code buffer} argument was not {@code null}, 115 * that buffer will be used and returned. 116 */ 117 CharArrayBufferche/http/util/CharArrayBuffer.html#CharArrayBuffer">CharArrayBuffer formatNameValuePair(CharArrayBuffer buffer, 118 NameValuePair nvp, 119 boolean quote); 120 121 } 122