KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > WebContext


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.directwebremoting;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.servlet.ServletException JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import javax.servlet.http.HttpSession JavaDoc;
24
25 /**
26  * Class to enable us to access servlet parameters.
27  * @author Joe Walker [joe at getahead dot ltd dot uk]
28  */

29 public interface WebContext extends ServerContext
30 {
31     /**
32      * Get the script session that represents the currently viewed page in the
33      * same way that an HttpSession represents a cookie.
34      * @return A browser object for this user
35      */

36     ScriptSession getScriptSession();
37
38     /**
39      * What is the URL of the current page.
40      * This includes 'http://', up to (but not including) '?' or '#'
41      * @return The URL of the current page
42      */

43     String JavaDoc getCurrentPage();
44
45     /**
46      * Returns the current session associated with this request, or if the
47      * request does not have a session, creates one.
48      * @return Returns the http session.
49      * @see HttpServletRequest#getSession()
50      */

51     HttpSession JavaDoc getSession();
52
53     /**
54      * Returns the current HttpSession associated with this request or, if
55      * there is no current session and create is true, returns a new session.
56      * If create is false and the request has no valid HttpSession, this method
57      * returns null.
58      * @param create false to return null if there's no current session
59      * @return the session associated with this request
60      * @see HttpServletRequest#getSession(boolean)
61      */

62     HttpSession JavaDoc getSession(boolean create);
63
64     /**
65      * Accessor for the http request information.
66      * @return Returns the request.
67      */

68     HttpServletRequest JavaDoc getHttpServletRequest();
69
70     /**
71      * Accessor for the http response bean.
72      * <p>You can't use this request to directly reply to the response or to add
73      * headers or cookies.
74      * @return Returns the response.
75      */

76     HttpServletResponse JavaDoc getHttpServletResponse();
77
78     /**
79      * An attribute used by {@link WebContext#forwardToString(String)} to inform
80      * anyone that wants to know that this is a request from DWR.
81      */

82     public static final String JavaDoc ATTRIBUTE_DWR = "org.directwebremoting";
83
84     /**
85      * Forward a request to a given URL and catch the data written to it.
86      * It is possible to distinguish requests that arrive normally and requests
87      * that come from a DWR forwardToString() by the presence of a request
88      * attribute. Before the request is forwarded, DWR will call:
89      * <pre>
90      * request.setAttribute(WebContext.ATTRIBUTE_DWR, Boolean.TRUE);
91      * </pre>
92      * @param url The URL to forward to
93      * @return The text that results from forwarding to the given URL
94      * @throws IOException if the target resource throws this exception
95      * @throws ServletException if the target resource throws this exception
96      * @throws IllegalStateException if the response was already committed
97      */

98     String JavaDoc forwardToString(String JavaDoc url) throws ServletException JavaDoc, IOException JavaDoc;
99
100     /**
101      * For system use only: This method allows the system to fill in the session
102      * id and page id when they are discovered.
103      * @param page The URL of the current page
104      * @param scriptSessionId The session id passed in by the browser
105      */

106     void setCurrentPageInformation(String JavaDoc page, String JavaDoc scriptSessionId);
107 }
108
Popular Tags