01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/api-impl/src/java/org/theospi/portfolio/presentation/export/StreamedPage.java $
03: * $Id:StreamedPage.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.presentation.export;
21:
22: import java.io.IOException;
23: import java.io.InputStream;
24: import java.net.URL;
25: import java.net.URLConnection;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29:
30: import websphinx.Access;
31: import websphinx.Link;
32: import websphinx.Page;
33:
34: public class StreamedPage extends Page {
35: protected final transient Log logger = LogFactory
36: .getLog(getClass());
37:
38: private Link link;
39:
40: public StreamedPage(Link link) {
41: super ("Streamed");
42: this .link = link;
43: }
44:
45: /**
46: * Get the Link that points to this page.
47: *
48: * @return the Link object that was used to download this page.
49: */
50: public Link getOrigin() {
51: return link;
52: }
53:
54: public InputStream getStream() throws IOException {
55: URLConnection conn = Access.getAccess().openConnection(link);
56:
57: // fetch and store final redirected URL and response headers
58: InputStream returned = conn.getInputStream();
59:
60: this .setContentEncoding(conn.getContentEncoding());
61: this .setContentType(conn.getContentType());
62: this .setExpiration(conn.getExpiration());
63: this .setLastModified(conn.getLastModified());
64:
65: return returned;
66: }
67:
68: /**
69: * Get the URL.
70: *
71: * @return the URL of the link that was used to download this page
72: */
73: public URL getURL() {
74: return getOrigin().getURL();
75: }
76:
77: }
|