View Javadoc

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  
17  package org.apache.pluto.portalImpl.core;
18  
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  
22  import org.apache.pluto.om.window.PortletWindow;
23  import org.apache.pluto.services.information.ResourceURLProvider;
24  
25  public class ResourceURLProviderImpl implements ResourceURLProvider
26  {
27  
28      private PortletWindow portletWindow = null;
29      private String stringUrl = "";
30      private String base = "";
31  
32      public ResourceURLProviderImpl(DynamicInformationProviderImpl provider,
33                                     PortletWindow portletWindow)
34      {
35          this.portletWindow = portletWindow;
36          this.base = PortalURL.getBaseURLexcludeContext();
37      }
38  
39      // ResourceURLProvider implementation.
40  
41      public void setAbsoluteURL(String path)
42      {
43          stringUrl = path;
44      }
45      
46      public void setFullPath(String path)
47      {
48          stringUrl = base + path;
49      }
50      
51      public String toString()
52      {
53          URL url = null;
54  
55          if (!"".equals(stringUrl))
56          {
57              try 
58              {
59                  url = new URL(stringUrl);
60              } 
61              catch (MalformedURLException e) 
62              {
63                  throw new java.lang.IllegalArgumentException("A malformed URL has occured");                  
64              }
65          }
66  
67          return ((url==null)?"":url.toString());
68          
69      }
70  
71  }