View Javadoc
1   /**
2    * This file Copyright (c) 2003-2017 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.io.IOException;
40  import java.io.Writer;
41  import java.util.Map;
42  
43  import javax.servlet.ServletContext;
44  import javax.servlet.ServletException;
45  import javax.servlet.http.HttpServletRequest;
46  import javax.servlet.http.HttpServletResponse;
47  import javax.servlet.jsp.PageContext;
48  
49  
50  /**
51   * Context interface specialized for servlet requests; knows about HttpServletRequest/HttpServletResponse.
52   */
53  public interface WebContext extends Context {
54  
55      /**
56       * Attribute name to get the requests character encoding.
57       *
58       * @deprecated since 5.3.3 use AggregationState
59       */
60      @Deprecated
61      public static final String ATTRIBUTE_REQUEST_CHARACTER_ENCODING = "characterEncoding";
62  
63      /**
64       * Attribute name to get the request uri.
65       *
66       * @deprecated since 5.3.3 use AggregationState
67       */
68      @Deprecated
69      public static final String ATTRIBUTE_REQUEST_URI = "requestURI";
70  
71      /**
72       * Method used to initialize the context.
73       */
74      public void init(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext);
75  
76      /**
77       * Retrieves the Aggregator instance, which gathers all info regarding the current request (paths, etc).
78       */
79      public AggregationState getAggregationState();
80  
81      /**
82       * Resets the current aggregator instance.
83       */
84      void resetAggregationState();
85  
86      /**
87       * Get form object assembled by <code>MultipartRequestFilter</code>.
88       *
89       * @return multipart form object
90       */
91      public MultipartForm getPostedForm();
92  
93      /**
94       * Get a parameter value as string.
95       *
96       * @return parameter value
97       */
98      public String getParameter(String name);
99  
100     /**
101      * Get all parameter values as a Map&lt;String, String&gt;.
102      *
103      * @return parameter values
104      */
105     public Map<String, String> getParameters();
106 
107     /**
108      * Get the current context path.
109      */
110     public String getContextPath();
111 
112     /**
113      * Avoid calls to this method wherever possible.
114      *
115      * @return Returns the request.
116      */
117     public HttpServletRequest getRequest();
118 
119     /**
120      * Avoid depending on this as much as possible.
121      */
122     public HttpServletResponse getResponse();
123 
124     /**
125      * Returns the current servlet context.
126      *
127      * @return ServletContext instance
128      */
129     ServletContext getServletContext();
130 
131     /**
132      * Includes/render the given path into the given Writer, by wrapping it in the current HttpServletResponse.
133      *
134      * @see javax.servlet.ServletRequest#getRequestDispatcher(String)
135      * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
136      */
137     void include(final String path, final Writer out) throws ServletException, IOException;
138 
139     /**
140      * Sets the current jsp page context. Callers should take care of appropriately unset it
141      * once done with it. Typically a jsp renderer will setPageContext(null) after having rendered
142      * a jsp.
143      *
144      * @param pageContext jsp page context
145      */
146     void setPageContext(PageContext pageContext);
147 
148     /**
149      * Returns the current jsp page context, <strong>if any</strong>.
150      *
151      * @return jsp page context or null if it has not been populated by calling setPageContext
152      */
153     PageContext getPageContext();
154 
155     public void push(HttpServletRequest request, HttpServletResponse response);
156 
157     /**
158      *
159      */
160     public void pop();
161 
162     /**
163      * Get parameter values as string[].
164      *
165      * @return parameter values
166      */
167     public String[] getParameterValues(String name);
168 
169 }