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