01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.container.services.information;
07:
08: import java.net.MalformedURLException;
09: import java.net.URL;
10:
11: import javax.servlet.http.HttpServletRequest;
12:
13: import org.apache.pluto.om.window.PortletWindow;
14: import org.apache.pluto.services.information.ResourceURLProvider;
15: import org.jasig.portal.container.om.window.PortletWindowImpl;
16:
17: /**
18: * Implementation of Apache Pluto object model.
19: * @author Ken Weiner, kweiner@unicon.net
20: * @version $Revision: 36504 $
21: */
22: public class ResourceURLProviderImpl implements ResourceURLProvider {
23:
24: private URL url = null;
25: private String base = "";
26:
27: public ResourceURLProviderImpl(PortletWindow portletWindow) {
28: this .base = getBaseUrl(((PortletWindowImpl) portletWindow)
29: .getHttpServletRequest());
30: }
31:
32: // ResourceURLProvider methods
33:
34: public void setAbsoluteURL(String path) {
35: try {
36: url = new URL(path);
37: } catch (MalformedURLException e) {
38: IllegalArgumentException iae = new java.lang.IllegalArgumentException(
39: "absoluteUrl: " + path);
40: iae.initCause(e);
41: throw iae;
42: }
43: }
44:
45: public void setFullPath(String path) {
46: try {
47: url = new URL(base + path);
48: } catch (MalformedURLException e) {
49: IllegalArgumentException iae = new java.lang.IllegalArgumentException(
50: "fullPath: " + path);
51: iae.initCause(e);
52: throw iae;
53: }
54: }
55:
56: public String toString() {
57: return ((url == null) ? "" : url.toString());
58: }
59:
60: // Additional methods
61:
62: private String getBaseUrl(HttpServletRequest request) {
63: String scheme = request.getScheme();
64: String serverName = request.getServerName();
65: int serverPort = request.getServerPort();
66: return scheme + "://" + serverName + ":" + serverPort;
67: }
68: }
|