1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.util;
24  
25  import java.io.IOException;
26  
27  import java.net.URL;
28  
29  import java.util.Map;
30  
31  import javax.portlet.ActionRequest;
32  import javax.portlet.RenderRequest;
33  
34  import javax.servlet.http.Cookie;
35  import javax.servlet.http.HttpServletRequest;
36  
37  /**
38   * <a href="Http.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   *
42   */
43  public interface Http {
44  
45      public static final String HTTP = "http";
46  
47      public static final String HTTPS = "https";
48  
49      public static final String HTTP_WITH_SLASH = "http://";
50  
51      public static final String HTTPS_WITH_SLASH = "https://";
52  
53      public static final int HTTP_PORT = 80;
54  
55      public static final int HTTPS_PORT = 443;
56  
57      public static final String PROTOCOL_DELIMITER = "://";
58  
59      public String addParameter(String url, String name, boolean value);
60  
61      public String addParameter(String url, String name, double value);
62  
63      public String addParameter(String url, String name, int value);
64  
65      public String addParameter(String url, String name, long value);
66  
67      public String addParameter(String url, String name, short value);
68  
69      public String addParameter(String url, String name, String value);
70  
71      public String decodeURL(String url);
72  
73      public String decodeURL(String url, boolean unescapeSpace);
74  
75      public String encodeURL(String url);
76  
77      public String encodeURL(String url, boolean escapeSpaces);
78  
79      public String getCompleteURL(HttpServletRequest request);
80  
81      public String getDomain(String url);
82  
83      public String getParameter(String url, String name);
84  
85      public String getParameter(String url, String name, boolean escaped);
86  
87      public Map<String, String[]> getParameterMap(String queryString);
88  
89      public String getProtocol(boolean secure);
90  
91      public String getProtocol(String url);
92  
93      public String getProtocol(HttpServletRequest request);
94  
95      public String getProtocol(ActionRequest actionRequest);
96  
97      public String getProtocol(RenderRequest renderRequest);
98  
99      public String getQueryString(String url);
100 
101     public String getRequestURL(HttpServletRequest request);
102 
103     public boolean hasProxyConfig();
104 
105     public boolean isNonProxyHost(String host);
106 
107     public boolean isProxyHost(String host);
108 
109     public Map<String, String[]> parameterMapFromString(String queryString);
110 
111     public String parameterMapToString(Map<String, String[]> parameterMap);
112 
113     public String parameterMapToString(
114         Map<String, String[]> parameterMap, boolean addQuestion);
115 
116     public String protocolize(String url, boolean secure);
117 
118     public String protocolize(String url, HttpServletRequest request);
119 
120     public String protocolize(String url, ActionRequest actionRequest);
121 
122     public String protocolize(String url, RenderRequest renderRequest);
123 
124     public String removeParameter(String url, String name);
125 
126     public String removeProtocol(String url);
127 
128     public void submit(String location) throws IOException;
129 
130     public void submit(String location, Cookie[] cookies) throws IOException;
131 
132     public void submit(String location, boolean post) throws IOException;
133 
134     public void submit(String location, Cookie[] cookies, boolean post)
135         throws IOException;
136 
137     public void submit(
138             String location, Cookie[] cookies, Map<String, String> parts,
139             boolean post)
140         throws IOException;
141 
142     public byte[] URLtoByteArray(String location) throws IOException;
143 
144     public byte[] URLtoByteArray(String location, Cookie[] cookies)
145         throws IOException;
146 
147     public byte[] URLtoByteArray(String location, boolean post)
148         throws IOException;
149 
150     public byte[] URLtoByteArray(
151             String location, Cookie[] cookies, boolean post)
152         throws IOException;
153 
154     public byte[] URLtoByteArray(
155             String location, Cookie[] cookies, Map<String, String> parts,
156             boolean post)
157         throws IOException;
158 
159     public String URLtoString(String location) throws IOException;
160 
161     public String URLtoString(String location, Cookie[] cookies)
162         throws IOException;
163 
164     public String URLtoString(String location, boolean post) throws IOException;
165 
166     public String URLtoString(
167             String location, Cookie[] cookies, boolean post)
168         throws IOException;
169 
170     public String URLtoString(
171             String location, Cookie[] cookies, Map<String, String> parts,
172             boolean post)
173         throws IOException;
174 
175     public String URLtoString(
176             String location, String host, int port, String realm,
177             String username, String password)
178         throws IOException;
179 
180     /**
181      * This method only uses the default Commons HttpClient implementation when
182      * the URL object represents a HTTP resource. The URL object could also
183      * represent a file or some JNDI resource. In that case, the default Java
184      * implementation is used.
185      *
186      * @param       url URL object
187      * @return      A string representation of the resource referenced by the
188      *              URL object
189      * @throws      IOException
190      */
191     public String URLtoString(URL url) throws IOException;
192 
193 }