View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.container.url.impl;
18  
19  import org.apache.commons.configuration.Configuration;
20  import org.apache.commons.configuration.ConfigurationException;
21  import org.apache.commons.configuration.PropertiesConfiguration;
22  import org.apache.jetspeed.container.url.BasePortalURL;
23  
24  /***
25   * <p>
26   * BasePortalURL defines the interface for manipulating Base URLs in a portal.
27   * Base URLs contain the isSecure flag, server name, server port, and server scheme.
28   * This abstraction was necessary for wiring the entire portal's base URL via another
29   * mechanism than retrieving from the servlet request.
30   * </p>
31   * 
32   * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
33   * @version $Id: $
34   *
35   */
36  public class BasePortalURLImpl implements BasePortalURL
37  {
38      private String serverName;    
39      private String serverScheme;
40      private int serverPort;    
41      private boolean secure;
42      
43      public BasePortalURLImpl()
44      {        
45      }
46      
47      /***
48       * This constructor takes a string that represents the name of an
49       * environment variable.  The environment variable will be the full
50       * path of a properties file to be loaded.  Information from the
51       * properties file will populate this object
52       */
53      public BasePortalURLImpl(String environmentPath) throws ConfigurationException 
54      {
55          String propertyFilePath = null;
56          if (environmentPath != null) 
57          {
58              propertyFilePath = System.getProperty(environmentPath);
59          }
60          
61          PropertiesConfiguration config = null;
62          
63          // Load the file if the path is provided
64          if (propertyFilePath != null) 
65          {
66              config = new PropertiesConfiguration(propertyFilePath);
67          }
68  
69          if (config != null) 
70          {
71              this.serverName = config.getString("portal.url.name");
72              this.serverScheme = config.getString("portal.url.scheme");
73              this.serverPort = config.getInt("portal.url.port");
74              this.secure = config.getBoolean("portal.url.secure");            
75          }
76      }
77      
78      
79      public BasePortalURLImpl(Configuration config)
80      {
81          this.serverName = config.getString("portal.url.name");
82          this.serverScheme = config.getString("portal.url.scheme");
83          this.serverPort = config.getInt("portal.url.port");
84          this.secure = config.getBoolean("portal.url.secure");
85      }
86      
87      public BasePortalURLImpl(String serverScheme, String serverName, int serverPort, boolean secure)
88      {
89          this.serverName = serverName;
90          this.serverScheme = serverScheme;
91          this.serverPort = serverPort;
92          this.secure = secure;
93      }
94      
95      public boolean isSecure()
96      {
97          return secure;
98      }
99      
100     public void setSecure(boolean secure)
101     {
102         this.secure = secure;
103     }
104     
105     public String getServerName()
106     {
107         return serverName;
108     }
109     
110     public void setServerName(String serverName)
111     {
112         this.serverName = serverName;
113     }
114     
115     public int getServerPort()
116     {
117         return serverPort;
118     }
119     
120     public void setServerPort(int serverPort)
121     {
122         this.serverPort = serverPort;
123     }
124     
125     public String getServerScheme()
126     {
127         return serverScheme;
128     }
129     
130     public void setServerScheme(String serverScheme)
131     {
132         this.serverScheme = serverScheme;
133     }
134 
135 }