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