1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.webpage;
18
19
20 import java.io.IOException;
21
22
23 import javax.servlet.http.*;
24
25
26 import java.net.URLConnection;
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
51 String userName;
52
53
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 proxyBase,
65 String 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
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 con,
101 int contentType,
102 String url) throws IOException
103 {
104
105 String content = getHTMLContent(con, data, url);
106 if (WebPageHelper.CT_HTML == contentType)
107 {
108
109 HTMLRewriter rewriter = new HTMLRewriter ();
110
111
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 con,
126 HttpServletResponse response) throws IOException
127 {
128
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 getContentAsString(URLConnection con,
142 ProxyRunData data,
143 String url)
144 throws IOException
145 {
146 return "";
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 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
183 {
184 return true;
185 }
186
187 public void proxy(String site, ProxyRunData data)
188 throws IOException
189 {
190 }
191
192 }
193