001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.container.url.impl;
018:
019: import org.apache.commons.configuration.Configuration;
020: import org.apache.commons.configuration.ConfigurationException;
021: import org.apache.commons.configuration.PropertiesConfiguration;
022: import org.apache.jetspeed.container.url.BasePortalURL;
023:
024: /**
025: * <p>
026: * BasePortalURL defines the interface for manipulating Base URLs in a portal.
027: * Base URLs contain the isSecure flag, server name, server port, and server scheme.
028: * This abstraction was necessary for wiring the entire portal's base URL via another
029: * mechanism than retrieving from the servlet request.
030: * </p>
031: *
032: * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
033: * @version $Id: $
034: *
035: */
036: public class BasePortalURLImpl implements BasePortalURL {
037: private String serverName;
038: private String serverScheme;
039: private int serverPort;
040: private boolean secure;
041:
042: public BasePortalURLImpl() {
043: }
044:
045: /**
046: * This constructor takes a string that represents the name of an
047: * environment variable. The environment variable will be the full
048: * path of a properties file to be loaded. Information from the
049: * properties file will populate this object
050: */
051: public BasePortalURLImpl(String environmentPath)
052: throws ConfigurationException {
053: String propertyFilePath = null;
054: if (environmentPath != null) {
055: propertyFilePath = System.getProperty(environmentPath);
056: }
057:
058: PropertiesConfiguration config = null;
059:
060: // Load the file if the path is provided
061: if (propertyFilePath != null) {
062: config = new PropertiesConfiguration(propertyFilePath);
063: }
064:
065: if (config != null) {
066: this .serverName = config.getString("portal.url.name");
067: this .serverScheme = config.getString("portal.url.scheme");
068: this .serverPort = config.getInt("portal.url.port");
069: this .secure = config.getBoolean("portal.url.secure");
070: }
071: }
072:
073: public BasePortalURLImpl(Configuration config) {
074: this .serverName = config.getString("portal.url.name");
075: this .serverScheme = config.getString("portal.url.scheme");
076: this .serverPort = config.getInt("portal.url.port");
077: this .secure = config.getBoolean("portal.url.secure");
078: }
079:
080: public BasePortalURLImpl(String serverScheme, String serverName,
081: int serverPort, boolean secure) {
082: this .serverName = serverName;
083: this .serverScheme = serverScheme;
084: this .serverPort = serverPort;
085: this .secure = secure;
086: }
087:
088: public boolean isSecure() {
089: return secure;
090: }
091:
092: public void setSecure(boolean secure) {
093: this .secure = secure;
094: }
095:
096: public String getServerName() {
097: return serverName;
098: }
099:
100: public void setServerName(String serverName) {
101: this .serverName = serverName;
102: }
103:
104: public int getServerPort() {
105: return serverPort;
106: }
107:
108: public void setServerPort(int serverPort) {
109: this .serverPort = serverPort;
110: }
111:
112: public String getServerScheme() {
113: return serverScheme;
114: }
115:
116: public void setServerScheme(String serverScheme) {
117: this.serverScheme = serverScheme;
118: }
119:
120: }
|