portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r760987 - in /portals/jetspeed-2/portal/trunk: applications/jetspeed/src/main/webapp/WEB-INF/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/ c...
Date Wed, 01 Apr 2009 17:58:17 GMT
Author: woonsan
Date: Wed Apr  1 17:58:16 2009
New Revision: 760987

URL: http://svn.apache.org/viewvc?rev=760987&view=rev
Log:
JS2-949: 
Moves head element aggregation just before rendering root fragment or just before writing
the maximized window content
because the velocity macro invoked during rendering the topmost fragment should be able to
access all the head elements.
Also, adds a utility method in JPT to allow easily convert element to html string.

Modified:
    portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetspeed_macros.vm
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/AsyncPageAggregatorImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/BaseAggregatorImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PageAggregatorImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/DOMUtils.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/layout/JetspeedPowerTool.java

Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetspeed_macros.vm
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetspeed_macros.vm?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetspeed_macros.vm
(original)
+++ portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetspeed_macros.vm
Wed Apr  1 17:58:16 2009
@@ -76,8 +76,13 @@
 
 #* Adds additional style sheets and java script from portlets *#
 #macro (includeHeaderResource)
- #acquireHeaderResource()
+#acquireHeaderResource()
 $resourceHeader.getContent()
+#set($headElements = $request.getAttribute("org.apache.jetspeed.markup.head.elements"))
+#foreach($headElement in $headElements)
+#set($headElemHtml = $jetspeed.getElementHtmlString($headElement))
+$headElemHtml
+#end
 #end
 
 #* Adds additional style sheets and java script from portlets - desktop version *#
@@ -153,9 +158,9 @@
 #set($_pages = $site.getMenu("pages").elements)
 <div id="pages-menu" class="menu">#foreach($_page in $_pages)
 #if($_page.isSelected($site))
-	#set($_cssClass = "link page-link selected")
+    #set($_cssClass = "link page-link selected")
 #else
-	#set($_cssClass = "link page-link")
+    #set($_cssClass = "link page-link")
 #end
 <a href="portal${_page.url}" class="$!{_cssClass}" title="${_page.getTitle($preferedLocale)}">$_page.getTitle($preferedLocale)</a><span
class="separator"></span>#end  
 </div>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/AsyncPageAggregatorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/AsyncPageAggregatorImpl.java?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/AsyncPageAggregatorImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/AsyncPageAggregatorImpl.java
Wed Apr  1 17:58:16 2009
@@ -18,9 +18,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -29,14 +27,12 @@
 import org.apache.jetspeed.aggregator.PortletAccessDeniedException;
 import org.apache.jetspeed.aggregator.PortletRenderer;
 import org.apache.jetspeed.aggregator.RenderingJob;
-import org.apache.jetspeed.aggregator.impl.BaseAggregatorImpl;
+import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.container.state.NavigationalState;
 import org.apache.jetspeed.exception.JetspeedException;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.container.PortletWindow;
