portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r1816788 - /portals/jetspeed-2/portal/trunk/components/jetspeed-layout-portlets/src/main/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
Date Fri, 01 Dec 2017 01:22:28 GMT
Author: taylor
Date: Fri Dec  1 01:22:28 2017
New Revision: 1816788

URL: http://svn.apache.org/viewvc?rev=1816788&view=rev
Log:
JS2-1364: layout portlet configuration properties can now optionally be loaded via servlet
context resource stream

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-layout-portlets/src/main/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-layout-portlets/src/main/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-layout-portlets/src/main/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java?rev=1816788&r1=1816787&r2=1816788&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-layout-portlets/src/main/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-layout-portlets/src/main/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
Fri Dec  1 01:22:28 2017
@@ -16,20 +16,6 @@
  */
 package org.apache.jetspeed.portlets.layout;
 
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-import javax.portlet.PortletPreferences;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
@@ -39,6 +25,7 @@ import org.apache.jetspeed.PortalReserve
 import org.apache.jetspeed.administration.PortalConfiguration;
 import org.apache.jetspeed.administration.PortalConfigurationConstants;
 import org.apache.jetspeed.capabilities.CapabilityMap;
+import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.layout.JetspeedPowerTool;
 import org.apache.jetspeed.locator.LocatorDescriptor;
 import org.apache.jetspeed.locator.TemplateDescriptor;
@@ -48,11 +35,23 @@ import org.apache.jetspeed.om.page.Conte
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.velocity.JetspeedPowerToolFactory;
-import org.apache.jetspeed.container.PortletWindow;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
+
 /**
  */
 public class LayoutPortlet extends org.apache.portals.bridges.common.GenericServletPortlet
@@ -90,7 +89,10 @@ public class LayoutPortlet extends org.a
     public static final String TEMPLATE_EXTENSION_KEY = "template.extension";
     public static final String DEFAULT_TEMPLATE_TYPE = "velocity";
     public static final String TEMPLATE_TYPE_KEY = "template.type";
-    
+
+    // JS2-1361: load templates from webapp resource loader
+    protected boolean isLoadFromFileSystem = true;
+
     public void init( PortletConfig config ) throws PortletException
     {
         super.init(config);
@@ -116,6 +118,9 @@ public class LayoutPortlet extends org.a
         
         templateLocator = (TemplateLocator) getPortletContext().getAttribute("TemplateLocator");
         decorationLocator = (TemplateLocator) getPortletContext().getAttribute("DecorationLocator");
+
+        // JS2-1361: load templates from webapp resource loader
+        isLoadFromFileSystem = portalConfiguration.getBoolean(PortalConfigurationConstants.RESOURCE_LOADER_FILESYSTEM,
true);
     }
 
     public void doHelp( RenderRequest request, RenderResponse response ) throws PortletException,
IOException
@@ -542,7 +547,7 @@ public class LayoutPortlet extends org.a
         }
 
         // get decorator template
-        Configuration decoConf = new PropertiesConfiguration(propsTemp.getAbsolutePath());
+        Configuration decoConf = loadPropertiesConfiguration(propsTemp.getAbsolutePath(),
request);
         String ext = decoConf.getString("template.extension");
         String decoratorPath = decorator + "/" + DECORATOR_TYPE + ext;
         TemplateDescriptor template = null;
@@ -561,6 +566,17 @@ public class LayoutPortlet extends org.a
 
         return  template.getAppRelativePath();
     }
+
+    protected Configuration loadPropertiesConfiguration(String path, RenderRequest request)
 throws ConfigurationException {
+        if (isLoadFromFileSystem) {
+            return new PropertiesConfiguration(path);
+        }
+        RequestContext context = getRequestContext(request);
+        InputStream stream = context.getConfig().getServletContext().getResourceAsStream(path);
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(stream);
+        return configuration;
+    }
     
     /**
      * 
@@ -657,7 +673,7 @@ public class LayoutPortlet extends org.a
         // load Decoration.CONFIG_FILE_NAME (layout.properties)
         try
         {
-            props = new PropertiesConfiguration(templatePropertiesPath);
+            props = loadPropertiesConfiguration(templatePropertiesPath, request);
             if (log.isDebugEnabled())
                 log.debug("Successfully read in: <" + templatePropertiesPath + "> ");
         } 



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


Mime
View raw message