1 | /* |
2 | * Copyright 2003,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 | package org.apache.pluto.driver.core; |
17 | |
18 | import java.net.MalformedURLException; |
19 | import java.net.URL; |
20 | |
21 | import javax.servlet.http.HttpServletRequest; |
22 | |
23 | import org.apache.commons.logging.Log; |
24 | import org.apache.commons.logging.LogFactory; |
25 | import org.apache.pluto.PortletWindow; |
26 | import org.apache.pluto.driver.url.PortalURLFactory; |
27 | import org.apache.pluto.spi.ResourceURLProvider; |
28 | |
29 | public class ResourceURLProviderImpl implements ResourceURLProvider { |
30 | |
31 | private static final Log LOG = |
32 | LogFactory.getLog(ResourceURLProviderImpl.class); |
33 | |
34 | private String stringUrl = ""; |
35 | private String base = ""; |
36 | |
37 | public ResourceURLProviderImpl(HttpServletRequest req, |
38 | PortletWindow internalPortletWindow) { |
39 | this.base = |
40 | PortalURLFactory.getFactory().createPortalURL(req).getServerURI(); |
41 | if (LOG.isDebugEnabled()) { |
42 | LOG.debug("Resource URL Created with base: " + base); |
43 | } |
44 | } |
45 | |
46 | public void setAbsoluteURL(String path) { |
47 | stringUrl = path; |
48 | } |
49 | |
50 | public void setFullPath(String path) { |
51 | stringUrl = base + path; |
52 | } |
53 | |
54 | public String toString() { |
55 | URL url = null; |
56 | |
57 | if (!"".equals(stringUrl)) { |
58 | try { |
59 | url = new URL(stringUrl); |
60 | } catch (MalformedURLException e) { |
61 | throw new java.lang.IllegalArgumentException( |
62 | "A malformed URL has occured"); |
63 | } |
64 | } |
65 | |
66 | return ((url == null) ? "" : url.toString()); |
67 | |
68 | } |
69 | } |