portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smi...@apache.org
Subject svn commit: r469307 [1/3] - in /portals/jetspeed-2/trunk: applications/gems/src/java/org/apache/portals/gems/dojo/ applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/permissions/ applications/j2-admin/src/webapp/WEB-INF/ applications/...
Date Mon, 30 Oct 2006 22:35:57 GMT
Author: smilek
Date: Mon Oct 30 14:35:55 2006
New Revision: 469307

URL: http://svn.apache.org/viewvc?view=rev&rev=469307
Log:
Improved management of html <head> content via HeaderResource and HeaderAggregatorImpl.

Recently added doHeader phase has facilitated a close examination of remaining header generation problems. This check-in is about addressing the following deficiencies:

1) Detection of the addition of duplicate header content is too coarse-grained. For example, entire script blocks are compared with each other as each is added. Exacerbating this problem is that each block is the complete definition for an html element to be added to the <head> (e.g. <script>, <link>, <style>).

2) In order to load a toolkit like dojo, each portlet which requires dojo needs to specify all header content needed to load the basic dojo in addition to any portlet specific header requirements. Making matters worse, this portlet must deal with the differences in dojo loading between /portal and /desktop. To date this problem has been mitigated by moving the common load code to a base class such as AbstractDojoVelocityPortlet.

3) Header content must be specified in java code and/or templates (e.g. velocity, jsp). The template solution further encumbers the effort to detect duplicate header content.

4) The ordering of header content is determined by whatever order the portlets get rendered.

We're writing an entry on this topic to add to the Documentation Guides.


Steve Milek

Added:
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceLib.java
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/headtag.xml
Modified:
    portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java
    portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java
    portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/permissions/SecurityPermissionsPortlet.java
    portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/portlet.xml
    portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/security/constraints/constraints-view-header.vm
    portals/jetspeed-2/trunk/components/header-resource/pom.xml
    portals/jetspeed-2/trunk/components/header-resource/project.xml
    portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceFactoryImpl.java
    portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/HeaderAggregatorImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletHeaderRequestImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletHeaderResponseImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopContextImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopImpl.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/PortalReservedParameters.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktop.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktopContext.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResource.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/headerresource/HeaderResourceFactory.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/portlet/PortletHeaderRequest.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/portlet/PortletHeaderResponse.java
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/aggregation.xml
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/desktop.xml
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/pipelines.xml
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/jetspeed_macros.vm
    portals/jetspeed-2/trunk/src/webapp/desktop-themes/blue/blue.jsp
    portals/jetspeed-2/trunk/src/webapp/desktop-themes/blue/blue.vm
    portals/jetspeed-2/trunk/src/webapp/desktop-themes/tigris/tigris.jsp
    portals/jetspeed-2/trunk/src/webapp/desktop-themes/tigris/tigris.vm

Modified: portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java (original)
+++ portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java Mon Oct 30 14:35:55 2006
@@ -35,20 +35,7 @@
  * @version $Id: $
  */
 public abstract class AbstractDojoVelocityPortlet extends GenericVelocityPortlet implements SupportsHeaderPhase 