-import org.w3c.dom.Element;
 
 /**
  * Asynchronous Page Aggregator builds the content required to render a 
@@ -89,9 +85,6 @@
             aggregateAndRender(root, context, page, true, null, null, null);
         }
         
-        // accumulate all the head contributions from the rendered contents
-        aggregateHeadElements(root, context, null);
-        
         // write all rendered content
         context.getResponse().getWriter().write(root.getRenderedContent());
         
@@ -202,39 +195,12 @@
         if (log.isDebugEnabled())
         {
             log.debug("Rendering portlet fragment: [[name, " + f.getName() + "], [id, " +
f.getId() + "]]");
-        }        
-        
-        renderer.renderNow(f, context);
-    }
-    
-    protected void aggregateHeadElements( ContentFragment f, RequestContext context, Map<String,
Element> headElements )
-    {
-        boolean isRoot = (headElements == null);
-        
-        if (headElements == null)
-        {
-            headElements = new HashMap<String, Element>();
         }
         
-        List<ContentFragment> contentFragments = (List<ContentFragment>) f.getContentFragments();
-        
-        if (contentFragments != null && !contentFragments.isEmpty())
-        {
-            for (ContentFragment child : contentFragments)
-            {
-                if (!"hidden".equals(f.getState()))
-                {
-                    aggregateHeadElements(child, context, headElements);
-                }
-            }
-        }
+        // accumulate all the head contributions from the rendered contents
+        aggregateHeadElements(f, context, null);   
         
-        headElements.putAll(f.getPortletContent().getHeadElements());
-
-        if (isRoot)
-        {
-            context.getRequest().setAttribute(PortalReservedParameters.MARKUP_HEAD_ELEMENTS_ATTRIBUTE,
headElements);
-        }
+        renderer.renderNow(f, context);
     }
-
+    
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/BaseAggregatorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/BaseAggregatorImpl.java?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/BaseAggregatorImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/BaseAggregatorImpl.java
Wed Apr  1 17:58:16 2009
@@ -16,7 +16,9 @@
  */
 package org.apache.jetspeed.aggregator.impl;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -27,6 +29,7 @@
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.request.RequestContext;
+import org.w3c.dom.Element;
 
 /**
  * Share common code for all aggregators 
@@ -89,8 +92,8 @@
         try
         {
             renderer.renderNow(window.getFragment(), context);
-            renderer.renderNow(layoutContentFragment, context);              
-            
+            aggregateHeadElements(window.getFragment(), context, null);
+            renderer.renderNow(layoutContentFragment, context);
         }
         catch (Exception e)
         {
@@ -98,4 +101,52 @@
             window.getFragment().overrideRenderedContent("Sorry, but we were unable access
the requested portlet. Send the following message to your portal admin:  "+  e.getMessage());
         }
     }
+
+    /**
+     * <p>
+     * aggregateHeadElements
+     * </p>
+     * Aggregates all contributed head elements from each content fragment into a map
+     * and store it into a specific request attribute.
+     * 
+     * @param f
+     * @param context
+     * @param headElements
+     */
+    protected void aggregateHeadElements( ContentFragment f, RequestContext context, Map<String,
Element> headElements )
+    {
+        boolean isRoot = (headElements == null);
+        
+        if (headElements == null)
+        {
+            headElements = new HashMap<String, Element>();
+        }
+        
+        List<ContentFragment> contentFragments = (List<ContentFragment>) f.getContentFragments();
+        
+        if (contentFragments != null && !contentFragments.isEmpty())
+        {
+            for (ContentFragment child : contentFragments)
+            {
+                if (!"hidden".equals(f.getState()))
+                {
+                    aggregateHeadElements(child, context, headElements);
+                }
+            }
+        }
+
+        PortletContent portletContent = f.getPortletContent();
+
+        // root fragment's portlet content can be null
+        if (portletContent != null)
+        {
+            headElements.putAll(portletContent.getHeadElements());
+        }
+
+        if (isRoot)
+        {
+            context.getRequest().setAttribute(PortalReservedParameters.MARKUP_HEAD_ELEMENTS_ATTRIBUTE,
headElements);
+        }
+    }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PageAggregatorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PageAggregatorImpl.java?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PageAggregatorImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PageAggregatorImpl.java
Wed Apr  1 17:58:16 2009
@@ -17,9 +17,7 @@
 package org.apache.jetspeed.aggregator.impl;
 
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.aggregator.PageAggregator;
@@ -30,7 +28,6 @@
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.request.RequestContext;
-import org.w3c.dom.Element;
 
 /**
  * ContentPageAggregator builds the content required to render a page of portlets.
@@ -77,12 +74,9 @@
         }
         else
         {
-            aggregateAndRender(root, context, page);
+            aggregateAndRender(root, context, page, true);
         }
         
-        // accumulate all the head contributions from the rendered contents
-        aggregateHeadElements(root, context, null);
-        
         // write all rendered content
         context.getResponse().getWriter().write(root.getRenderedContent());
         
@@ -95,7 +89,7 @@
         releaseBuffers(root, context);        
     }
 
-    protected void aggregateAndRender( ContentFragment f, RequestContext context, ContentPage
page )
+    protected void aggregateAndRender( ContentFragment f, RequestContext context, ContentPage
page, boolean isRoot )
     {
         List<ContentFragment> contentFragments = (List<ContentFragment>) f.getContentFragments();
         
@@ -105,41 +99,18 @@
             {
                 if (!"hidden".equals(f.getState()))
                 {
-                    aggregateAndRender(child, context, page);
+                    aggregateAndRender(child, context, page, false);
                 }
             }
         }
         
-        renderer.renderNow(f, context);
-    }
-    
-    protected void aggregateHeadElements( ContentFragment f, RequestContext context, Map<String,
Element> headElements )
-    {
-        boolean isRoot = (headElements == null);
-        
-        if (headElements == null)
-        {
-            headElements = new HashMap<String, Element>();
-        }
-        
-        List<ContentFragment> contentFragments = (List<ContentFragment>) f.getContentFragments();
-        
-        if (contentFragments != null && !contentFragments.isEmpty())
-        {
-            for (ContentFragment child : contentFragments)
-            {
-                if (!"hidden".equals(f.getState()))
-                {
-                    aggregateHeadElements(child, context, headElements);
-                }
-            }
-        }
-        
-        headElements.putAll(f.getPortletContent().getHeadElements());
-
         if (isRoot)
         {
-            context.getRequest().setAttribute(PortalReservedParameters.MARKUP_HEAD_ELEMENTS_ATTRIBUTE,
headElements);
+            // accumulate all the head contributions from the rendered contents
+            aggregateHeadElements(f, context, null);   
         }
+        
+        renderer.renderNow(f, context);
     }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/DOMUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/DOMUtils.java?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/DOMUtils.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/DOMUtils.java
Wed Apr  1 17:58:16 2009
@@ -152,9 +152,7 @@
         try
         {
             xmlWriter = new XMLWriter(writer, outputFormat);
-            xmlWriter.write(element);
-            xmlWriter.flush();
-            xmlWriter.close();
+            writeElement(xmlWriter, element);
         }
         catch (IOException e)
         {
@@ -171,4 +169,11 @@
         return stringified;
     }
     
+    public static void writeElement(XMLWriter xmlWriter, org.dom4j.Element element) throws
IOException
+    {
+        xmlWriter.write(element);
+        xmlWriter.flush();
+        xmlWriter.close();
+    }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
Wed Apr  1 17:58:16 2009
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.io.Writer;
 import java.security.Principal;
 import java.util.HashMap;
@@ -55,8 +56,13 @@
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.ArgUtil;
+import org.apache.jetspeed.util.DOMUtils;
 import org.apache.jetspeed.util.Path;
 import org.apache.velocity.context.Context;
+import org.dom4j.io.HTMLWriter;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
+import org.w3c.dom.Element;
 
 /**
  * <p>
@@ -94,6 +100,8 @@
     protected static final String COLUMNS_ATTR = "columns";
 
     protected static final String COLUMN_SIZES = "columnSizes";
+    
+    protected static final OutputFormat DEFAULT_ELEMENT_HTML_OUTPUT_FORMAT = OutputFormat.createPrettyPrint();
 
     protected RenderRequest renderRequest;
 
@@ -837,4 +845,38 @@
             return "";
         }
     }
+
+    public String getElementHtmlString(Element element)
+    {
+        String html = null;
+        StringWriter writer = new StringWriter(80);
+        XMLWriter xmlWriter = null;
+
+        if (element instanceof org.dom4j.Element)
+        {
+            try
+            {
+                xmlWriter = new HTMLWriter(writer, DEFAULT_ELEMENT_HTML_OUTPUT_FORMAT);
+                DOMUtils.writeElement(xmlWriter, (org.dom4j.Element) element);
+                html = writer.toString();
+            }
+            catch (IOException e)
+            {
+            }
+            finally
+            {
+                if (xmlWriter != null)
+                {
+                    try { xmlWriter.close(); } catch (IOException ce) { }
+                }
+            }
+        }
+        else
+        {
+            html = DOMUtils.stringifyElement(element);
+        }
+        
+        return html;
+    }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/layout/JetspeedPowerTool.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/layout/JetspeedPowerTool.java?rev=760987&r1=760986&r2=760987&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/layout/JetspeedPowerTool.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/layout/JetspeedPowerTool.java
Wed Apr  1 17:58:16 2009
@@ -23,11 +23,12 @@
 import javax.portlet.WindowState;
 import javax.security.auth.Subject;
 
+import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.locator.TemplateDescriptor;
 import org.apache.jetspeed.locator.TemplateLocatorException;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.container.PortletWindow;
+import org.w3c.dom.Element;
 
 /**
  * JetspeedPowerTool
@@ -237,4 +238,7 @@
     String getPageBasePath();    
     
     String renderPortletWindow(String windowId, String portletId);
+    
+    String getElementHtmlString(Element element);
+    
 }
\ No newline at end of file



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