View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.context;
35  
36  import info.magnolia.cms.beans.runtime.MultipartForm;
37  import info.magnolia.cms.core.AggregationState;
38  
39  import java.util.Map;
40  import java.io.IOException;
41  import java.io.Writer;
42  
43  import javax.servlet.http.HttpServletRequest;
44  import javax.servlet.http.HttpServletResponse;
45  import javax.servlet.jsp.PageContext;
46  import javax.servlet.ServletContext;
47  import javax.servlet.ServletException;
48  
49  
50  /**
51   * Context interface specialized for servlet requests; knows about HttpServletRequest/HttpServletResponse.
52   * 
53   * @author Philipp Bracher
54   * @version $Revision: 32667 $ ($Author: gjoseph $)
55   */
56  public interface WebContext extends Context {
57  
58      /**
59       * Attribute name to get the requests character encoding.
60       * @deprecated use AggregationState
61       */
62      public static final String ATTRIBUTE_REQUEST_CHARACTER_ENCODING = "characterEncoding";
63  
64      /**
65       * Attribute name to get the request uri
66       * @deprecated use AggregationState
67       */
68      public static final String ATTRIBUTE_REQUEST_URI = "requestURI";
69  
70      /**
71       * Method used to initialize the context.
72       */
73      public void init(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext);
74  
75      /**
76       * Retrieves the Aggregator instance, which gathers all info regarding the current request (paths, etc).
77       */
78      public AggregationState getAggregationState();
79  
80      /**
81       * Resets the current aggregator instance.
82       */
83      void resetAggregationState();
84  
85      /**
86       * Get form object assembled by <code>MultipartRequestFilter</code>.
87       * @return multipart form object
88       */
89      public MultipartForm getPostedForm();
90  
91      /**
92       * Get a parameter value as string.
93       * @return parameter value
94       */
95      public String getParameter(String name);
96  
97      /**
98       * Get all parameter values as a Map&lt;String, String&gt;.
99       * @return parameter values
100      */
101     public Map<String, String> getParameters();
102 
103     /**
104      * Get the current context path.
105      */
106     public String getContextPath();
107 
108     /**
109      * Avoid calls to this method wherever possible.
110      * @return Returns the request.
111      */
112     public HttpServletRequest getRequest();
113 
114     /**
115      * Avoid depending on this as much as possible.
116      */
117     public HttpServletResponse getResponse();
118 
119     /**
120      * Returns the current servlet context.
121      * @return ServletContext instance
122      */
123     ServletContext getServletContext();
124 
125     /**
126      * Includes/render the given path into the given Writer, by wrapping it in the current HttpServletResponse.
127      * @see javax.servlet.ServletRequest#getRequestDispatcher(String)
128      * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse) 
129      */
130     void include(final String path, final Writer out) throws ServletException, IOException;
131 
132     /**
133      * Sets the current jsp page context. Callers should take care of appropriately unset it
134      * once done with it. Typically a jsp renderer will setPageContext(null) after having rendered
135      * a jsp.
136      * @param pageContext jsp page context
137      */
138     void setPageContext(PageContext pageContext);
139 
140     /**
141      * Returns the current jsp page context, <strong>if any</strong>.
142      * @return jsp page context or null if it has not been populated by calling setPageContext
143      */
144     PageContext getPageContext();
145 
146     /**
147      * @param request
148      * @param response
149      */
150     public void push(HttpServletRequest request, HttpServletResponse response);
151 
152     /**
153      *
154      */
155     public void pop();
156 
157     /**
158      * Get parameter values as string[].
159      * @return parameter values
160      */
161     public String[] getParameterValues(String name);
162 
163 }