You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2006/01/11 02:04:11 UTC

svn commit: r367856 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed: container/url/impl/ velocity/

Author: taylor
Date: Tue Jan 10 17:04:09 2006
New Revision: 367856

URL: http://svn.apache.org/viewcvs?rev=367856&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-466

 This issue adds two new features:

1. Production Configuration via an external configuration file
    This configuration file allows administrators to change production configuration properties
    outside of the portal without moving the entire assembly directory out of the portal
    see jetspeed-production.properties and jetspeed-production.xml

2. Hard-code base URL

   Allows the Base URL to be hard-coded by a system administrator
  Base URLs contain the isSecure flag, server name, server port, and server scheme.
  This abstraction was necessary for wiring the entire portal's base URL via another
   mechanism than retrieving from the servlet request.

Both of these features are turned OFF by default.
To enable them, see portal-url-generation.xml 

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/BasePortalURLImpl.java
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/AbstractPortalURL.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/PathInfoEncodingPortalURL.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/QueryStringEncodingPortalURL.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/AbstractPortalURL.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/AbstractPortalURL.java?rev=367856&r1=367855&r2=367856&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/AbstractPortalURL.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/AbstractPortalURL.java Tue Jan 10 17:04:09 2006
@@ -25,6 +25,7 @@
 import org.apache.jetspeed.PortalContext;
 import org.apache.jetspeed.container.ContainerConstants;
 import org.apache.jetspeed.container.state.NavigationalState;
+import org.apache.jetspeed.container.url.BasePortalURL;
 import org.apache.jetspeed.container.url.PortalURL;
 import org.apache.jetspeed.util.ArgUtil;
 import org.apache.pluto.om.window.PortletWindow;
@@ -44,18 +45,22 @@
     private static String navStateParameter;
     
     private NavigationalState navState;
-    private String serverName;    
-    private String serverScheme;
+    private BasePortalURL base = null;
+    
     private String contextPath;
     private String basePath;
     private String path;
     private String encodedNavState;
     private String secureBaseURL;
     private String nonSecureBaseURL;
-    private int serverPort;    
-    private boolean secure;
     private String characterEncoding = "UTF-8";
     
