httpfactory.java
来自「很棒的web服务器源代码」· Java 代码 · 共 740 行 · 第 1/2 页
JAVA
740 行
// HttpFactory.java// $Id: HttpFactory.java,v 1.4 2000/08/16 21:37:59 ylafon Exp $// (c) COPYRIGHT MIT and INRIA, 1996.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.www.http;import org.w3c.www.mime.MimeType;/** * Use this class to create pre-defined header values of various kind. */public class HttpFactory { /** * Create an <code>Accept</code> header clause. * @param type The MIME type that you will accept. * @param quality The quality you are willing to set to that MIME type. * @return An instance of <strong>HttpAccept</strong>. * @see HttpAccept */ public static HttpAccept makeAccept(MimeType type, double quality) { return new HttpAccept(true, type, quality); } /** * Create an <code>Accept</code> header clause. * This will be assigned the default <strong>1.0</strong> quality. * @param type The MIME type that you will accept. * @return An instance of <strong>HttpAccept</strong>. * @see HttpAccept */ public static HttpAccept makeAccept(MimeType type) { return new HttpAccept(true, type, (double) 1.0); } /** * Build an accept object by parsing the given string. * @param strval The String to parse. * @return An HttpAccept instance. */ public static HttpAccept parseAccept(String strval) { HttpAccept a = new HttpAccept(); a.setString(strval); return a; } /** * Build a list of accept clause, ready for the <code>Accept</code> header. * @param accepts The various accept clauses, as build through calls to * <code>makeAccept</code> and gathered in an array, or <strong>null * </strong> to create an empty list. * @return An instance of <strojng>HttpAcceptList</code>. * @see HttpAcceptList */ public static HttpAcceptList makeAcceptList(HttpAccept accepts[]) { if ( accepts == null ) return new HttpAcceptList(null); else return new HttpAcceptList(accepts); } /** * Build an accept list object by parsing the given string. * @param strval The String to parse. * @return An HttpAcceptList instance. */ public static HttpAcceptList parseAcceptList(String strval) { HttpAcceptList a = new HttpAcceptList(); a.setString(strval); return a; } /** * Build an <code>Accept-Charset</code> header clause. * @param charset The accepted charset. * @param quality The quality under which this charset is accepted. * @return An instance of HttpAcceptCharset. * @see HttpAcceptCharset */ public static HttpAcceptCharset makeAcceptCharset(String charset , double quality) { return new HttpAcceptCharset(true, charset, quality); } /** * Build an <code>Accept-Charset</code> header clause. * Uses the default <strong>1.0</strong> quality. * @param charset The accepted charset. * @return An instance of HttpAcceptCharset. * @see HttpAcceptCharset */ public static HttpAcceptCharset makeAcceptCharset(String charset) { return new HttpAcceptCharset(true, charset, (double) 1.0); } /** * Build an accept charset object by parsing the given string. * @param strval The String to parse. * @return An HttpAcceptCharset instance. */ public static HttpAcceptCharset parseAcceptCharset(String strval) { HttpAcceptCharset a = new HttpAcceptCharset(); a.setString(strval); return a; } /** * Build a list of accepted charset for the <code>Accept-Charset</code> * header. * @param charsets A list of accepted charsets, encoded as an array * or <strong>null</strong> to create an empty list. * @return An instance of HttpAcceptCharsetList. * @see HttpAcceptCharsetList */ public static HttpAcceptCharsetList makeAcceptCharsetList(HttpAcceptCharset charsets[]) { return new HttpAcceptCharsetList(charsets); } /** * Build an accept charset list object by parsing the given string. * @param strval The String to parse. * @return An HttpAcceptCharsetList instance. */ public static HttpAcceptCharsetList parseAcceptCharsetList(String strval) { HttpAcceptCharsetList a = new HttpAcceptCharsetList(); a.setString(strval); return a; } /** * Build an <code>Accept-Encoding</code> header clause. * @param enc The accepted encoding. * @param quality The quality at which this encoding is accepted. * @return An instance of HttpAcceptEncoding. * @see HttpAcceptEncoding */ public static HttpAcceptEncoding makeAcceptEncoding(String enc , double quality) { return new HttpAcceptEncoding(true, enc, quality); } /** * Build an <code>Accept-Encoding</code> header clause. * Uses the default <strong>1.0</strong> quality. * @param enc The accepted encoding. * @return An instance of HttpAcceptEncoding. * @see HttpAcceptEncoding */ public static HttpAcceptEncoding makeAcceptEncoding(String enc) { return new HttpAcceptEncoding(true, enc, (double) 1.0); } /** * Build an accept encoding object by parsing the given string. * @param strval The String to parse. * @return An HttpAcceptLanguage instance. */ public static HttpAcceptEncoding parseAcceptEncoding(String strval) { HttpAcceptEncoding e = new HttpAcceptEncoding(); e.setString(strval); return e; } /** * Build an <code>Accept-Language</code> header clause. * @param lang The accepted language. * @param quality The quality at which this language is accepted. * @return An instance of HttpAcceptLanguage. * @see HttpAcceptLanguage */ public static HttpAcceptLanguage makeAcceptLanguage(String lang , double quality) { return new HttpAcceptLanguage(true, lang, quality); } /** * Build an <code>Accept-Language</code> header clause. * Uses the default <strong>1.0</strong> quality. * @param lang The accepted language. * @return An instance of HttpAcceptLanguage. * @see HttpAcceptLanguage */ public static HttpAcceptLanguage makeAcceptLanguage(String lang) { return new HttpAcceptLanguage(true, lang, (double) 1.0); } /** * Build an accept language object by parsing the given string. * @param strval The String to parse. * @return An HttpAcceptLanguage instance. */ public static HttpAcceptLanguage parseAcceptLanguage(String strval) { HttpAcceptLanguage a = new HttpAcceptLanguage(); a.setString(strval); return a; } /** * Build a list of accept language clauses for the <code>Accept-Language * </code> header. * @param langs A list of accepted languages, encoded as an array, or * <strong>null</strong> to create an empty list. */ public static HttpAcceptLanguageList makeAcceptLanguageList(HttpAcceptLanguage langs[]) { return new HttpAcceptLanguageList(langs); } /** * Build an accept language list object by parsing the given string. * @param strval The String to parse. * @return An HttpAcceptLanguageList instance. */ public static HttpAcceptLanguageList parseAcceptLanguageList(String strval) { HttpAcceptLanguageList a = new HttpAcceptLanguageList(); a.setString(strval); return a; } /** * Build a empty bag instance. * Bags are used in PEP and PICS. * @param name The name of the bag to construct. * @return An empty bag instance. * @see HttpBag */ public static HttpBag makeBag(String name) { return new HttpBag(true, name); } /** * Build a bag object by parsing the given string. * @param strval The String to parse. * @return An HttpBag instance. */ public static HttpBag parseBag(String strval) { HttpBag a = new HttpBag(); a.setString(strval); return a; } /** * Build an empty cache control directive. * @return An instance of HttpCacheControl, with default settings. * @see HttpCacheControl */ public static HttpCacheControl makeCacheControl() { return new HttpCacheControl(true); } /** * Build a cache control object by parsing the given string. * @param strval The String to parse. * @return An HttpCacheControl instance. */ public static HttpCacheControl parseCacheControl(String strval) { HttpCacheControl a = new HttpCacheControl(); a.setString(strval); return a; } /** * Build a challenge requesting authorization from a client. * @param scheme The scheme used by that challenge. * @return An HttpChallenge instance. * @see HttpChallenge */ public static HttpChallenge makeChallenge(String scheme) { return new HttpChallenge(true, scheme); } /** * Build a challenge object by parsing the given string. * @param strval The String to parse. * @return An HttpChallenge instance. */ public static HttpChallenge parseChallenge(String strval) { HttpChallenge a = new HttpChallenge(); a.setString(strval); return a; } /** * Build the description of a HTTP content range. * @param unit The unit of that range. * @param firstpos The first position of that range (can be <strong>-1 * </strong> to indicate a postfix range. * @param lastpost The last position of that range (can be <strong>-1 * </strong> to indicate a prefix range). * @param length The full length of the entity from which that range was * taken. * @return An instance of HttpContentRange. * @see HttpContentRange */ public static HttpContentRange makeContentRange(String unit , int firstpos , int lastpos , int length) { return new HttpContentRange(true, unit, firstpos, lastpos, length); } /** * Build a content range object by parsing the given string. * @param strval The String to parse. * @return An HttpContantRange instance. */ public static HttpContentRange parseContentRange(String strval) { HttpContentRange a = new HttpContentRange(); a.setString(strval); return a; } /** * Build a single cookie value. * @param name The name of that cookie. * @param value The value of that cookie. * @return An instance of HttpCookie. * @see HttpCookie */ public static HttpCookie makeCookie(String name, String value) { return new HttpCookie(true, name, value); } /** * Build a list of cookies out of a set of cookies. * @param cookies The cookies to be added to the list, may be * <strong>null</strong> to create an empty list. * @return An instance of HttpCookieList. * @see HttpCookieList */ public static HttpCookieList makeCookieList(HttpCookie cookies[]) { return new HttpCookieList(cookies); } /** * Build a cookie list object by parsing the given string. * @param strval The String to parse. * @return An HttpCookieList instance.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?