-{
-    protected void includeDojoRequires(StringBuffer headerInfoText)
-    {
-    }
-    protected void includeDojoWidgetRequires(StringBuffer headerInfoText)
-    {
-        appendHeaderText(headerInfoText, "dojo.widget.Manager");
-    }
-    protected void includeDojoCustomWidgetRequires(StringBuffer headerInfoText)
-    {
-        headerInfoText.append("dojo.hostenv.setModulePrefix('jetspeed.ui.widget', '../desktop/widget');\r\n");
-        headerInfoText.append("dojo.hostenv.setModulePrefix('jetspeed.desktop', '../desktop/core');\r\n");
-    }
-    
+{    
     /*
      * Class specific logger.
      */
@@ -68,88 +55,19 @@
      * @param request render request
      * @param response render response
      */    
-    public void doHeader(PortletHeaderRequest request, PortletHeaderResponse response)
+    public void doHeader( PortletHeaderRequest request, PortletHeaderResponse response )
     throws PortletException
     {
-        String portalContextPath = request.getPortalContextPath();
-
         // use header resource component to ensure header logic is included only once
         HeaderResource headerResource = response.getHeaderResource();
-        StringBuffer headerInfoText = new StringBuffer();
-        Map headerInfoMap = null;
 
-        // add dojo if not already in use as desktop
-        if (!request.isDesktopEncoder()) 
-        {
-            // dojo configuration
-            headerInfoText.setLength(0);
-            headerInfoText.append("\r\n");
-            headerInfoText.append("var djConfig = {isDebug: true, debugAtAllCosts: true, baseScriptUri: '" + portalContextPath + "/javascript/dojo/'};\r\n");
-            headerInfoMap = new HashMap(8);
-            headerInfoMap.put("type", "text/javascript");
-            headerInfoMap.put("language", "JavaScript");
-            headerResource.addHeaderInfo("script", headerInfoMap, headerInfoText.toString());
+        headerResource.dojoEnable();
+        includeHeaderContent( headerResource );
+    }
     
-            // dojo script
-            headerInfoMap = new HashMap(8);
-            headerInfoMap.put("language", "JavaScript");
-            headerInfoMap.put("type", "text/javascript");
-            headerInfoMap.put("src", portalContextPath + "/javascript/dojo/dojo.js");
-            headerResource.addHeaderInfo("script", headerInfoMap, "");
-            
-            // dojo includes
-            headerInfoText.setLength(0);
-            headerInfoText.append("\r\n");
-            includeDojoRequires(headerInfoText);
-            includeDojoWidgetRequires(headerInfoText);
-            includeDojoCustomWidgetRequires(headerInfoText);
-            
-            headerInfoText.append("dojo.require('jetspeed.desktop.compatibility');\r\n");
-
-            headerInfoMap = new HashMap(8);
-            headerInfoMap.put("language", "JavaScript");
-            headerInfoMap.put("type", "text/javascript");
-            headerResource.addHeaderInfo("script", headerInfoMap, headerInfoText.toString());
-        }
-        
-        // close DOJO if not already in use as desktop
-        if (!request.isDesktopEncoder()) 
-        {
-            // complete DoJo includes
-            headerInfoText.setLength(0);
-            headerInfoText.append("\r\n");
-            headerInfoText.append("dojo.hostenv.writeIncludes();\r\n");
-            headerInfoMap = new HashMap(8);
-            headerInfoMap.put("language", "JavaScript");
-            headerInfoMap.put("type", "text/javascript");
-            headerResource.addHeaderInfo("script", headerInfoMap, headerInfoText.toString());
-        }
-
-        // add jetspeed widget package if not already in use as desktop
-        if (!request.isDesktopEncoder()) 
-        {
-            headerInfoText.setLength(0);
-            headerInfoText.append("\r\n");
-            headerInfoText.append("dojo.widget.manager.registerWidgetPackage('jetspeed.ui.widget');\r\n");
-            headerInfoMap = new HashMap(8);
-            headerInfoMap.put("language", "JavaScript");
-            headerInfoMap.put("type", "text/javascript");
-            headerResource.addHeaderInfo("script", headerInfoMap, headerInfoText.toString());
-        }
-        
-        if (!request.isDesktopEncoder()) 
-        {
-            headerInfoText.setLength(0);
-            headerInfoText.append("\r\n");
-            headerInfoText.append("html, body\r\n");
-            headerInfoText.append("{\r\n");
-            headerInfoText.append("   width: 100%;\r\n");
-            headerInfoText.append("   height: 100%;\r\n");
-            headerInfoText.append("   margin: 0 0 0 0;\r\n");
-            headerInfoText.append("}\r\n");
-            headerInfoMap = new HashMap(8);
-            headerResource.addHeaderInfo("style", headerInfoMap, headerInfoText.toString());
-        }
+    protected void includeHeaderContent( HeaderResource headerResource )
+    {
+        // do nothing - intended for derived classes
     }
     
     protected void appendHeaderText(StringBuffer headerInfoText, String header)

Modified: portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java (original)
+++ portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java Mon Oct 30 14:35:55 2006
@@ -55,7 +55,13 @@
 public class DojoSpringMVCPortlet extends DispatcherPortlet implements SupportsHeaderPhase
 {
 	protected static final String CRLF = "\r\n";
-
+    
+    protected static final String DOJO_REQUIRES_CORE_INIT_PARAM = "dojo.requires.core";
+    protected static final String DOJO_REQUIRES_MODULES_INIT_PARAM = "dojo.requires.modules";
+    
+    private String dojoRequiresCoreList = null;
+    private String dojoRequiresAddOnList = null;
+    
     /*
      * Class specific logger.
      */
@@ -71,52 +77,6 @@
         super();
     }
     
-    protected void includeDojoConfig(PortletHeaderRequest request, PortletHeaderResponse response, String portalContextPath, StringBuffer headerInfoText)
-		throws PortletException
-	{	
-    	headerInfoText.append( "var djConfig = { " );
-    	headerInfoText.append( "isDebug: true, debugAtAllCosts: false" );
-    	headerInfoText.append( ", baseScriptUri: '" );
-    	headerInfoText.append( portalContextPath ).append( "/javascript/dojo/" );
-    	headerInfoText.append( "'" );
-    	headerInfoText.append( " };" ).append( CRLF );
-	}
-    
-    protected String getDojoJSPath( String portalContextPath )
-    {
-    	return portalContextPath + "/javascript/dojo/dojo.js";
-    }
-	
-    protected void includeDojoRequires(PortletHeaderRequest request, PortletHeaderResponse response, StringBuffer headerInfoText)
-    	throws PortletException
-    {
-    	if ( this.headerPage != null )
-    	{
-    		include( request, response, this.headerPage, headerInfoText );
-    	}
-    }
-    protected void includeDojoWidgetRequires(PortletHeaderRequest request, PortletHeaderResponse response, StringBuffer headerInfoText)
-        throws PortletException
-    {
-
-    }
-    protected void includeDojoCustomWidgetRequires(PortletHeaderRequest request, PortletHeaderResponse response, StringBuffer headerInfoText)
-        throws PortletException
-    {
-        
-    }
-    
-    protected void includeDojoWriteIncludes(PortletHeaderRequest request, PortletHeaderResponse response, StringBuffer headerInfoText)
-        throws PortletException
-    {
-    	headerInfoText.append( "dojo.hostenv.writeIncludes();" ).append( CRLF );
-    }
-    protected void includeDojoRegisterWidgetPackage(PortletHeaderRequest request, PortletHeaderResponse response, StringBuffer headerInfoText)
-        throws PortletException
-    {
-        headerInfoText.append( "dojo.widget.manager.registerWidgetPackage('jetspeed.ui.widget');" ).append( CRLF );
-    }
-    
     protected boolean addJavascriptBlock(HeaderResource headerResource, StringBuffer javascriptText)
     {
     	return addJavascriptElement( headerResource, null, javascriptText );
@@ -159,6 +119,8 @@
         synchronized (this) 
         {
             this.headerPage = this.getInitParameter("HeaderPage");
+            this.dojoRequiresCoreList = this.getInitParameter( DOJO_REQUIRES_CORE_INIT_PARAM );
+            this.dojoRequiresAddOnList = this.getInitParameter( DOJO_REQUIRES_MODULES_INIT_PARAM );
         }
     }
 
@@ -180,81 +142,30 @@
     public void doHeader(PortletHeaderRequest request, PortletHeaderResponse response)    
     throws PortletException
     {
-        String portalContextPath = request.getPortalContextPath();
-
         // use header resource component to ensure header logic is included only once
         HeaderResource headerResource = response.getHeaderResource();
-        StringBuffer headerInfoText = new StringBuffer();
-        Map headerInfoMap = null;
-        boolean isJetspeedDesktop = request.isDesktopEncoder();
-        boolean addedDojoRequires = false;
         
+        headerResource.dojoEnable();
+        includeHeaderContent( headerResource );
         
-        // add dojo if not already in use as desktop
-        if (!isJetspeedDesktop) 
+        /*if ( this.headerPage != null )
         {
-            // dojo configuration
-            headerInfoText.setLength(0);
-            includeDojoConfig( request, response, portalContextPath, headerInfoText );
-            addJavascriptBlock( headerResource, headerInfoText );
-            
-            // dojo script
-            addJavascriptInclude( headerResource, getDojoJSPath( portalContextPath ) );
-            
-            // dojo includes
-            headerInfoText.setLength(0);
-            includeDojoRequires( request, response, headerInfoText );
-            if ( addJavascriptBlock( headerResource, headerInfoText ) )
-            {
-            	addedDojoRequires = true;
-            }
-            	
-            headerInfoText.setLength(0);
-            includeDojoWidgetRequires( request, response, headerInfoText );
-            if ( addJavascriptBlock( headerResource, headerInfoText ) )
-            {
-            	addedDojoRequires = true;
-            }
-            
-            headerInfoText.setLength(0);
-            includeDojoCustomWidgetRequires( request, response, headerInfoText );
-            if ( addJavascriptBlock( headerResource, headerInfoText ) )
-            {
-            	addedDojoRequires = true;
-            }
-        }
-        
-        // close DOJO if not already in use as desktop
-        if (!isJetspeedDesktop) 
+                include( request, response, this.headerPage, headerInfoText );
+        }*/
+    }
+    
+    protected void includeHeaderContent( HeaderResource headerResource )
+    {
+        // do nothing - intended for derived classes
+        if ( this.dojoRequiresCoreList != null )
         {
-            // complete dojo includes
-        	if ( addedDojoRequires )
-        	{
-        		headerInfoText.setLength(0);
-        		includeDojoWriteIncludes( request, response, headerInfoText );
-        		addJavascriptBlock( headerResource, headerInfoText );
-        	}
-        
-            headerInfoText.setLength(0);
-            includeDojoRegisterWidgetPackage( request, response, headerInfoText );
-            addJavascriptBlock( headerResource, headerInfoText );        
+            headerResource.dojoAddCoreLibraryRequires( this.dojoRequiresCoreList );
         }
-        
-        if (!isJetspeedDesktop)
+        if ( this.dojoRequiresAddOnList != null )
         {
-            headerInfoText.setLength(0);
-            headerInfoText.append("\r\n");
-            headerInfoText.append("html, body\r\n");
-            headerInfoText.append("{\r\n");
-            headerInfoText.append("   width: 100%;\r\n");
-            headerInfoText.append("   height: 100%;\r\n");
-            headerInfoText.append("   margin: 0 0 0 0;\r\n");
-            headerInfoText.append("}\r\n");
-            headerInfoMap = new HashMap(8);
-            headerResource.addHeaderInfo("style", headerInfoMap, headerInfoText.toString());
+            headerResource.dojoAddModuleLibraryRequires( this.dojoRequiresAddOnList );
         }
-    }
-    
+    }    
     
     public void include(PortletHeaderRequest request, PortletHeaderResponse response, String headerPagePath, StringBuffer headerText) throws PortletException
     {

Modified: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/permissions/SecurityPermissionsPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/permissions/SecurityPermissionsPortlet.java?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/permissions/SecurityPermissionsPortlet.java (original)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/permissions/SecurityPermissionsPortlet.java Mon Oct 30 14:35:55 2006
@@ -33,6 +33,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.headerresource.HeaderResource;
 import org.apache.jetspeed.security.PermissionManager;
 import org.apache.jetspeed.security.RoleManager;
 import org.apache.jetspeed.security.om.InternalPermission;
@@ -94,29 +95,21 @@
 
     */
 
-    protected void includeDojoRequires(StringBuffer headerInfoText)
+    protected void includeHeaderContent( HeaderResource headerResource )
     {
-        appendHeaderText(headerInfoText, "dojo.lang.*");
-        appendHeaderText(headerInfoText, "dojo.event.*");
-        appendHeaderText(headerInfoText, "dojo.io");
-    }
-    protected void includeDojoWidgetRequires(StringBuffer headerInfoText)
-    {
-        super.includeDojoWidgetRequires(headerInfoText);
-        appendHeaderText(headerInfoText, "dojo.widget.Manager");
-        appendHeaderText(headerInfoText, "dojo.widget.LayoutContainer");
-        appendHeaderText(headerInfoText, "dojo.widget.ContentPane");
-        appendHeaderText(headerInfoText, "dojo.widget.SplitContainer");
-        appendHeaderText(headerInfoText, "dojo.widget.TabContainer");
-        appendHeaderText(headerInfoText, "dojo.widget.Checkbox");
-        appendHeaderText(headerInfoText, "dojo.widget.Dialog");
-        appendHeaderText(headerInfoText, "dojo.widget.Button");
-        appendHeaderText(headerInfoText, "dojo.widget.Menu2");
-    }
-    protected void includeDojoCustomWidgetRequires(StringBuffer headerInfoText)
-    {
-        super.includeDojoCustomWidgetRequires(headerInfoText);
-        appendHeaderText(headerInfoText, "jetspeed.ui.widget.EditorTable");
+        headerResource.dojoAddCoreLibraryRequire( "dojo.lang.*" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.event.*" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.io.*" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.*" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.LayoutContainer" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.ContentPane" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.SplitContainer" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.TabContainer" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.Checkbox" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.Dialog" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.Button" );
+        headerResource.dojoAddCoreLibraryRequire( "dojo.widget.Menu2" );
+        headerResource.dojoAddModuleLibraryRequire( "jetspeed.ui.widget.EditorTable" );
     }
     
     public void doView(RenderRequest request, RenderResponse response)

Modified: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/portlet.xml?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/portlet.xml (original)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/portlet.xml Mon Oct 30 14:35:55 2006
@@ -1273,8 +1273,12 @@
 			<value>/WEB-INF/springmvc/context/portlet/constraints.xml</value>
 		</init-param>
 		<init-param>
-			<name>HeaderPage</name>
-			<value>/WEB-INF/view/security/constraints/constraints-view-header.vm</value>
+			<name>dojo.requires.core</name>
+			<value>dojo.lang.*;dojo.event.*;dojo.io.*;dojo.widget.*;dojo.widget.Tree;dojo.widget.Button;dojo.widget.Checkbox;dojo.widget.Dialog;dojo.widget.TabContainer;dojo.widget.ContentPane;dojo.widget.LayoutContainer</value>
+		</init-param>
+		<init-param>
+			<name>dojo.requires.modules</name>
+			<value>jetspeed.ui.widget.EditorTable;jetspeed.desktop.compatibility</value>
 		</init-param>
         <portlet-name>SecurityConstraintsPortlet</portlet-name>
     	<display-name>Security Constraints</display-name>        

Modified: portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/security/constraints/constraints-view-header.vm
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/security/constraints/constraints-view-header.vm?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/security/constraints/constraints-view-header.vm (original)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/security/constraints/constraints-view-header.vm Mon Oct 30 14:35:55 2006
@@ -1,3 +1,6 @@
+dojo.require('dojo.lang.*');
+dojo.require('dojo.event.*');
+dojo.require('dojo.io.*');
 dojo.require('dojo.widget.*');
 dojo.require('dojo.widget.Tree');
 dojo.require("dojo.widget.Button");

Modified: portals/jetspeed-2/trunk/components/header-resource/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/header-resource/pom.xml?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/components/header-resource/pom.xml (original)
+++ portals/jetspeed-2/trunk/components/header-resource/pom.xml Mon Oct 30 14:35:55 2006
@@ -40,6 +40,29 @@
         Jetspeed Header Resource Management
     </description>
 
+
+    <!-- Dependencies -->
+
+    <dependencies>
+
+        <!-- Build Dependencies -->
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+
+
+    </dependencies>
+
+
     <!-- Build Configuration -->
 
     <build>

Modified: portals/jetspeed-2/trunk/components/header-resource/project.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/header-resource/project.xml?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/components/header-resource/project.xml (original)
+++ portals/jetspeed-2/trunk/components/header-resource/project.xml Mon Oct 30 14:35:55 2006
@@ -43,7 +43,15 @@
     <dependency>
       <id>org.apache.portals.jetspeed-2:jetspeed-api</id>
       <version>${jetspeed.version}</version>
-    </dependency>  
+    </dependency>
+    <dependency>
+        <id>commons-lang</id>
+        <groupId>commons-lang</groupId>
+        <version>2.0</version>
+        <properties>
+            <war.bundle>true</war.bundle>
+        </properties>
+    </dependency>
   </dependencies>
 
 </project>

Modified: portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceFactoryImpl.java?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceFactoryImpl.java (original)
+++ portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceFactoryImpl.java Mon Oct 30 14:35:55 2006
@@ -15,9 +15,12 @@
  */
 package org.apache.jetspeed.headerresource.impl;
 
+import java.util.Map;
+
 import javax.portlet.PortletRequest;
 
 import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.container.url.BasePortalURL;
 import org.apache.jetspeed.headerresource.HeaderResource;
 import org.apache.jetspeed.headerresource.HeaderResourceFactory;
 import org.apache.jetspeed.request.RequestContext;
@@ -36,6 +39,10 @@
     public HeaderResource getHeaderResouce(RequestContext requestContext)
     {
         return new HeaderResourceImpl(requestContext);
+    }
+    public HeaderResource getHeaderResource(RequestContext requestContext, BasePortalURL baseUrlAccess, boolean isDesktop, Map headerConfiguration )
+    {
+        return new HeaderResourceImpl(requestContext, baseUrlAccess, isDesktop, headerConfiguration );
     }
 
     /* (non-Javadoc)

Modified: portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceImpl.java?view=diff&rev=469307&r1=469306&r2=469307
==============================================================================
--- portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceImpl.java (original)
+++ portals/jetspeed-2/trunk/components/header-resource/src/java/org/apache/jetspeed/headerresource/impl/HeaderResourceImpl.java Mon Oct 30 14:35:55 2006
@@ -19,12 +19,20 @@
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 import java.util.Set;
 
 import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.container.url.BasePortalURL;
 import org.apache.jetspeed.headerresource.HeaderResource;
+import org.apache.jetspeed.headerresource.HeaderResourceLib;
 import org.apache.jetspeed.request.RequestContext;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * Default implementation for HeaderResource
  * 
@@ -33,51 +41,1010 @@
  */
 public class HeaderResourceImpl implements HeaderResource
 {
+    protected final static Log log = LogFactory.getLog( HeaderResourceImpl.class );
+    
+    protected final static String EOL = "\r\n";   // html eol
+    protected final static String UNNAMED_CONTENT_HEADER_NAME = "org.apache.jetspeed.headerresource.unnamed";
+    
     private RequestContext requestContext;
+    
+    // base portal url to override default url server info from servlet
+    private BasePortalURL baseUrlAccess = null;
+    
+    private boolean isDesktop;
+    
+    private Map headerConfiguration;
+    
 
+    // ... mutable output tracking
+    //     - when depending on this feature, one HeaderResourceImpl instance must process all header inclusion
+    private HashMap namedResourcesAlreadyOutput;
+    
+    // ... as needed, these are obtained from request attributes
+    private Map headerDynamicConfiguration;
+    private Map headerNamedResources;
+    private Map headerNamedResourcesAddedFragments;
+    private Map headerResourceRegistry;
+    
+    // ... save generated portal urls to avoid duplicate effort
+    private String portalBaseUrl;
+    private String portalUrl;
+    
     /**
      * Default Constructor
      * 
      * @param context
      */
-    public HeaderResourceImpl(RequestContext context)
+    public HeaderResourceImpl( RequestContext context )
+    {
+        this.requestContext = context;
+    }
+    public HeaderResourceImpl( RequestContext context, BasePortalURL baseUrlAccess, boolean isDesktop, Map headerConfiguration )
+    {
+        this.requestContext = context;
+        this.baseUrlAccess = baseUrlAccess;
+        
+        this.isDesktop = isDesktop;
+        
+        this.headerConfiguration = headerConfiguration;
+    }
+        
+    /**
+     * Output all content (that has not already been output)
+     * 
+     * @return content string for inclusion in html &lt;head&gt;
+     */
+    public String getContent()
     {
-        requestContext = context;
+        StringBuffer header = new StringBuffer();
+        getNamedResourceContent( null, false, header );
+        getUnnamedContent( header );
+        return header.toString();
+    }
+    
+    /**
+     * Output all content (that has not already been output)
+     * 
+     * @return content string for inclusion in html &lt;head&gt;
+     */
+    public String toString()
+    {
+        return getContent();
     }
 
     /**
-     * Gets HeaderInfo set from the request.
+     * Output all unnamed (getHeaderInfoSet()) content (that has not already been output)
      * 
-     * @return
+     * @return content string for inclusion in html &lt;head&gt;
      */
-    private Set getHeaderInfoSet()
+    public String getUnnamedContent()
     {
-        Set headerInfoSet = (Set) requestContext.getAttribute(PortalReservedParameters.HEADER_RESOURCE_ATTRIBUTE);
-        if (headerInfoSet == null)
+        StringBuffer header = new StringBuffer();
+        getUnnamedContent( header );
+        return header.toString();
+    }
+
+    /**
+     * Output all getHeaderSections() content (that has not already been output)
+     * 
+     * @return content string for inclusion in html &lt;head&gt;
+     */
+    public String getNamedContent()
+    {
+        StringBuffer header = new StringBuffer();
+        getNamedResourceContent( null, false, header );
+        return header.toString();
+    }
+    
+    /**
+     * Output the one getHeaderSections() content entry with a key that matches headerName (if it has not already been output)
+     * 
+     * @return content string for inclusion in html &lt;head&gt;
+     */
+    public String getNamedContent( String headerName )
+    {
+        StringBuffer header = new StringBuffer();
+        getNamedResourceContent( headerName, false, header );
+        return header.toString();
+    }
+    
+    /**
+     * Output getHeaderSections() content entries with key prefixes that match headerNamePrefix (if it has not already been output)
+     * 
+     * @return content string for inclusion in html &lt;head&gt;
+     */
+    public String getNamedContentForPrefix( String headerNamePrefix )
+    {
+        if ( headerNamePrefix == null )
+            headerNamePrefix = "";
+        if ( ! headerNamePrefix.endsWith( "." ) )
+            headerNamePrefix = headerNamePrefix + ".";
+        StringBuffer header = new StringBuffer();
+        getNamedResourceContent( headerNamePrefix, true, header );
+        return header.toString();
+    }
+    
+    /*
+     * Output all getHeaderInfoSet() content (that has not already been output)
+     */
+    protected void getUnnamedContent( StringBuffer header )
+    {
+        HashMap namedResourcesInOutput = getNamedResourcesAlreadyOutput();
+        if ( namedResourcesInOutput == null )
         {
-            headerInfoSet = new LinkedHashSet();
-            requestContext.setAttribute(PortalReservedParameters.HEADER_RESOURCE_ATTRIBUTE, headerInfoSet);
+            namedResourcesInOutput = new HashMap();
+            setNamedResourcesAlreadyOutput( namedResourcesInOutput );
+        }
+        if ( ! namedResourcesInOutput.containsKey( UNNAMED_CONTENT_HEADER_NAME ) )
+        {
+            namedResourcesInOutput.put( UNNAMED_CONTENT_HEADER_NAME, Boolean.TRUE );
+            Set headerInfoSet = getHeaderInfoSet();
+            for ( Iterator ite = headerInfoSet.iterator(); ite.hasNext(); )
+            {
+                header.append( ((HeaderInfo) ite.next()).toString() );
+                header.append( EOL );
+            }
         }
-        return headerInfoSet;
     }
+    
+    /*
+     * Output getHeaderSections() content (that has not already been output) with regard to optional match arguments
+     */
+    protected void getNamedResourceContent( String headerNameMatch, boolean headerNameMatchPrefixOnly, StringBuffer header )
+    {
+        List headerOrderList = getHeaderSectionOrderList( false );
+        if ( headerOrderList != null && headerOrderList.size() > 0 )
+        {
+            HashMap namedResourcesInOutput = getNamedResourcesAlreadyOutput();
+            if ( namedResourcesInOutput == null )
+            {
+                namedResourcesInOutput = new HashMap();
+                setNamedResourcesAlreadyOutput( namedResourcesInOutput );
+            }
+            Map namedResources = getHeaderSections();
+            Map dynamicConfig = getHeaderDynamicConfiguration();
+            Map headerTypes = getHeaderSectionTypes( false );
+            Map headerRsrcRegistry = getHeaderResourceRegistry();
+            HashMap headerReqFlagResults = new HashMap();
+            boolean inScriptBlock = false;
+            boolean inStyleBlock = false;
+            Iterator headerOrderListIter = headerOrderList.iterator();
+            while ( headerOrderListIter.hasNext() )
+            {
+                String headerName = (String)headerOrderListIter.next();
+                if ( namedResourcesInOutput.containsKey( headerName ) )
+                {
+                    continue;
+                }
+                if ( headerNameMatch != null )
+                {
+                    if ( headerNameMatchPrefixOnly )
+                    {
+                        if ( ! headerName.startsWith( headerNameMatch ) )
+                        {
+                            continue;
+                        }
+                    }
+                    else
+                    {
+                        if ( ! headerName.equals( headerNameMatch ) )
+                        {
+                            continue;
+                        }
+                    }
+                }
+                boolean includeHeader = true;
+                Object[] headerTypePair = ( ( headerTypes != null ) ? (Object[])headerTypes.get( headerName ) : (Object[])null );
+                String headerReqFlag = ( ( headerTypePair != null ) ? (String)headerTypePair[1] : (String)null );
+                if ( headerReqFlag != null && headerReqFlag.length() > 0 )
+                {
+                    Boolean headerReqFlagResult = (Boolean)headerReqFlagResults.get( headerReqFlag );
+                    if ( headerReqFlagResult == null )
+                    {
+                        headerReqFlagResult = Boolean.FALSE;
+                        Object headerReqFlagValObj = dynamicConfig.get( headerReqFlag );
+                        if ( headerReqFlagValObj != null )
+                            headerReqFlagResult = new Boolean( headerReqFlagValObj.toString() );
+                        headerReqFlagResults.put( headerReqFlag, headerReqFlagResult );
+                    }
+                    includeHeader = headerReqFlagResult.booleanValue();
+                }
+                if ( includeHeader )
+                {
+                    namedResourcesInOutput.put( headerName, Boolean.TRUE );
+                    Integer headerTypeIdObj = ( ( headerTypePair != null ) ? (Integer)headerTypePair[0] : (Integer)null );
+                    int headerTypeId = ( ( headerTypeIdObj != null ) ? headerTypeIdObj.intValue() : HeaderResource.HEADER_TYPE_ID_SCRIPT_BLOCK );
 
+                    boolean requiresScriptBlock = false;
+                    boolean requiresStyleBlock = false;
+                    boolean preCloseBlock = false;
+                    boolean postCloseBlock = false;
+                    
+                    switch ( headerTypeId )
+                    {
+                        case HeaderResource.HEADER_TYPE_ID_SCRIPT_BLOCK:
+                        {
+                            requiresScriptBlock = true;
+                            break;
+                        }
+                        case HeaderResource.HEADER_TYPE_ID_SCRIPT_BLOCK_START:
+                        {
+                            preCloseBlock = true;
+                            requiresScriptBlock = true;
+                            break;
+                        }
+                        case HeaderResource.HEADER_TYPE_ID_SCRIPT_TAG:
+                        {
+                            preCloseBlock = true;
+                            break;
+                        }
+                        case HeaderResource.HEADER_TYPE_ID_SCRIPT_BLOCK_END:
+                        {
+                            postCloseBlock = true;
+                            requiresScriptBlock = true;
+                            break;
+                        }
+                        case HeaderResource.HEADER_TYPE_ID_STYLE_BLOCK:
+                        {
+                            requiresStyleBlock = true;
+                            break;
+                        }
+                        case HeaderResource.HEADER_TYPE_ID_LINK_TAG:
+                        {
+                            preCloseBlock = true;
+                            break;
+                        }
+                        case HeaderResource.HEADER_TYPE_ID_BASE_TAG:
+                        {
+                            preCloseBlock = true;
+                            break;
+                        }
+                        default:
+                        {
+                            log.error( "HeaderResource.getNamedResourceContent() cannot include header section with unknown type; header-section-name=" + headerName + " header-section-type-id=" + headerTypeId );
+                            includeHeader = false;
+                            break;
+                        }
+                    }
+                    if ( includeHeader )
+                    {
+                        if ( requiresScriptBlock && inStyleBlock )
+                        {
+                            preCloseBlock = true;
+                        }
+                        else if ( requiresStyleBlock && inScriptBlock )
+                        {
+                            preCloseBlock = true;
+                        }
+                        if ( preCloseBlock )
+                        {
+                            if ( inScriptBlock )
+                            {
+                                header.append( "</script>" ).append( EOL );
+                                inScriptBlock = false;
+                            }
+                            else if ( inStyleBlock )
+                            {
+                                header.append( "</style>" ).append( EOL );
+                                inStyleBlock = false;
+                            }
+                        }
+                        
+                        String headerText = (String)namedResources.get( headerName );
+                        if ( headerText == null )
+                        {
+                            headerText = generateHeaderSection( headerName );
+                            if ( headerText == null && headerRsrcRegistry != null )
+                            {                                
+                                headerText = (String)headerRsrcRegistry.get( headerName );
+                                log.debug( "header resource registry text for header section=" + headerName + " headerText=" + headerText );
+                            }
+                        }
+                        if ( headerText != null && headerText.length() > 0 )
+                        {
+                            if ( requiresScriptBlock && ! inScriptBlock )
+                            {
+                                header.append( "<script language=\"JavaScript\" type=\"text/javascript\">" ).append( EOL );
+                                inScriptBlock = true;
+                            }
+                            else if ( requiresStyleBlock && ! inStyleBlock )
+                            {
+                                header.append( "<style>" ).append( EOL );
+                                inStyleBlock = true;
+                            }
+                            header.append( headerText ).append( EOL );
+                        }
+                        if ( postCloseBlock )
+                        {
+                            if ( inScriptBlock )
+                            {
+                                header.append( "</script>" ).append( EOL );
+                                inScriptBlock = false;
+                            }
+                            else if ( inStyleBlock )
+                            {
+                                header.append( "</style>" ).append( EOL );
+                                inStyleBlock = false;
+                            }
+                        }
+                    }
+                }   // if ( includeHeader )
+            }   // while ( headerOrderListIter.hasNext() )
+            if ( inScriptBlock )
+            {
+                header.append( "</script>" ).append( EOL );
+                inScriptBlock = false;
+            }
+            else if ( inStyleBlock )
+            {
+                header.append( "</style>" ).append( EOL );
+                inStyleBlock = false;
+            }
+        }   // if ( headerOrderList != null && headerOrderList.size() > 0 )
+    }
+    
     /*
-     * (non-Javadoc)
+     * Intended as derived class hook into late, auto-generated header resources
+     */
+    protected String generateHeaderSection( String headerName )
+    {
+        if ( headerName != null )
+        {
+            if ( headerName.equals( HEADER_SECTION_BASE_TAG ) )
+            {
+                return jetspeedGenerateBasetag();
+            }
+            else if ( headerName.startsWith( HEADER_SECTION_NAME_PREFIX_DOJO ) )
+            {
+                if ( headerName.equals( HEADER_SECTION_DOJO_PREINIT ) )
+                {
+                    return dojoGeneratePreinit();
+                }
+                else if ( headerName.equals( HEADER_SECTION_DOJO_INIT ) )
+                {
+                    return dojoGenerateInit();
+                }
+                else if ( headerName.equals( HEADER_SECTION_DOJO_WRITEINCLUDES ) )
+                {
+                    return dojoGenerateWriteincludes();
+                }
+                else if ( headerName.equals( HEADER_SECTION_DOJO_STYLE_BODYEXPAND ) )
+                {
+                    return dojoGenerateBodyExpandStyle();
+                }
+                else if ( headerName.equals( HEADER_SECTION_DOJO_STYLE_BODYEXPAND_NOSCROLL ) )
+                {
+                    return dojoGenerateBodyExpandNoScrollStyle();
+                }
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Add text argument to the getHeaderSections() content entry with a key that matches addToHeaderName argument
      * 
-     * @see org.apache.jetspeed.headerresource.impl.HeaderResource#getString()
      */
-    public String toString()
+    public void addHeaderSectionFragment( String addToHeaderName, String text )
     {
-        Set headerInfoSet = getHeaderInfoSet();
-        StringBuffer header = new StringBuffer();
-        for (Iterator ite = headerInfoSet.iterator(); ite.hasNext();)
+        addHeaderSectionFragment( null, addToHeaderName, text, false );
+    }
+    
+    /**
+     * If no previous call using value of headerFragmentName argument has been added to any getHeaderSections() content entry,
+     * add text argument to the getHeaderSections() content entry with a key that matches addToHeaderName argument
+     * 
+     */
+    public void addHeaderSectionFragment( String headerFragmentName, String addToHeaderName, String text )
+    {
+        addHeaderSectionFragment( headerFragmentName, addToHeaderName, text, false );
+    }
+    
+    protected void addHeaderSectionFragment( String headerFragmentName, String addToHeaderName, String text, boolean alreadyCheckedFragName )
+    {
+        if ( addToHeaderName != null && text != null )
         {
-            header.append(((HeaderInfo) ite.next()).toString());
-            header.append("\n");
+            boolean addText = true;
+            if ( ! alreadyCheckedFragName && headerFragmentName != null && hasHeaderSectionFragment( headerFragmentName, true ) )
+            {
+                addText = false;
+            }
+            if ( addText )
+            {
+                Map headerRsrcRegistry = getHeaderResourceRegistry();
+                if ( headerRsrcRegistry != null )
+                {
+                    String overrideText = (String)headerRsrcRegistry.get( headerFragmentName );
+                    if ( overrideText != null )
+                    {
+                        text = overrideText;
+                    }
+                }
+                Map namedResources = getHeaderSections();
+                String nText = (String)namedResources.get( addToHeaderName );
+                if ( nText == null )
+                {
+                    nText = text + EOL;
+                    orderHeaderSection( addToHeaderName );
+                }
+                else
+                {
+                    nText = nText + text + EOL;
+                }
+                namedResources.put( addToHeaderName, nText );
+            }
         }
-        return header.toString();
+    }
+    
+    /**
+     * Indicate whether value of headerFragmentName argument has been used to add to any getHeaderSections() content entry
+     * 
+     * @return true if headerFragmentName argument has been used to add to any getHeaderSections() content entry
+     */
+    public boolean hasHeaderSectionFragment( String headerFragmentName )
+    {
+        return hasHeaderSectionFragment( headerFragmentName, false );
+    }
+    protected boolean hasHeaderSectionFragment( String headerFragmentName, boolean setToTrue )
+    {
+        if ( headerFragmentName != null )
+        {
+            Map namedResourcesAddedFragments = getHeaderSectionsAddedFragments();
+            if ( namedResourcesAddedFragments.containsKey( headerFragmentName ) )
+            {
+                return true;
+            }
+            else if ( setToTrue )
+            {
+                namedResourcesAddedFragments.put( headerFragmentName, Boolean.TRUE );
+            }
+        }
+        return false;
+    }
+    
+    protected void orderHeaderSection( String headerName )
+    {
+        if ( headerName != null )
+        {
+            Map headerNames = getHeaderSectionNames( true );
+            if ( ! headerNames.containsKey( headerName ) )
+            {
+                List headerOrderList = getHeaderSectionOrderList( true );
+                
+                headerOrderList.add( headerName );
+                headerNames.put( headerName, Boolean.TRUE );
+            }
+        }
+    }
+    
+    /**
+     * Indicate whether value of headerName is an included header section
+     * 
+     * @return true if headerName argument is an included header section
+     */
+    public boolean isHeaderSectionIncluded( String headerName )
+    {
+        if ( headerName != null )
+        {
+            Map headerNames = getHeaderSectionNames( false );
+            if ( headerNames != null && headerNames.get( headerName ) != null )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    /**
+     * Get the type of the getHeaderSections() content entry with a key that matches headerName argument
+     * 
+     * @return type of header section
+     */
+    public String getHeaderSectionType( String headerName )
+    {
+        if ( headerName != null )
+        {
+            Map headerTypes = getHeaderSectionTypes( false );
+            if ( headerTypes != null )
+            {
+                Object[] headerTypePair = (Object[])headerTypes.get( headerName );
+                if ( headerTypePair != null )
+                {
+                    Integer headerTypeId = (Integer)headerTypePair[0];
+                    return HeaderResourceLib.getHeaderType( headerTypeId );
+                }
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Set the type of the getHeaderSections() content entry with a key that matches headerName argument
+     * to the value of the headerType argument
+     */
+    public void setHeaderSectionType( String headerName, String headerType  )
+    {
+        if ( headerName != null )
+        {
+            int headerTypeId = HeaderResourceLib.getHeaderTypeId( headerType );
+            if ( headerTypeId < 0 )
+            {
+                log.error( "HeaderResourceImpl.setHeaderSectionType() ignoring specification of unknown header section type; header-section-name=" + headerName + " header-section-type=" + headerType );
+            }
+            else
+            {
+                Map headerTypes = getHeaderSectionTypes( true );
+                Object[] headerTypePair = (Object[])headerTypes.get( headerName );
+                if ( headerTypePair == null )
+                {
+                    if ( headerType != null )
+                    {
+                        headerTypePair = new Object[] { new Integer( headerTypeId ), null };
+                        headerTypes.put( headerName, headerTypePair );
+                    }
+                }
+                else
+                {
+                    headerTypePair[0] = new Integer( headerTypeId );
+                }
+            }
+        }
+    }
+    
+    /**
+     * Get the requiredflag of the getHeaderSections() content entry with a key that matches headerName argument
+     * 
+     * @return requiredflag for header section
+     */
+    public String getHeaderSectionRequiredFlag( String headerName )
+    {
+        if ( headerName != null )
+        {
+            Map headerTypes = getHeaderSectionTypes( false );
+            if ( headerTypes != null )
+            {
+                Object[] headerTypePair = (Object[])headerTypes.get( headerName );
+                if ( headerTypePair != null )
+                {
+                    return (String)headerTypePair[1];
+                }
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Set the requiredflag of the getHeaderSections() content entry with a key that matches headerName argument
+     * to the value of the headerReqFlag argument
+     */
+    public void setHeaderSectionRequiredFlag( String headerName, String headerReqFlag )
+    {
+        if ( headerName != null )
+        {
+            if ( headerReqFlag != null && headerReqFlag.length() == 0 )
+                headerReqFlag = null;
+            
+            Map headerTypes = getHeaderSectionTypes( true );
+            Object[] headerTypePair = (Object[])headerTypes.get( headerName );
+            if ( headerTypePair == null )
+            {
+                if ( headerReqFlag != null )
+                {
+                    headerTypePair = new Object[] { null, headerReqFlag };
+                    headerTypes.put( headerName, headerTypePair );
+                }
+            }
+            else
+            {
+                headerTypePair[1] = headerReqFlag;
+            }
+        }
+    }
+    
+    protected Map getHeaderSectionTypes( boolean create )
+    {
+        Map dynamicConfig = getHeaderDynamicConfiguration();
+        Map headerTypes = (Map)dynamicConfig.get( HEADER_CONFIG_TYPES );
+        if ( headerTypes == null && create )
+        {
+            headerTypes = new HashMap();
+            dynamicConfig.put( HEADER_CONFIG_TYPES, headerTypes );
+        }
+        return headerTypes;
+    }
+    protected Map getHeaderSectionNames( boolean create )
+    {
+        Map dynamicConfig = getHeaderDynamicConfiguration();
+        Map headerNames = (Map)dynamicConfig.get( HEADER_INTERNAL_INCLUDED_NAMES );
+        if ( headerNames == null && create )
+        {
+            headerNames = new HashMap();
+            dynamicConfig.put( HEADER_INTERNAL_INCLUDED_NAMES, headerNames );
+        }
+        return headerNames;
+    }
+    protected List getHeaderSectionOrderList( boolean create )
+    {
+        Map dynamicConfig = getHeaderDynamicConfiguration();
+        List headerOrderList = (List)dynamicConfig.get( HEADER_CONFIG_ORDER );
+        if ( headerOrderList == null )
+        {
+            headerOrderList = new ArrayList();
+            dynamicConfig.put( HEADER_CONFIG_ORDER, headerOrderList );
+        }
+        return headerOrderList;
+    }
+    
+    /**
+     * Access modifiable header configuration settings
+     * 
+     * @return Map containing modifiable header configuration settings 
+     */
+    public Map getHeaderDynamicConfiguration()
+    {
+        if ( this.headerDynamicConfiguration == null )
+        {
+            this.headerDynamicConfiguration = (Map)requestContext.getAttribute( PortalReservedParameters.HEADER_CONFIGURATION_ATTRIBUTE );
+            if ( this.headerDynamicConfiguration == null )
+            {
+                this.headerDynamicConfiguration = new HashMap();
+                requestContext.setAttribute( PortalReservedParameters.HEADER_CONFIGURATION_ATTRIBUTE, this.headerDynamicConfiguration );
+            }
+        }
+        return this.headerDynamicConfiguration;
+    }
+    protected Map getHeaderSections()
+    {
+        if ( this.headerNamedResources == null )
+        {
+            this.headerNamedResources = (Map)requestContext.getAttribute( PortalReservedParameters.HEADER_NAMED_RESOURCE_ATTRIBUTE );
+            if ( this.headerNamedResources == null )
+            {
+                this.headerNamedResources = new HashMap();
+                requestContext.setAttribute( PortalReservedParameters.HEADER_NAMED_RESOURCE_ATTRIBUTE, this.headerNamedResources );
+            }
+        }
+        return this.headerNamedResources;
+    }
+    protected Map getHeaderSectionsAddedFragments()
+    {
+        if ( this.headerNamedResourcesAddedFragments == null )
+        {
+            this.headerNamedResourcesAddedFragments = (Map)requestContext.getAttribute( PortalReservedParameters.HEADER_NAMED_RESOURCE_ADDED_FRAGMENTS_ATTRIBUTE );
+            if ( this.headerNamedResourcesAddedFragments == null )
+            {
+                this.headerNamedResourcesAddedFragments = new HashMap();
+                requestContext.setAttribute( PortalReservedParameters.HEADER_NAMED_RESOURCE_ADDED_FRAGMENTS_ATTRIBUTE, this.headerNamedResourcesAddedFragments );
+            }
+        }
+        return this.headerNamedResourcesAddedFragments;
+    }
+    protected Map getHeaderResourceRegistry()
+    {
+        if ( this.headerResourceRegistry == null )
+        {
+            this.headerResourceRegistry = (Map)requestContext.getAttribute( PortalReservedParameters.HEADER_NAMED_RESOURCE_REGISTRY_ATTRIBUTE );
+            if ( this.headerResourceRegistry == null )
+            {
+                this.headerResourceRegistry = new HashMap();
+            }
+        }
+        return this.headerResourceRegistry;
+    }
+    
+    protected RequestContext getRequestContext()
+    {
+        return this.requestContext;
+    }    
+    protected BasePortalURL getBaseUrlAccess()
+    {
+        return this.baseUrlAccess;
+    }
+    
+    /**
+     * Is request for /desktop rather than /portal
+     * 
+     * @return true if request is for /desktop, false if request is for /portal
+     */
+    public boolean isDesktop()
+    {
+        return this.isDesktop;
+    }
+    
+    /**
+     * Access complete header configuration settings
+     * 
+     * @return unmodifiable Map containing complete header configuration settings
+     */
+    public Map getHeaderConfiguration()
+    {
+        return this.headerConfiguration;
+    }
+    
+    protected HashMap getNamedResourcesAlreadyOutput()
+    {
+        return this.namedResourcesAlreadyOutput;
+    }
+    protected void setNamedResourcesAlreadyOutput( HashMap newOne )
+    {
+        this.namedResourcesAlreadyOutput = newOne;
+    }
+
+    
+    // get portal urls - a copy of each of these methods exists in JetspeedDesktopContextImpl.java
+    
+    /**
+     * Portal base url ( e.g. http://localhost:8080/jetspeed )
+     * 
+     * @return portal base url
+     */
+    public String getPortalBaseUrl()
+    {
+        if ( this.portalBaseUrl == null )
+        {
+            this.portalBaseUrl = HeaderResourceLib.getPortalBaseUrl( this.requestContext, this.baseUrlAccess );
+        }
+        return this.portalBaseUrl;
+    }
+    
+    /**
+     * Portal base url ( e.g. http://localhost:8080/jetspeed )
+     * 
+     * @return portal base url
+     */
+    public String getPortalBaseUrl( boolean encode )
+    {
+        String baseurl = getPortalBaseUrl();
+        if ( ! encode )
+        {
+            return baseurl;
+        }
+        else
+        {
+            return requestContext.getResponse().encodeURL( baseurl );
+        }
+    }
+        
+    /**
+     * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
+     * 
+     * @return portal base url with relativePath argument appended
+     */
+    public String getPortalResourceUrl( String relativePath )
+    {
+        return getPortalResourceUrl( relativePath, false );
+    }
+    
+    /**
+     * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
+     * 
+     * @return portal base url with relativePath argument appended
+     */
+    public String getPortalResourceUrl( String relativePath, boolean encode )
+    {
+        return HeaderResourceLib.getPortalResourceUrl( relativePath, getPortalBaseUrl(), encode, this.requestContext );
+    }
+    
+    /**
+     * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
+     * 
+     * @return portal base servlet url
+     */
+    public String getPortalUrl()
+    {
+        if ( this.portalUrl == null )
+        {
+            this.portalUrl = HeaderResourceLib.getPortalUrl( getPortalBaseUrl(), this.requestContext );
+        }
+        return this.portalUrl;
+    }
+    
+    /**
+     * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
+     * 
+     * @return portal base servlet url
+     */
+    public String getPortalUrl( boolean encode )
+    {
+        return getPortalUrl( null, encode );
+    }
+    
+    /**
+     * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
+     * 
+     * @return portal base servlet url with relativePath argument appended
+     */
+    public String getPortalUrl( String relativePath )
+    {
+        return getPortalUrl( relativePath, false );
+    }
+    
+    /**
+     * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
+     * 
+     * @return portal base servlet url with relativePath argument appended
+     */
+    public String getPortalUrl( String relativePath, boolean encode )
+    {
+        return HeaderResourceLib.getPortalResourceUrl( relativePath, getPortalUrl(), encode, this.requestContext );
+    }
+    
+
+    //  jetspeed - special convenience methods
+    
+    protected String jetspeedGenerateBasetag()
+    {
+        StringBuffer basetagOut = new StringBuffer();
+        // <script type="text/javascript" src='http://localhost:8080/jetspeed/javascript/dojo/dojo.js'></script>
+        // src='$jetspeedDesktop.getPortalResourceUrl("/javascript/dojo/dojo.js")'
+        basetagOut.append( "<base href=\"" ).append( getPortalResourceUrl( "/", false ) ).append( "\">" );
+        return basetagOut.toString();
+    }
+    
+    // dojo - special convenience methods
+    
+    /**
+     * If no previous call using value of dojoRequire argument has been added to any getHeaderSections() content entry,
+     * add text argument to the getHeaderSections() content entry for dojo core require statements
+     * 
+     */
+    public void dojoAddCoreLibraryRequire( String dojoRequire )
+    {
+        dojoAddRequire( dojoRequire, HEADER_SECTION_DOJO_REQUIRES_CORE );
+    }
+    
+    /**
+     * Split dojoRequires argument using ';' delimiter and for each resulting dojoRequire value, if no previous call
+     * using dojoRequire value has been added to any getHeaderSections() content entry,
+     * add text argument to the getHeaderSections() content entry for dojo core require statements
+     * 
+     */
+    public void dojoAddCoreLibraryRequires( String dojoRequires )
+    {
+        dojoAddRequires( dojoRequires, HEADER_SECTION_DOJO_REQUIRES_CORE );
+    }
+    
+    /**
+     * If no previous call using value of dojoRequire argument has been added to any getHeaderSections() content entry,
+     * add text argument to the getHeaderSections() content entry for dojo library module require statements
+     * 
+     */
+    public void dojoAddModuleLibraryRequire( String dojoRequire )
+    {
+        dojoAddRequire( dojoRequire, HEADER_SECTION_DOJO_REQUIRES_MODULES );
+    }
+    
+    /**
+     * Split dojoRequires argument using ';' delimiter and for each resulting dojoRequire value, if no previous call
+     * using dojoRequire value has been added to any getHeaderSections() content entry,
+     * add text argument to the getHeaderSections() content entry for dojo library module require statements
+     * 
+     */
+    public void dojoAddModuleLibraryRequires( String dojoRequires )
+    {
+        dojoAddRequires( dojoRequires, HEADER_SECTION_DOJO_REQUIRES_MODULES );
+    }
+    
+    /**
+     * Assure that header section name for dojo body expand style is included
+     * 
+     */
+    public void dojoAddBodyExpandStyle( boolean omitWindowScrollbars )
+    {
+        if ( isHeaderSectionIncluded( HEADER_SECTION_DOJO_STYLE_BODYEXPAND ) || isHeaderSectionIncluded( HEADER_SECTION_DOJO_STYLE_BODYEXPAND_NOSCROLL ) )
+        {
+            // already included - first inclusion wins
+        }
+        else
+        {
+            if ( ! omitWindowScrollbars )
+            {
+                orderHeaderSection( HEADER_SECTION_DOJO_STYLE_BODYEXPAND );
+            }
+            else
+            {
+                orderHeaderSection( HEADER_SECTION_DOJO_STYLE_BODYEXPAND_NOSCROLL );
+            }
+        }
+    }
+    
+    /**
+     * Enable dojo by setting appropriate modifiable header configuration setting
+     * 
+     */
+    public void dojoEnable()
+    {
+        getHeaderDynamicConfiguration().put( "dojo.enable", "true" );
+    }
+    
+    protected void dojoDisable()
+    {
+        getHeaderDynamicConfiguration().put( "dojo.enable", "false" );
+    }
+    protected String dojoGetPath()
+    {
+        return (String)getHeaderDynamicConfiguration().get( "dojo.path" );
+    }
+    protected void dojoAddRequire( String dojoRequire, String addToHeaderName )
+    {
+        if ( dojoRequire != null && addToHeaderName != null && ! hasHeaderSectionFragment( dojoRequire, true ) )
+        {
+            String requireStatement = "    dojo.require(\"" + dojoRequire + "\");";
+            addHeaderSectionFragment( dojoRequire, addToHeaderName, requireStatement, true );
+        }
+    }
+    protected void dojoAddRequires( String dojoRequires, String addToHeaderName )
+    {
+        String[] reqStatements = StringUtils.split( dojoRequires, ';' );
+        int reqStatementsLen = ( reqStatements == null ) ? 0 : reqStatements.length;
+        if ( reqStatementsLen > 0 )
+        {   
+            for ( int i = 0 ; i < reqStatementsLen ; i++ )
+            {
+                dojoAddRequire( reqStatements[i], addToHeaderName );
+            }
+        }
+    }
+    protected String dojoGeneratePreinit()
+    {
+        StringBuffer preinitOut = new StringBuffer();
+        //preinitOut.append( "    " ).append( "function de_jsessionid_url(url){var tEnds = url.indexOf(';jsessionid=');if (tEnds > 0) url = url.substring(0, tEnds);return url;}" ).append( EOL );
+        // presence of ;jsessionid in dojo baseScriptUri is bad news
+        preinitOut.append( "    " ).append( "djConfig.baseScriptUri = \"" ).append( getPortalResourceUrl( dojoGetPath(), false ) ).append( "\";" );
+        return preinitOut.toString();
+    }
+    protected String dojoGenerateInit()
+    {
+        StringBuffer initOut = new StringBuffer();
+        // <script type="text/javascript" src='http://localhost:8080/jetspeed/javascript/dojo/dojo.js'></script>
+        // src='$jetspeedDesktop.getPortalResourceUrl("/javascript/dojo/dojo.js")'
+        initOut.append( "<script type=\"text/javascript\" src=\"" ).append( getPortalResourceUrl( dojoGetPath(), false ) ).append( "dojo.js" ).append( "\"></script>" );
+        return initOut.toString();
+    }
+    protected String dojoGenerateWriteincludes()
+    {
+        return "    dojo.hostenv.writeIncludes();";
+    }
+    protected String dojoGenerateBodyExpandStyle()
+    {   // if not defined as getHeaderResourceRegistry(), generate default text
+        Map headerRsrcRegistry = getHeaderResourceRegistry();
+        String headerText = (String)headerRsrcRegistry.get( HEADER_SECTION_DOJO_STYLE_BODYEXPAND );
+        if ( headerText == null )
+        {
+            headerText = "html, body { width: 100%; height: 100%; padding: 0 0 0 0; margin: 0 0 0 0; }";
+        }
+        return headerText;
+    }
+    protected String dojoGenerateBodyExpandNoScrollStyle()
+    {   // if not defined as getHeaderResourceRegistry(), generate default text
+        Map headerRsrcRegistry = getHeaderResourceRegistry();
+        String headerText = (String)headerRsrcRegistry.get( HEADER_SECTION_DOJO_STYLE_BODYEXPAND_NOSCROLL );
+        if ( headerText == null )
+        {
+            headerText = "html, body { width: 100%; height: 100%; overflow: hidden; padding: 0 0 0 0; margin: 0 0 0 0; }";
+        }
+        return headerText;
     }
 
+    
+    // older content implementation - using HeaderInfo set 
+    
+    /**
+     * Gets HeaderInfo set from the request.
+     * 
+     * @return HeaderInfo set containing content for inclusion in html &lt;head&gt;
+     */
+    private Set getHeaderInfoSet()
+    {
+        Set headerInfoSet = (Set) requestContext.getAttribute(PortalReservedParameters.HEADER_RESOURCE_ATTRIBUTE);
+        if (headerInfoSet == null)
+        {
+            headerInfoSet = new LinkedHashSet();
+            requestContext.setAttribute(PortalReservedParameters.HEADER_RESOURCE_ATTRIBUTE, headerInfoSet);
+        }
+        return headerInfoSet;
+    }
+    
     /*
      * (non-Javadoc)
      * 
@@ -155,7 +1122,31 @@
         attrs.put("type", "text/css");
         addHeaderInfo("link", attrs, null);
     }
-
+    
+    private void dumpNameValue( Map m  )
+    {
+        if ( m == null )
+        {
+            log.info( "   <null>" );
+            return;
+        }
+        if ( m.size() == 0 )
+        {
+            log.info( "   <empty>" );
+            return;
+        }
+        Iterator entryIter = m.entrySet().iterator();
+        while ( entryIter.hasNext() )
+        {
+            Map.Entry e = (Map.Entry)entryIter.next();
+            Object eKey = e.getKey();
+            Object eVal = e.getValue();
+            String eKeyDesc = ( eKey instanceof String ) ? (String)eKey : (( eKey == null ) ? "null" : eKey.getClass().getSimpleName() );
+            String eValDesc = ( eVal instanceof String ) ? (String)eVal : (( eVal == null ) ? "null" : eVal.getClass().getSimpleName() );
+            log.info( "   key=" + eKeyDesc + " value=" + eValDesc);
+        }
+    }
+    
     /**
      * This class represents tag information for HeaderResouce component
      * 



---------------------------------------------------------------------
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