+
+    public AbstractPortalURL(NavigationalState navState, PortalContext portalContext, BasePortalURL base)
+    {
+        this(navState, portalContext);        
+        this.base = base;
+    }
     
     public AbstractPortalURL(NavigationalState navState, PortalContext portalContext)
     {
@@ -89,22 +94,30 @@
     
     protected void decodeBaseURL(HttpServletRequest request)
     {
-        this.serverName = request.getServerName();
-        this.serverPort = request.getServerPort();
-        this.serverScheme = request.getScheme();
-        this.secure = request.isSecure();
+        if (base == null)
+        {
+            base = new BasePortalURLImpl();
+            base.setServerScheme(request.getScheme());
+            base.setServerName(request.getServerName());
+            base.setServerPort(request.getServerPort());
+            base.setSecure(request.isSecure());            
+        }        
         StringBuffer buffer;
 	
         buffer = new StringBuffer(HTTPS);
-	buffer.append("://").append(this.serverName);
-	if(this.serverPort != 443 && this.serverPort != 80)
-	    buffer.append(":").append(this.serverPort);
-	this.secureBaseURL = buffer.toString();
+        buffer.append("://").append(base.getServerName());
+        if (base.getServerPort() != 443 && base.getServerPort() != 80)
+	    {
+            buffer.append(":").append(base.getServerPort());
+        }
+        this.secureBaseURL = buffer.toString();
 	    
         buffer = new StringBuffer(HTTP);
-        buffer.append("://").append(this.serverName);
-        if(this.serverPort != 443 && this.serverPort != 80)
-             buffer.append(":").append(this.serverPort);
+        buffer.append("://").append(base.getServerName());
+        if (base.getServerPort() != 443 && base.getServerPort() != 80)
+        {
+             buffer.append(":").append(base.getServerPort());
+        }
         this.nonSecureBaseURL = buffer.toString();
     }
     
@@ -149,7 +162,7 @@
 
     public String getBaseURL()
     {
-        return getBaseURL(secure);
+        return getBaseURL(base.isSecure());
     }
     
     public String getBaseURL(boolean secure)
@@ -188,7 +201,7 @@
     
     public boolean isSecure()
     {
-        return secure;
+        return base.isSecure();
     }
         
     public NavigationalState getNavigationalState()

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/BasePortalURLImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/BasePortalURLImpl.java?rev=367856&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/BasePortalURLImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/BasePortalURLImpl.java Tue Jan 10 17:04:09 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container.url.impl;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.jetspeed.container.url.BasePortalURL;
+
+/**
+ * <p>
+ * BasePortalURL defines the interface for manipulating Base URLs in a portal.
+ * Base URLs contain the isSecure flag, server name, server port, and server scheme.
+ * This abstraction was necessary for wiring the entire portal's base URL via another
+ * mechanism than retrieving from the servlet request.
+ * </p>
+ * 
+ * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
+ * @version $Id: $
+ *
+ */
+public class BasePortalURLImpl implements BasePortalURL
+{
+    private String serverName;    
+    private String serverScheme;
+    private int serverPort;    
+    private boolean secure;
+    
+    public BasePortalURLImpl()
+    {        
+    }
+    
+    public BasePortalURLImpl(Configuration config)
+    {
+        this.serverName = config.getString("portal.url.name");
+        this.serverScheme = config.getString("portal.url.scheme");
+        this.serverPort = config.getInt("portal.url.port");
+        this.secure = config.getBoolean("portal.url.secure");
+    }
+    
+    public BasePortalURLImpl(String serverScheme, String serverName, int serverPort, boolean secure)
+    {
+        this.serverName = serverName;
+        this.serverScheme = serverScheme;
+        this.serverPort = serverPort;
+        this.secure = secure;
+    }
+    
+    public boolean isSecure()
+    {
+        return secure;
+    }
+    
+    public void setSecure(boolean secure)
+    {
+        this.secure = secure;
+    }
+    
+    public String getServerName()
+    {
+        return serverName;
+    }
+    
+    public void setServerName(String serverName)
+    {
+        this.serverName = serverName;
+    }
+    
+    public int getServerPort()
+    {
+        return serverPort;
+    }
+    
+    public void setServerPort(int serverPort)
+    {
+        this.serverPort = serverPort;
+    }
+    
+    public String getServerScheme()
+    {
+        return serverScheme;
+    }
+    
+    public void setServerScheme(String serverScheme)
+    {
+        this.serverScheme = serverScheme;
+    }
+
+}

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/PathInfoEncodingPortalURL.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/PathInfoEncodingPortalURL.java?rev=367856&r1=367855&r2=367856&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/PathInfoEncodingPortalURL.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/PathInfoEncodingPortalURL.java Tue Jan 10 17:04:09 2006
@@ -22,6 +22,7 @@
 
 import org.apache.jetspeed.PortalContext;
 import org.apache.jetspeed.container.state.NavigationalState;
+import org.apache.jetspeed.container.url.BasePortalURL;
 
 /**
  * PathInfoEncodingPortalURL encodes the NavigationalState as PathInfo element
@@ -31,6 +32,10 @@
  */
 public class PathInfoEncodingPortalURL extends AbstractPortalURL
 {
+    public PathInfoEncodingPortalURL(NavigationalState navState, PortalContext portalContext, BasePortalURL base)
+    {
+        super(navState, portalContext, base);
+    }
 
     public PathInfoEncodingPortalURL(NavigationalState navState, PortalContext portalContext)
     {

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/QueryStringEncodingPortalURL.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/QueryStringEncodingPortalURL.java?rev=367856&r1=367855&r2=367856&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/QueryStringEncodingPortalURL.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/url/impl/QueryStringEncodingPortalURL.java Tue Jan 10 17:04:09 2006
@@ -19,6 +19,7 @@
 
 import org.apache.jetspeed.PortalContext;
 import org.apache.jetspeed.container.state.NavigationalState;
+import org.apache.jetspeed.container.url.BasePortalURL;
 
 /**
  * QueryStringEncodingPortalURL encodes the NavigationalState as query parameter
@@ -28,6 +29,11 @@
  */
 public class QueryStringEncodingPortalURL extends AbstractPortalURL
 {
+    public QueryStringEncodingPortalURL(NavigationalState navState, PortalContext portalContext, BasePortalURL base)
+    {
+        super(navState, portalContext, base);
+    }
+
     public QueryStringEncodingPortalURL(NavigationalState navState, PortalContext portalContext)
     {
         super(navState, portalContext);

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java?rev=367856&r1=367855&r2=367856&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java Tue Jan 10 17:04:09 2006
@@ -47,6 +47,7 @@
 import org.apache.jetspeed.components.portletentity.PortletEntityNotGeneratedException;
 import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
 import org.apache.jetspeed.container.state.NavigationalState;
+import org.apache.jetspeed.container.url.BasePortalURL;
 import org.apache.jetspeed.container.url.PortalURL;
 import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
@@ -136,6 +137,8 @@
     protected Context velocityContext;
 
     private DynamicTitleService titleService;
+    
+    private BasePortalURL baseUrlAccess;
 
     public JetspeedPowerToolImpl(RequestContext requestContext, DynamicTitleService titleService) throws Exception
     {
@@ -144,10 +147,12 @@
         this.titleService = titleService;
         windowAccess = (PortletWindowAccessor) getComponent(PortletWindowAccessor.class.getName());
         entityAccess = (PortletEntityAccessComponent) getComponent(PortletEntityAccessComponent.class.getName());
+        baseUrlAccess = (BasePortalURL) getComponent("BasePortalURL");
         renderRequest = (RenderRequest) request.getAttribute(RENDER_REQUEST_ATTR);
         renderResponse = (RenderResponse) request.getAttribute(RENDER_RESPONSE_ATTR);
         portletConfig = (PortletConfig) request.getAttribute(PORTLET_CONFIG_ATTR);
 
+
         templateLocator = (TemplateLocator) getComponent("TemplateLocator");
         decorationLocator = (TemplateLocator) getComponent("DecorationLocator");
         // By using null, we create a re-useable locator
@@ -925,9 +930,18 @@
         {
             HttpServletRequest request = getRequestContext().getRequest();
             StringBuffer path = new StringBuffer();
-            return renderResponse.encodeURL(path.append(request.getScheme()).append("://").append(
-                    request.getServerName()).append(":").append(request.getServerPort()).append(
-                    request.getContextPath()).append(request.getServletPath()).append(relativePath).toString());
+            if (this.baseUrlAccess == null)
+            {
+                return renderResponse.encodeURL(path.append(request.getScheme()).append("://").append(
+                request.getServerName()).append(":").append(request.getServerPort()).append(
+                request.getContextPath()).append(request.getServletPath()).append(relativePath).toString());                
+            }
+            else
+            {
+                return renderResponse.encodeURL(path.append(baseUrlAccess.getServerScheme()).append("://").append(
+                        baseUrlAccess.getServerName()).append(":").append(baseUrlAccess.getServerPort()).append(
+                        request.getContextPath()).append(request.getServletPath()).append(relativePath).toString());                                
+            }
         }
         else
         {



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org