KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > webpage > JetspeedSiteSession


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
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
17 package org.apache.jetspeed.services.webpage;
18
19 // java.io
20
import java.io.IOException JavaDoc;
21
22 // javax.servlet
23
import javax.servlet.http.*;
24
25 // java.net
26
import java.net.URLConnection JavaDoc;
27
28 import org.apache.log4j.Logger;
29
30 import org.apache.jetspeed.util.rewriter.HTMLRewriter;
31
32 /**
33  * <p>Represents a session with a site</p>
34  *
35  * <p>This class extends AbstractSiteSession, implementing
36  * the specific code login and logout to a site. The content rewriter
37  * is also specialized here to handle the specific needs </p>
38
39  *
40  * <p>Sessions are stored in the SessionMap per Jetspeed Session.
41  * (The SessionMap is stored in the Servlet Session)</p>
42  *
43  */

44
45 public class JetspeedSiteSession extends AbstractSiteSession
46 {
47
48     Site site;
49
50     // the User Name owning this session
51
String JavaDoc userName;
52
53     // the log file singleton instance
54
static Logger log = Logger.getLogger(JetspeedSiteSession.class);
55
56     /**
57      * Create a session, which maintains sessions with one website.
58      *
59      * @param site the site to manage.
60      * @param targetBase the target host's base URL
61      * @param proxyBase the proxy server host URL base address.
62      */

63     public JetspeedSiteSession(Site site,
64                                String JavaDoc proxyBase,
65                                String JavaDoc userName)
66     {
67         super(site.getURL(), proxyBase);
68         this.site = site;
69         this.userName = userName;
70     }
71
72     /**
73      * Logs on to the Secured site 'automatically', using a predefined
74      * exchange based on a logon-screen POST to the site,
75      * sending the logon credentials and security permissions.
76      *
77      * @param data the request specific rundata.
78      *
79      * @exception IOException a servlet exception.
80      */

81     public boolean logon(ProxyRunData data)
82                        throws IOException JavaDoc
83     {
84         return true;
85     }
86
87
88     /**
89      * Reads stream from proxied host, runs HTML parser against that stream,
90      * rewriting relevant links, and writes the parsed stream back to the client.
91      *
92      * @param request Servlet request.
93      * @param con the URLConnection with proxied host.
94      * @param contentType the contentType of the request.
95      *
96      * @exception IOException a servlet exception.
97      */

98
99     public void rewriteContent(ProxyRunData data,
100                                URLConnection JavaDoc con,
101                                int contentType,
102                                String JavaDoc url) throws IOException JavaDoc
103     {
104         // Read the HTML Content
105
String JavaDoc content = getHTMLContent(con, data, url);
106         if (WebPageHelper.CT_HTML == contentType)
107         {
108             // TODO: Deprecate this and use stream-based rewriting
109
HTMLRewriter rewriter = new HTMLRewriter (); // site.getID(), url);
110
// TODO: use Reader String result = rewriter.rewrite(content, proxyBase, targetBase);
111
//data.getResponse().getWriter().write(result);
112
}
113         else
114             data.getResponse().getWriter().write(content);
115
116     }
117
118     /**
119      * Retrieves the content from the URL Connection stream and writes it to servlet response
120      *
121      * @param con The URLConnection to read from.
122      *
123      * @exception IOException a servlet exception.
124      */

125     public void drainContent(URLConnection JavaDoc con,
126                              HttpServletResponse response) throws IOException JavaDoc
127     {
128         // TODO: rewrite this, and deprecate all String based rewriting
129
}
130
131     /**
132      * Gets the HTML content from the URL Connection stream and returns it as a Stream
133      *
134      * @param con The URLConnection to read from.
135      * @param data the request specific rundata.
136      * @return The HTML Content from the stream.
137      *
138      * @deprecate
139      * @exception IOException a servlet exception.
140      */

141     public String JavaDoc getContentAsString(URLConnection JavaDoc con,
142                                      ProxyRunData data,
143                                      String JavaDoc url)
144                     throws IOException JavaDoc
145     {
146         return ""; // todo: deprecate this
147
}
148
149
150
151     /**
152      * Gets the network element object associated with this session.
153      *
154      * @return A network element object for this session.
155      */

156     public Site getSite()
157     {
158         return site;
159     }
160
161     /**
162      * Gets the user name who owns this session.
163      *
164      * @return The string value of the user name.
165      */

166     public String JavaDoc getUserName()
167     {
168         return userName;
169     }
170
171     /**
172      * Logs out to the Network Element by sending the session id cookie
173      * to a pre-defined logout-URL in the Network Element.
174      * The logout-URL is defined in the proxy configuration.
175      * We communicate with a specific MNE logout resource form via HTTP GET.
176      *
177      * @param data the request specific rundata.
178      *
179      * @exception IOException a servlet exception.
180      */

181     public boolean logout(ProxyRunData data)
182                        throws IOException JavaDoc
183     {
184         return true; // LOGOUT
185
}
186
187     public void proxy(String JavaDoc site, ProxyRunData data)
188                     throws IOException JavaDoc
189     {
190     }
191
192 }
193
194
Popular Tags