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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.services.webpage;
1819// java.io20import java.io.IOException;
2122// javax.servlet23import javax.servlet.http.*;
2425// java.net26import java.net.URLConnection;
2728import org.apache.log4j.Logger;
2930import org.apache.jetspeed.util.rewriter.HTMLRewriter;
3132/***33 * <p>Represents a session with a site</p>34 * 35 * <p>This class extends AbstractSiteSession, implementing36 * the specific code login and logout to a site. The content rewriter37 * is also specialized here to handle the specific needs </p>3839 *40 * <p>Sessions are stored in the SessionMap per Jetspeed Session.41 * (The SessionMap is stored in the Servlet Session)</p>42 *43 */4445publicclassJetspeedSiteSessionextendsAbstractSiteSession46 {
4748Site site;
4950// the User Name owning this session51 String userName;
5253// the log file singleton instance54static Logger log = Logger.getLogger(JetspeedSiteSession.class);
5556/***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 URL61 * @param proxyBase the proxy server host URL base address.62 */63publicJetspeedSiteSession(Site site,
64 String proxyBase,
65 String userName)
66 {
67super(site.getURL(), proxyBase);
68this.site = site;
69this.userName = userName;
70 }
7172/***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 */81publicboolean logon(ProxyRunData data)
82 throws IOException
83 {
84returntrue;
85 }
868788/***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 */9899publicvoid rewriteContent(ProxyRunData data,
100 URLConnection con,
101int contentType,
102 String url) throws IOException
103 {
104// Read the HTML Content 105 String content = getHTMLContent(con, data, url);
106if (WebPageHelper.CT_HTML == contentType)
107 {
108// TODO: Deprecate this and use stream-based rewriting109HTMLRewriter rewriter = newHTMLRewriter (); // site.getID(), url);110// TODO: use Reader String result = rewriter.rewrite(content, proxyBase, targetBase);111//data.getResponse().getWriter().write(result);112 }
113else114 data.getResponse().getWriter().write(content);
115116 }
117118/***119 * Retrieves the content from the URL Connection stream and writes it to servlet response120 *121 * @param con The URLConnection to read from.122 *123 * @exception IOException a servlet exception.124 */125publicvoid drainContent(URLConnection con,
126 HttpServletResponse response) throws IOException
127 {
128// TODO: rewrite this, and deprecate all String based rewriting129 }
130131/***132 * Gets the HTML content from the URL Connection stream and returns it as a Stream133 *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 * @deprecate139 * @exception IOException a servlet exception.140 */141public String getContentAsString(URLConnection con,
142ProxyRunData data,
143 String url)
144 throws IOException
145 {
146return""; // todo: deprecate this147 }
148149150151/***152 * Gets the network element object associated with this session.153 * 154 * @return A network element object for this session.155 */156publicSite getSite()
157 {
158return site;
159 }
160161/***162 * Gets the user name who owns this session.163 * 164 * @return The string value of the user name.165 */166public String getUserName()
167 {
168return userName;
169 }
170171/***172 * Logs out to the Network Element by sending the session id cookie173 * 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 */181publicboolean logout(ProxyRunData data)
182 throws IOException
183 {
184returntrue; // LOGOUT185 }
186187publicvoid proxy(String site, ProxyRunData data)
188 throws IOException
189 {
190 }
191192 }
193