portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r881250 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-cm/src/test/java/org/apache/jetspeed/cache/ components/jetspeed-portal/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/ components/jetspeed-por...
Date Tue, 17 Nov 2009 12:25:35 GMT
Author: woonsan
Date: Tue Nov 17 12:25:34 2009
New Revision: 881250

URL: http://svn.apache.org/viewvc?rev=881250&view=rev
Log:
JS2-1083: Removing dom4j dependency in head contribution handling.

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java   (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java   (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java   (with props)
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java   (with props)
Removed:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/dom/
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/test/java/org/apache/jetspeed/cache/TestContentCache.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/pom.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletAggregatorImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletRenderResponseContextImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletResponseContextImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/request/JetspeedRequestContext.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/ui/Jetui.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/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/state/MockRequestContext.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestDOMUtils.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/window/MockPortletWindow.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/aggregator/PortletContent.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/PortletWindow.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/layout/JetspeedPowerTool.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/mockobjects/request/MockRequestContext.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/request/RequestContext.java
    portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/HeadElementsUtils.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/test/java/org/apache/jetspeed/cache/TestContentCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/test/java/org/apache/jetspeed/cache/TestContentCache.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/test/java/org/apache/jetspeed/cache/TestContentCache.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/test/java/org/apache/jetspeed/cache/TestContentCache.java Tue Nov 17 12:25:34 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.jetspeed.cache;
 
-import java.io.NotSerializableException;
 import java.io.PrintWriter;
 import java.security.Principal;
 import java.util.LinkedList;
@@ -31,8 +30,8 @@
 import org.apache.jetspeed.cache.impl.EhPortletContentCacheImpl;
 import org.apache.jetspeed.cache.impl.JetspeedCacheKeyGenerator;
 import org.apache.jetspeed.mockobjects.request.MockRequestContext;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
 import com.mockrunner.mock.web.MockHttpServletResponse;
@@ -393,14 +392,14 @@
         }
 
 
-        public void addHeadElement(Element element, String keyHint) throws NotSerializableException
+        public void addHeadElement(HeadElement element, String keyHint)
         {
             // TODO Auto-generated method stub
             
         }
 
 
-        public List<KeyValue<String, Element>> getHeadElements()
+        public List<KeyValue<String, HeadElement>> getHeadElements()
         {
             // TODO Auto-generated method stub
             return null;

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/pom.xml?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/pom.xml Tue Nov 17 12:25:34 2009
@@ -136,10 +136,6 @@
       <artifactId>jaxen</artifactId>
     </dependency>
     <dependency>
-      <groupId>dom4j</groupId>
-      <artifactId>dom4j</artifactId>
-    </dependency>
-    <dependency>
       <groupId>asm</groupId>
       <artifactId>asm</artifactId>
     </dependency>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletAggregatorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletAggregatorImpl.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletAggregatorImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletAggregatorImpl.java Tue Nov 17 12:25:34 2009
@@ -28,10 +28,10 @@
 import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.exception.JetspeedException;
 import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.util.DOMUtils;
+import org.apache.jetspeed.util.HeadElementUtils;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 /**
  * PortletAggregator builds the content required to render a single portlet.
@@ -114,7 +114,7 @@
     
     protected void writeHeadElements(RequestContext context, PortletWindow window) throws IOException
     {
-        List<KeyValue<String, Element>> headElements = window.getHeadElements();
+        List<KeyValue<String, HeadElement>> headElements = window.getHeadElements();
 
         if (!headElements.isEmpty())
         {
@@ -122,9 +122,10 @@
             
             out.println("<JS_PORTLET_HEAD_ELEMENTS>");
             
-            for (KeyValue<String, Element> kvPair : headElements)
+            for (KeyValue<String, HeadElement> kvPair : headElements)
             {
-                out.println(DOMUtils.stringifyElementToHtml(kvPair.getValue()));
+                HeadElement headElement = kvPair.getValue();
+                out.println(HeadElementUtils.toHtmlString(headElement));
             }
             
             out.print("</JS_PORTLET_HEAD_ELEMENTS>");

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java Tue Nov 17 12:25:34 2009
@@ -17,19 +17,17 @@
 package org.apache.jetspeed.aggregator.impl;
 
 import java.io.CharArrayWriter;
-import java.io.NotSerializableException;
 import java.io.PrintWriter;
-import java.io.Serializable;
 import java.util.Collections;
 import java.util.List;
 
 import org.apache.commons.collections.list.TreeList;
 import org.apache.jetspeed.aggregator.PortletContent;
 import org.apache.jetspeed.cache.ContentCacheKey;
-import org.apache.jetspeed.util.DOMUtils;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.util.DefaultKeyValue;
+import org.apache.jetspeed.util.HeadElementUtils;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 
 public class PortletContentImpl implements PortletContent
@@ -46,7 +44,7 @@
      * The list container for all contributed head elements from this portlet content.
      * Because the insertion order might be important for web development, this container should be list instead of map.
      */
-    private List<KeyValue<String, Element>> headElements;
+    private List<KeyValue<String, HeadElement>> headElements;
     
     PortletContentImpl()
     {
@@ -174,7 +172,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    public void addHeadElement(Element element, String keyHint) throws NotSerializableException
+    public void addHeadElement(HeadElement headElement, String keyHint)
     {
         if (this.headElements == null)
         {
@@ -184,11 +182,11 @@
             this.headElements = new TreeList();
         }
 
-        if (element == null)
+        if (headElement == null)
         {
             if (keyHint != null)
             {
-                KeyValue<String, Element> kvPair = new DefaultKeyValue(keyHint, null, true);
+                KeyValue<String, HeadElement> kvPair = new DefaultKeyValue(keyHint, null, true);
                 this.headElements.remove(kvPair);
             }
             else
@@ -201,28 +199,12 @@
             return;
         }
         
-        if (!(element instanceof Serializable))
-        {
-            throw new NotSerializableException("The element is not serializable.");
-        }
-        
         if (keyHint == null)
         {
-            // If element is dom4j's element, then we can use dom4j's serializer.
-            // Meanwhile, the element can be a serializable one which is not from dom4j.
-            // In the case, serialize the element to a string as a keyHint.
-            
-            if (element instanceof org.dom4j.Element) 
-            {
-                keyHint = DOMUtils.stringifyElement((org.dom4j.Element) element);
-            }
-            else
-            {
-                keyHint = DOMUtils.stringifyElement(element);
-            }
+            keyHint = HeadElementUtils.toHtmlString(headElement);
         }
 
-        KeyValue<String, Element> kvPair = new DefaultKeyValue(keyHint, element, true);
+        KeyValue<String, HeadElement> kvPair = new DefaultKeyValue(keyHint, headElement, true);
         
         if (!this.headElements.contains(kvPair))
         {
@@ -230,9 +212,9 @@
         }
     }
 
-    public List<KeyValue<String, Element>> getHeadElements()
+    public List<KeyValue<String, HeadElement>> getHeadElements()
     {
-        List<KeyValue<String, Element>> headElems = null;
+        List<KeyValue<String, HeadElement>> headElems = null;
         
         if (this.headElements != null) 
         {

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java?rev=881250&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java Tue Nov 17 12:25:34 2009
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.jetspeed.portlet.HeadElement;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * HeadElementImpl
+ * 
+ * @version $Id$
+ */
+public class HeadElementImpl implements HeadElement
+{
+    
+    private static final long serialVersionUID = 1L;
+    
+    private String tagName;
+    private Map<String, String> attributes;
+    private String textContent;
+    private Collection<HeadElement> childHeadElements;
+    
+    public HeadElementImpl()
+    {
+    }
+    
+    public HeadElementImpl(final Element element)
+    {
+        tagName = element.getTagName();
+        
+        if (attributes == null)
+        {
+            attributes = new HashMap<String, String>();
+        }
+        else
+        {
+            attributes.clear();
+        }
+        
+        NamedNodeMap attrs = element.getAttributes();
+        int length = attrs.getLength();
+        
+        for (int i = 0; i < length; i++)
+        {
+            Attr attr = (Attr) attrs.item(i);
+            attributes.put(attr.getName(), attr.getValue());
+        }
+        
+        textContent = element.getTextContent();
+        
+        NodeList nodeList = element.getChildNodes();
+        length = nodeList.getLength();
+        
+        for (int i = 0; i < length; i++)
+        {
+            Node node = nodeList.item(i);
+            
+            if (node.getNodeType() == Node.ELEMENT_NODE)
+            {
+                if (childHeadElements == null)
+                {
+                    childHeadElements = new ArrayList<HeadElement>();
+                }
+                
+                childHeadElements.add(new HeadElementImpl((Element) node));
+            }
+        }
+    }
+    
+    public String getTagName()
+    {
+        return tagName;
+    }
+    
+    public boolean hasAttribute(String name)
+    {
+        return attributes.containsKey(name);
+    }
+    
+    public String getAttribute(String name)
+    {
+        return attributes.get(name);
+    }
+    
+    public Map<String, String> getAttributeMap()
+    {
+        return attributes;
+    }
+    
+    public String getTextContent()
+    {
+        return textContent;
+    }
+    
+    public void setTextContent(String textContent)
+    {
+        this.textContent = textContent;
+    }
+    
+    public boolean hasChildHeadElements()
+    {
+        return (childHeadElements != null && !childHeadElements.isEmpty());
+    }
+    
+    public Collection<HeadElement> getChildHeadElements()
+    {
+        if (childHeadElements != null)
+        {
+            return childHeadElements;
+        }
+        else
+        {
+            return Collections.emptyList();
+        }
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/HeadElementImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletRenderResponseContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletRenderResponseContextImpl.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletRenderResponseContextImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletRenderResponseContextImpl.java Tue Nov 17 12:25:34 2009
@@ -18,10 +18,8 @@
 package org.apache.jetspeed.container.impl;
 
 import java.io.IOException;
-import java.io.NotSerializableException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.io.Serializable;
 import java.util.Collection;
 
 import javax.portlet.MimeResponse;
@@ -31,6 +29,7 @@
 
 import org.apache.jetspeed.aggregator.PortletContent;
 import org.apache.jetspeed.container.PortletWindow;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.util.DOMUtils;
 import org.apache.pluto.container.PortletContainer;
 import org.apache.pluto.container.PortletRenderResponseContext;
@@ -136,30 +135,17 @@
     {
         if (MimeResponse.MARKUP_HEAD_ELEMENT.equals(key))
         {
-            Element headElement = null;
+            HeadElement headElement = null;
             
             // Note that element can be null.
             // According to the SPEC, the property with this key can be removed with null element.
             if (element != null)
             {
-                if (element instanceof Serializable)
-                {
-                    headElement = element;
-                }
-                else
-                {
-                    headElement = DOMUtils.convertToSerializableElement(element);
-                }
+                headElement = new HeadElementImpl(element);
             }
             
-            try
-            {
-                // ID attribute of element is used as keyHint for the head element if available.
-                this.portletContent.addHeadElement(headElement, DOMUtils.getIdAttribute(element));
-            }
-            catch (NotSerializableException e)
-            {
-            }
+            // ID attribute of element is used as keyHint for the head element if available.
+            this.portletContent.addHeadElement(headElement, DOMUtils.getIdAttribute(element));
         }
         else
         {

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletResponseContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletResponseContextImpl.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletResponseContextImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/impl/PortletResponseContextImpl.java Tue Nov 17 12:25:34 2009
@@ -20,15 +20,18 @@
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.container.providers.ResourceURLProviderImpl;
 import org.apache.jetspeed.request.JetspeedRequestContext;
-import org.apache.jetspeed.util.DOMUtils;
 import org.apache.pluto.container.PortletContainer;
 import org.apache.pluto.container.PortletResponseContext;
 import org.apache.pluto.container.ResourceURLProvider;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 /**
@@ -103,36 +106,19 @@
     
     public Element createElement(String tagName) throws DOMException
     {
-        Element element = null;
+        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
+        DocumentBuilder docBuilder;
         
-        // Currently, Jetspeed uses dom4j to create a serializable dom element.
-        // However, dom4j depends on Class.forName() to manage singleton, which
-        // results another org.dom4j.DocumentFactory singleton which comes from another
-        // classloader such as PA's or common's.
-        // Therefore, we need to switch back to the portal's classloader during creation.
-        
-        ClassLoader paCL = Thread.currentThread().getContextClassLoader();
-        ClassLoader portalCL = JetspeedRequestContext.class.getClassLoader();
-        boolean switchCLs = (paCL != portalCL);
-        
-        try 
+        try
         {
-            if (switchCLs)
-            {
-                Thread.currentThread().setContextClassLoader(portalCL);
-            }
-            
-            element = DOMUtils.createSerializableElement(tagName);
-        } 
-        finally 
-        {
-            if (switchCLs)
-            {
-                Thread.currentThread().setContextClassLoader(paCL);
-            }
+            docBuilder = dbfac.newDocumentBuilder();
+            Document doc = docBuilder.newDocument();
+            return doc.createElement(tagName);
+        }
+        catch (ParserConfigurationException e)
+        {
+            throw new DOMException((short) 0, "Initialization failure");
         }
-        
-        return element;
     }
 
     public void close()

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/request/JetspeedRequestContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/request/JetspeedRequestContext.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/request/JetspeedRequestContext.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/request/JetspeedRequestContext.java Tue Nov 17 12:25:34 2009
@@ -51,6 +51,7 @@
 import org.apache.jetspeed.pipeline.Pipeline;
 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
 import org.apache.jetspeed.portalsite.PortalSiteSessionContext;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.profiler.ProfileLocator;
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
@@ -61,7 +62,6 @@
 import org.apache.jetspeed.util.KeyValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.w3c.dom.Element;
 
 /**
  * Jetspeed Request Context is associated with each portal request. The request
@@ -814,11 +814,11 @@
         rcc.setRequestContext(null);
     }
     
-    public List<KeyValue<String, Element>> getMergedHeadElements()
+    public List<KeyValue<String, HeadElement>> getMergedHeadElements()
     {
         ContentPage page = getPage();
         ContentFragment root = page.getRootContentFragment();
-        List<KeyValue<String, Element>> headElements = getPortletWindow(root).getHeadElements();
+        List<KeyValue<String, HeadElement>> headElements = getPortletWindow(root).getHeadElements();
         
         HttpSession session = getRequest().getSession();
         
@@ -858,7 +858,7 @@
             return headElements;
         }
         
-        List<KeyValue<String, Element>> mergedHeadElements = new TreeList(headElements);
+        List<KeyValue<String, HeadElement>> mergedHeadElements = new TreeList(headElements);
         
         for (String windowId : windowIds)
         {

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/ui/Jetui.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/ui/Jetui.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/ui/Jetui.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/ui/Jetui.java Tue Nov 17 12:25:34 2009
@@ -30,11 +30,11 @@
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.portlets.layout.ColumnLayout;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.util.DOMUtils;
+import org.apache.jetspeed.util.HeadElementUtils;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 /**
  *
@@ -144,13 +144,13 @@
     {        
        HeaderResource hr = headerFactory.getHeaderResouce(context);
        StringBuffer result = new StringBuffer(hr.getContent());
-       List<KeyValue<String, Element>> headers = context.getMergedHeadElements();
-       for (KeyValue<String, Element> pair : headers)
+       List<KeyValue<String, HeadElement>> headers = context.getMergedHeadElements();
+       for (KeyValue<String, HeadElement> pair : headers)
        {
            if (!pair.getKey().equals("header.dojo.library.include"))
            {
-               String element = DOMUtils.stringifyElementToHtml(pair.getValue());
-               result.append(element);
+               HeadElement headElement = pair.getValue();
+               result.append(HeadElementUtils.toHtmlString(headElement));
            }
        }
        return result.toString();

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=881250&r1=881249&r2=881250&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 Tue Nov 17 12:25:34 2009
@@ -19,19 +19,7 @@
 import java.io.IOException;
 import java.io.StringWriter;
 
-import org.apache.jetspeed.util.dom.DOMElementImpl;
-import org.dom4j.dom.DOMCDATA;
-import org.dom4j.dom.DOMComment;
-import org.dom4j.dom.DOMElement;
-import org.dom4j.dom.DOMText;
-import org.dom4j.io.HTMLWriter;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
-import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 public class DOMUtils
 {
@@ -39,71 +27,11 @@
     public static final int DEFAULT_ELEMENT_STRINGIFYING_BUFFER_SIZE = 80;
     public static final int DEFAULT_INDENT = 0;
     public static final String DEFAULT_INDENT_WITH = "\t";
-    public static final OutputFormat DEFAULT_HTML_OUTPUT_FORMAT = OutputFormat.createPrettyPrint();
-    
-    static
-    {
-        DEFAULT_HTML_OUTPUT_FORMAT.setExpandEmptyElements(true);
-    }
     
     private DOMUtils()
     {
     }
     
-    public static org.w3c.dom.Element createSerializableElement(String tagName)
-    {
-        return new DOMElementImpl(tagName);
-    }
-    
-    public static org.w3c.dom.Element convertToSerializableElement(org.w3c.dom.Element element)
-    {
-        return (org.w3c.dom.Element) convertElement(element);
-    }
-    
-    public static org.dom4j.Element convertElement(org.w3c.dom.Element element)
-    {
-        DOMElement domElement = (DOMElement) createSerializableElement(element.getNodeName());
-        
-        NamedNodeMap attrs = element.getAttributes();
-        
-        for (int i = 0; i < attrs.getLength(); i++) 
-        {
-            Attr attr = (Attr) attrs.item(i);
-            domElement.setAttribute(attr.getName(), attr.getValue());
-        }
-        
-        NodeList children = element.getChildNodes();
-        boolean hasChildren = (children.getLength() > 0);
-
-        if (hasChildren) 
-        {
-            for (int i = 0; i < children.getLength(); i++) 
-            {
-                Node child = children.item(i);
-
-                switch (child.getNodeType()) 
-                {
-                case Node.ELEMENT_NODE:
-                    domElement.add(convertElement((org.w3c.dom.Element) child));
-                    break;
-                case Node.TEXT_NODE:
-                    domElement.add(new DOMText(child.getNodeValue()));
-                    break;
-                case Node.COMMENT_NODE:
-                    domElement.add(new DOMComment(child.getNodeValue()));
-                    break;
-                case Node.CDATA_SECTION_NODE:
-                    domElement.add(new DOMCDATA(child.getNodeValue()));
-                    break;
-                default:
-                    // Do not support entity reference node and processing instruction node.
-                }
-            }
-        }
-        
-        return domElement;
-    }
-
     public static String stringifyElement(org.w3c.dom.Element element)
     {
         return stringifyElement(element, DEFAULT_ELEMENT_STRINGIFYING_BUFFER_SIZE, DEFAULT_INDENT, DEFAULT_INDENT_WITH);
@@ -127,79 +55,9 @@
         return stringified;
     }
     
-    public static String stringifyElement(org.dom4j.Element element)
-    {
-        return stringifyElement(element, DEFAULT_ELEMENT_STRINGIFYING_BUFFER_SIZE, DEFAULT_INDENT_WITH);
-    }
-    
-    public static String stringifyElement(org.dom4j.Element element, int initialBufferSize, String indentWith)
-    {
-        OutputFormat outputFormat = new OutputFormat();
-        outputFormat.setIndent(indentWith);
-        return stringifyElement(element, initialBufferSize, outputFormat);
-    }
-    
-    public static String stringifyElement(org.dom4j.Element element, int initialBufferSize, OutputFormat outputFormat)
-    {
-        String stringified = null;
-        StringWriter writer = new StringWriter(initialBufferSize);
-        XMLWriter xmlWriter = null;
-        
-        try
-        {
-            xmlWriter = new XMLWriter(writer, outputFormat);
-            xmlWriter.write(element);
-            xmlWriter.flush();
-            xmlWriter.close();
-        }
-        catch (IOException e)
-        {
-        }
-        finally
-        {
-            if (xmlWriter != null)
-            {
-                try { xmlWriter.close(); } catch (IOException ce) { }
-            }
-        }
-        
-        stringified = writer.toString();
-        return stringified;
-    }
-    
     public static String stringifyElementToHtml(Element element)
     {
-        String html = null;
-
-        if (element instanceof org.dom4j.Element)
-        {
-            StringWriter writer = new StringWriter(DEFAULT_ELEMENT_STRINGIFYING_BUFFER_SIZE);
-            XMLWriter xmlWriter = null;
-            
-            try
-            {
-                xmlWriter = new HTMLWriter(writer, DEFAULT_HTML_OUTPUT_FORMAT);
-                xmlWriter.write(element);
-                xmlWriter.flush();
-                xmlWriter.close();
-                html = writer.toString();
-            }
-            catch (IOException e)
-            {
-            }
-            finally
-            {
-                if (xmlWriter != null)
-                {
-                    try { xmlWriter.close(); } catch (IOException ce) { }
-                }
-            }
-        }
-        else
-        {
-            html = stringifyElement(element);
-        }
-        
+        String html = stringifyElement(element);
         return html;
     }
     

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java?rev=881250&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java Tue Nov 17 12:25:34 2009
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.util;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jetspeed.portlet.HeadElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import edu.emory.mathcs.backport.java.util.Arrays;
+
+/**
+ * HeadElementUtils
+ * 
+ * @version $Id$
+ */
+public class HeadElementUtils
+{
+
+    private static final int HEX = 16;
+    
+    private static final String[] KNOWN_ENTITIES = {"gt", "amp", "lt", "apos", "quot"};
+    
+    private static final Set<String> EXPANDABLE_HEAD_ELEMENT_TAG_NAME_SET = 
+        new HashSet<String>(Arrays.asList(new String [] { "SCRIPT", "STYLE", "TITLE" } ));
+    
+    private static final Set<String> PREFORMATTED_HEAD_ELEMENT_TAG_NAME_SET = 
+        new HashSet<String>(Arrays.asList(new String [] { "SCRIPT", "STYLE" } ));
+    
+    private static Logger log = LoggerFactory.getLogger(HeadElementUtils.class);
+    
+    private HeadElementUtils()
+    {
+    }
+    
+    public static String toHtmlString(final HeadElement headElement)
+    {
+        String tagName = headElement.getTagName().toUpperCase();
+        boolean isExpanedEmptyElements = EXPANDABLE_HEAD_ELEMENT_TAG_NAME_SET.contains(tagName);
+        boolean isPreformattedTextContent = PREFORMATTED_HEAD_ELEMENT_TAG_NAME_SET.contains(tagName);
+        return toString(headElement, isExpanedEmptyElements, isPreformattedTextContent, false);
+    }
+    
+    public static String toXhtmlString(final HeadElement headElement)
+    {
+        String tagName = headElement.getTagName().toUpperCase();
+        boolean isExpanedEmptyElements = EXPANDABLE_HEAD_ELEMENT_TAG_NAME_SET.contains(tagName);
+        boolean isPreformattedTextContent = PREFORMATTED_HEAD_ELEMENT_TAG_NAME_SET.contains(tagName);
+        return toString(headElement, isExpanedEmptyElements, isPreformattedTextContent, true);
+    }
+    
+    public static String toString(final HeadElement headElement, boolean isExpanedEmptyElements, boolean isPreformattedTextContent, boolean isPreformattedTextContentInCDATA)
+    {
+        StringWriter writer = new StringWriter(80);
+        
+        try
+        {
+            writeHeadElement(writer, headElement, isExpanedEmptyElements, isPreformattedTextContent, isPreformattedTextContentInCDATA);
+        }
+        catch (IOException e)
+        {
+            log.error("IOException during writing to string writer for head element. {}", e.toString());
+        }
+        
+        return writer.toString();
+    }
+    
+    public static void writeHeadElement(final Writer writer, final HeadElement headElement, boolean isExpandEmptyElements, boolean isPreformattedTextContent, boolean isPreformattedTextContentInCDATA) throws IOException
+    {
+        String tagName = headElement.getTagName();
+        writer.write('<');
+        writer.write(tagName);
+        
+        for (Map.Entry<String, String> entry : headElement.getAttributeMap().entrySet())
+        {
+            writer.write(' ');
+            writer.write(entry.getKey());
+            writer.write("=\"");
+            writer.write(encode(entry.getValue()));
+            writer.write("\"");
+        }
+        
+        if (!headElement.hasChildHeadElements())
+        {
+            String textContent = headElement.getTextContent();
+            
+            if (!isExpandEmptyElements && (textContent == null || "".equals(textContent)))
+            {
+                writer.write("/>");
+            }
+            else
+            {
+                writer.write('>');
+                
+                if (textContent != null)
+                {
+                    if (isPreformattedTextContent)
+                    {
+                        if (isPreformattedTextContentInCDATA)
+                        {
+                            writer.write("<![CDATA[");
+                            writer.write(textContent);
+                            writer.write("]]>");
+                        }
+                        else
+                        {
+                            writer.write(textContent);
+                        }
+                    }
+                    else
+                    {
+                        writer.write(encode(textContent));
+                    }
+                }
+                
+                writer.write("</");
+                writer.write(tagName);
+                writer.write('>');
+            }
+        }
+        else
+        {
+            writer.write(">\n");
+            
+            for (HeadElement childHeadElement : headElement.getChildHeadElements())
+            {
+                writeHeadElement(writer, childHeadElement, isPreformattedTextContent, isExpandEmptyElements, isPreformattedTextContentInCDATA);
+                writer.write('\n');
+            }
+            
+            writer.write("</");
+            writer.write(tagName);
+            writer.write('>');
+        }
+    }
+    
+    /**
+     * Escape &lt;, &gt; &amp; &apos;, &quot; as their entities and
+     * drop characters that are illegal in XML documents.
+     * @param value the string to encode.
+     * @return the encoded string.
+     */
+    public static String encode(String value) {
+        StringBuffer sb = new StringBuffer();
+        int len = value.length();
+        for (int i = 0; i < len; i++) {
+            char c = value.charAt(i);
+            switch (c) {
+            case '<':
+                sb.append("&lt;");
+                break;
+            case '>':
+                sb.append("&gt;");
+                break;
+            case '\'':
+                sb.append("&apos;");
+                break;
+            case '\"':
+                sb.append("&quot;");
+                break;
+            case '&':
+                int nextSemi = value.indexOf(";", i);
+                if (nextSemi < 0
+                    || !isReference(value.substring(i, nextSemi + 1))) {
+                    sb.append("&amp;");
+                } else {
+                    sb.append('&');
+                }
+                break;
+            default:
+                if (isLegalCharacter(c)) {
+                    sb.append(c);
+                }
+                break;
+            }
+        }
+        return sb.substring(0);
+    }
+    
+    /**
+     * Is the given argument a character or entity reference?
+     * @param ent the value to be checked.
+     * @return true if it is an entity.
+     */
+    private static boolean isReference(String ent) {
+        if (!(ent.charAt(0) == '&') || !ent.endsWith(";")) {
+            return false;
+        }
+
+        if (ent.charAt(1) == '#') {
+            if (ent.charAt(2) == 'x') {
+                try {
+                    // CheckStyle:MagicNumber OFF
+                    Integer.parseInt(ent.substring(3, ent.length() - 1), HEX);
+                    // CheckStyle:MagicNumber ON
+                    return true;
+                } catch (NumberFormatException nfe) {
+                    return false;
+                }
+            } else {
+                try {
+                    Integer.parseInt(ent.substring(2, ent.length() - 1));
+                    return true;
+                } catch (NumberFormatException nfe) {
+                    return false;
+                }
+            }
+        }
+
+        String name = ent.substring(1, ent.length() - 1);
+        for (int i = 0; i < KNOWN_ENTITIES.length; i++) {
+            if (name.equals(KNOWN_ENTITIES[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    /**
+     * Is the given character allowed inside an XML document?
+     *
+     * <p>See XML 1.0 2.2 <a
+     * href="http://www.w3.org/TR/1998/REC-xml-19980210#charsets">
+     * http://www.w3.org/TR/1998/REC-xml-19980210#charsets</a>.</p>
+     * @param c the character to test.
+     * @return true if the character is allowed.
+     */
+    private static boolean isLegalCharacter(char c) {
+        // CheckStyle:MagicNumber OFF
+        if (c == 0x9 || c == 0xA || c == 0xD) {
+            return true;
+        } else if (c < 0x20) {
+            return false;
+        } else if (c <= 0xD7FF) {
+            return true;
+        } else if (c < 0xE000) {
+            return false;
+        } else if (c <= 0xFFFD) {
+            return true;
+        }
+        // CheckStyle:MagicNumber ON
+        return false;
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/HeadElementUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=881250&r1=881249&r2=881250&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 Tue Nov 17 12:25:34 2009
@@ -35,8 +35,6 @@
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.PropertiesConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.jetspeed.Jetspeed;
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.aggregator.PortletRenderer;
@@ -49,14 +47,16 @@
 import org.apache.jetspeed.locator.TemplateLocatorException;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.portlet.HeaderPhaseSupportConstants;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.ArgUtil;
-import org.apache.jetspeed.util.DOMUtils;
+import org.apache.jetspeed.util.HeadElementUtils;
 import org.apache.jetspeed.util.KeyValue;
 import org.apache.jetspeed.util.Path;
 import org.apache.velocity.context.Context;
-import org.w3c.dom.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * <p>
@@ -845,24 +845,24 @@
         }
     }
 
-    public String getElementHtmlString(Element element)
+    public String getElementHtmlString(HeadElement headElement)
     {
-        return DOMUtils.stringifyElementToHtml(element);
+        return HeadElementUtils.toHtmlString(headElement);
     }
 
-    public List<KeyValue<String, Element>> getHeadElements(ContentFragment f) throws Exception
+    public List<KeyValue<String, HeadElement>> getHeadElements(ContentFragment f) throws Exception
     {
         return getPortletWindow(f).getHeadElements();
     }
 
-    public List<KeyValue<String, Element>> getHeadElements() throws Exception
+    public List<KeyValue<String, HeadElement>> getHeadElements() throws Exception
     {
         return requestContext.getMergedHeadElements();
     }
 
-    public boolean isDojoEnabled(List<KeyValue<String, Element>> headElements)
+    public boolean isDojoEnabled(List<KeyValue<String, HeadElement>> headElements)
     {
-        for (KeyValue<String, Element> kvPair : headElements)
+        for (KeyValue<String, HeadElement> kvPair : headElements)
         {
             if (HeaderPhaseSupportConstants.HEAD_ELEMENT_CONTRIBUTION_ELEMENT_ID_DOJO_LIBRARY_INCLUDE.equals(kvPair.getKey()))
             {

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/state/MockRequestContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/state/MockRequestContext.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/state/MockRequestContext.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/state/MockRequestContext.java Tue Nov 17 12:25:34 2009
@@ -37,11 +37,11 @@
 import org.apache.jetspeed.om.portlet.Language;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.pipeline.Pipeline;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.KeyValue;
 import org.apache.jetspeed.window.MockPortletWindow;
-import org.w3c.dom.Element;
 
 /**
  * @version $Id$
@@ -506,7 +506,7 @@
         return false;
     }
     
-    public List<KeyValue<String, Element>> getMergedHeadElements()
+    public List<KeyValue<String, HeadElement>> getMergedHeadElements()
     {
         return Collections.emptyList();
     }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestDOMUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestDOMUtils.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestDOMUtils.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestDOMUtils.java Tue Nov 17 12:25:34 2009
@@ -16,16 +16,11 @@
  */
 package org.apache.jetspeed.util;
 
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.StringWriter;
-
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.lang.SerializationUtils;
 import org.w3c.dom.CDATASection;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -59,34 +54,6 @@
         assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
         assertTrue("the child element is wrong.", stringified.contains("<source id=\"my-test-javascript-source\">source is available.</source>"));
         
-        // Tests with element created by conversion from standard element to serializable element
-        
-        Element converted = (Element) DOMUtils.convertElement(element);
-        assertTrue("converted element is not serializable!", converted instanceof Serializable);
-        assertEquals("converted element name is wrong.", element.getNodeName(), converted.getNodeName());
-        
-        // Tests with element deserialized after serialization
-        
-        Element deserialized = (Element) SerializationUtils.clone((Serializable) converted);
-        assertEquals("deserialized element name is wrong.", converted.getNodeName(), deserialized.getNodeName());
-        stringified = DOMUtils.stringifyElement((org.dom4j.Element) deserialized);
-        System.out.println("deserialized element's stringified: " + stringified);
-        assertTrue("deserialized element name is different.", stringified.contains("<script "));
-        assertTrue("id attribute does not exist.", stringified.contains("id=\"my-test-javascript\""));
-        assertTrue("type attribute does not exist.", stringified.contains("type=\"text/javascript\""));
-        assertTrue("the text content is wrong.", stringified.contains("alert("));
-        assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
-        assertTrue("the child element is wrong.", stringified.contains("<source id=\"my-test-javascript-source\">source is available.</source>"));
-        
-        stringified = DOMUtils.stringifyElement((org.dom4j.Element) converted);
-        System.out.println("converted element's stringified: " + stringified);
-        assertTrue("converted element name is different.", stringified.contains("<script "));
-        assertTrue("id attribute does not exist.", stringified.contains("id=\"my-test-javascript\""));
-        assertTrue("type attribute does not exist.", stringified.contains("type=\"text/javascript\""));
-        assertTrue("the text content is wrong.", stringified.contains("alert("));
-        assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
-        assertTrue("the child element is wrong.", stringified.contains("<source id=\"my-test-javascript-source\">source is available.</source>"));
-        
         // Tests with element having CDATA child node
         // setTextContent() should replace the CDATA node.
         
@@ -106,69 +73,4 @@
         assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
         assertTrue("the child element is wrong.", stringified.contains("<source id=\"my-test-javascript-source\">source is available.</source>"));
     }
-
-    public void testDOM4JElement() throws Exception
-    {
-        // Tests if setTextContent() is working 
-        // with our serializable element implementation which is based on dom4j
-        
-        org.w3c.dom.Element element = DOMUtils.createSerializableElement("script");
-        element.setAttribute("id", "my-test-javascript");
-        element.setAttribute("type", "text/javascript");
-        element.setTextContent("alert('<Hello, World!>');");
-        
-        String stringified = DOMUtils.stringifyElement((org.dom4j.Element) element);
-        
-        System.out.println("stringified: " + stringified);
-        assertTrue("element name is different.", stringified.contains("<script "));
-        assertTrue("id attribute does not exist.", stringified.contains("id=\"my-test-javascript\""));
-        assertTrue("type attribute does not exist.", stringified.contains("type=\"text/javascript\""));
-        assertTrue("the text content is wrong.", stringified.contains("alert("));
-        assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
-        
-        // Tests if getOwnerDocument() is working and it is possible to append text node
-        
-        element = DOMUtils.createSerializableElement("script");
-        element.setAttribute("id", "my-test-javascript");
-        element.setAttribute("type", "text/javascript");
-        element.appendChild(element.getOwnerDocument().createTextNode("alert('<Hello, World!>');"));
-        
-        stringified = DOMUtils.stringifyElement((org.dom4j.Element) element);
-        
-        System.out.println("stringified: " + stringified);
-        assertTrue("element name is different.", stringified.contains("<script "));
-        assertTrue("id attribute does not exist.", stringified.contains("id=\"my-test-javascript\""));
-        assertTrue("type attribute does not exist.", stringified.contains("type=\"text/javascript\""));
-        assertTrue("the text content is wrong.", stringified.contains("alert("));
-        assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
-    }
-    
-    public void testDOM4JWriting() throws Exception 
-    {
-        org.w3c.dom.Element element = DOMUtils.createSerializableElement("script");
-        element.setAttribute("id", "my-test-javascript");
-        element.setAttribute("type", "text/javascript");
-        element.setTextContent("alert('<Hello, World!>');");
-        
-        String stringified = null;
-        StringWriter writer = new StringWriter(80);
-        
-        try 
-        {
-            DOMElementWriter domWriter = new DOMElementWriter();
-            domWriter.write(element, writer, 0, "  ");
-        } 
-        catch (IOException e) 
-        {
-        }
-
-        stringified = writer.toString();
-        System.out.println("stringified: " + stringified);
-        assertTrue("element name is different.", stringified.contains("<script "));
-        assertTrue("id attribute does not exist.", stringified.contains("id=\"my-test-javascript\""));
-        assertTrue("type attribute does not exist.", stringified.contains("type=\"text/javascript\""));
-        assertTrue("the text content is wrong.", stringified.contains("alert("));
-        assertTrue("the text content is wrong.", stringified.contains("Hello, World!"));
-    }
-    
 }

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java?rev=881250&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java Tue Nov 17 12:25:34 2009
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.util;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.jetspeed.container.impl.HeadElementImpl;
+import org.apache.jetspeed.portlet.HeadElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class TestHeadElementUtils extends TestCase
+{
+    
+    private Document document;
+    
+    @Override
+    public void setUp() throws Exception
+    {
+        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
+        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
+        document = docBuilder.newDocument();
+    }
+
+    public void testScriptHeadElements() throws Exception
+    {
+        Element elem = document.createElement("script");
+        elem.setAttribute("language", "javascript");
+        elem.setAttribute("src", "http://localhost:8080/javascript/util.js");
+        elem.setAttribute("customAttribute", "<test>");
+        HeadElement headElem = new HeadElementImpl(elem);
+        
+        String headElemString = HeadElementUtils.toString(headElem, false, true, false);
+        System.out.println("headElemString: " + headElemString);
+        assertTrue(headElem.getTextContent() == null || "".equals(headElem.getTextContent()));
+        assertFalse(headElemString.endsWith("</script>"));
+        
+        headElemString = HeadElementUtils.toString(headElem, true, true, false);
+        System.out.println("headElemString: " + headElemString);
+        assertEquals(HeadElementUtils.toHtmlString(headElem), headElemString);
+        assertTrue(headElem.getTextContent() == null || "".equals(headElem.getTextContent()));
+        assertTrue(headElemString.endsWith("</script>"));
+        
+        elem = document.createElement("script");
+        elem.setAttribute("language", "javascript");
+        elem.setTextContent("\r\nif (true) {\r\n\talert(\"<test/>\");\r\n}\r\n");
+        headElem = new HeadElementImpl(elem);
+
+        headElemString = HeadElementUtils.toString(headElem, true, true, false);
+        System.out.println("headElemString: " + headElemString);
+        assertEquals(HeadElementUtils.toHtmlString(headElem), headElemString);
+        assertFalse(headElem.getTextContent() == null || "".equals(headElem.getTextContent()));
+        assertTrue(headElemString.endsWith("</script>"));
+
+        headElemString = HeadElementUtils.toXhtmlString(headElem);
+        System.out.println("headElemString: " + headElemString);
+        assertFalse(headElem.getTextContent() == null || "".equals(headElem.getTextContent()));
+        assertTrue(headElemString.contains("<![CDATA["));
+        assertTrue(headElemString.contains("]]>"));
+        assertTrue(headElemString.endsWith("</script>"));
+    }
+    
+    public void testMetaElements() throws Exception
+    {
+        Element elem = document.createElement("meta");
+        elem.setAttribute("name", "keywords");
+        elem.setAttribute("content", "HTML,CSS,XML,JavaScript");
+        HeadElement headElem = new HeadElementImpl(elem);
+        
+        String headElemString = HeadElementUtils.toString(headElem, false, true, false);
+        System.out.println("headElemString: " + headElemString);
+        assertEquals(HeadElementUtils.toHtmlString(headElem), headElemString);
+        assertTrue(headElemString.startsWith("<meta "));
+        assertTrue(headElemString.endsWith("/>"));
+        assertTrue(headElemString.contains("name=\"keywords\""));
+        assertTrue(headElemString.contains("content=\"HTML,CSS,XML,JavaScript\""));
+    }
+    
+    public void testHandlerElements() throws Exception
+    {
+        Element elem = document.createElement("handler");
+        elem.setAttribute("type", "text/x-vbscript");
+        elem.setAttribute("src", "http://localhost:8080/javascript/calc.vbs");
+        Element child = document.createElement("handler");
+        child.setAttribute("type", "text/javascript");
+        child.setTextContent("\r\n//some inline javascript\r\n");
+        elem.appendChild(child);
+        
+        HeadElement headElem = new HeadElementImpl(elem);
+        String headElemString = HeadElementUtils.toString(headElem, true, true, false);
+        System.out.println("headElemString: " + headElemString);
+        assertEquals(HeadElementUtils.toHtmlString(headElem), headElemString);
+        assertTrue(headElemString.startsWith("<handler "));
+        assertTrue(headElemString.indexOf("<handler ", 1) > 0);
+        assertTrue(headElemString.endsWith("</handler>"));
+        assertTrue(headElemString.substring(0, headElemString.length() - "</handler>".length()).trim().endsWith("</handler>"));
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/util/TestHeadElementUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/window/MockPortletWindow.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/window/MockPortletWindow.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/window/MockPortletWindow.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/window/MockPortletWindow.java Tue Nov 17 12:25:34 2009
@@ -30,11 +30,13 @@
 import org.apache.jetspeed.factory.PortletInstance;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.KeyValue;
 import org.apache.pluto.container.PortletRequestContext;
 import org.apache.pluto.container.PortletResponseContext;
-import org.w3c.dom.Element;
+
+import edu.emory.mathcs.backport.java.util.Collections;
 
 /**
  * @version $Id$
@@ -239,9 +241,8 @@
         return true;
     }
 
-    public List<KeyValue<String, Element>> getHeadElements()
+    public List<KeyValue<String, HeadElement>> getHeadElements()
     {
-        // TODO Auto-generated method stub
-        return null;
+        return Collections.emptyList();
     }
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java Tue Nov 17 12:25:34 2009
@@ -17,11 +17,8 @@
 package org.apache.jetspeed.om.window.impl;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
 
 import javax.portlet.PortletMode;
 import javax.portlet.PortletRequest;
@@ -29,7 +26,6 @@
 import javax.portlet.WindowState;
 
 import org.apache.commons.collections.list.TreeList;
-import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.aggregator.PortletContent;
 import org.apache.jetspeed.aggregator.RenderTrackable;
 import org.apache.jetspeed.container.PortletWindow;
@@ -37,7 +33,7 @@
 import org.apache.jetspeed.factory.PortletInstance;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
-import org.apache.jetspeed.portlet.HeaderPhaseSupportConstants;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.HeadElementsUtils;
 import org.apache.jetspeed.util.KeyValue;
@@ -80,7 +76,7 @@
     private PortletRequestContext portletRequestContext;
     private PortletResponse portletResponse;
     private PortletInstance portletInstance;
-    private List<KeyValue<String, Element>> headElements;
+    private List<KeyValue<String, HeadElement>> headElements;
 
     private boolean valid;
     
@@ -298,7 +294,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    public List<KeyValue<String, Element>> getHeadElements()
+    public List<KeyValue<String, HeadElement>> getHeadElements()
     {
         if (headElements == null && fragment != null && fragment.getPortletContent() != null)
         {

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/aggregator/PortletContent.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/aggregator/PortletContent.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/aggregator/PortletContent.java (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/aggregator/PortletContent.java Tue Nov 17 12:25:34 2009
@@ -16,13 +16,12 @@
 */
 package org.apache.jetspeed.aggregator;
 
-import java.io.NotSerializableException;
 import java.io.PrintWriter;
 import java.util.List;
 
 import org.apache.jetspeed.cache.ContentCacheKey;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 /**
  * <p>
@@ -122,9 +121,8 @@
      * 
      * @param element
      * @param keyHint
-     * @throws NotSerializableException
      */
-    void addHeadElement(Element element, String keyHint) throws NotSerializableException;
+    void addHeadElement(HeadElement element, String keyHint);
     
     /**
      * Retrieves header element key value pairs to be contributed to the page.
@@ -132,7 +130,7 @@
      * 
      * @return
      */
-    List<KeyValue<String, Element>> getHeadElements(); 
+    List<KeyValue<String, HeadElement>> getHeadElements(); 
     
     void reset();
     

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/PortletWindow.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/PortletWindow.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/PortletWindow.java (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/PortletWindow.java Tue Nov 17 12:25:34 2009
@@ -26,11 +26,11 @@
 import org.apache.jetspeed.factory.PortletInstance;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.KeyValue;
 import org.apache.pluto.container.PortletRequestContext;
 import org.apache.pluto.container.PortletResponseContext;
-import org.w3c.dom.Element;
 
 /**
  * @version $Id$
@@ -72,6 +72,6 @@
      * 
      * @return
      */
-    List<KeyValue<String, Element>> getHeadElements();
+    List<KeyValue<String, HeadElement>> getHeadElements();
     
 }

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=881250&r1=881249&r2=881250&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 Tue Nov 17 12:25:34 2009
@@ -28,8 +28,8 @@
 import org.apache.jetspeed.locator.TemplateLocatorException;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 /**
  * JetspeedPowerTool
@@ -246,7 +246,7 @@
      * @param element
      * @return
      */
-    String getElementHtmlString(Element element);
+    String getElementHtmlString(HeadElement element);
     
     /**
      * Returns all the contributed head elements from the fragment and its child fragments.
@@ -254,20 +254,20 @@
      * @return
      * @throws Exception
      */
-    List<KeyValue<String, Element>> getHeadElements(ContentFragment f) throws Exception;;
+    List<KeyValue<String, HeadElement>> getHeadElements(ContentFragment f) throws Exception;;
 
     /**
      * Returns all the contributed head elements from the current fragment and its child fragments.
      * @return
      * @throws Exception
      */
-    List<KeyValue<String, Element>> getHeadElements() throws Exception;
+    List<KeyValue<String, HeadElement>> getHeadElements() throws Exception;
     
     /**
      * Returns true if head element has dojo library inclusion.
      * @param headElements
      * @return
      */
-    boolean isDojoEnabled(List<KeyValue<String, Element>> headElements);
+    boolean isDojoEnabled(List<KeyValue<String, HeadElement>> headElements);
     
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/mockobjects/request/MockRequestContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/mockobjects/request/MockRequestContext.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/mockobjects/request/MockRequestContext.java (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/mockobjects/request/MockRequestContext.java Tue Nov 17 12:25:34 2009
@@ -38,10 +38,10 @@
 import org.apache.jetspeed.om.portlet.Language;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.pipeline.Pipeline;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.util.KeyValue;
-import org.w3c.dom.Element;
 
 
 
@@ -602,7 +602,7 @@
         return false;
     }
     
-    public List<KeyValue<String, Element>> getMergedHeadElements()
+    public List<KeyValue<String, HeadElement>> getMergedHeadElements()
     {
         return Collections.emptyList();
     }

Added: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java?rev=881250&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java (added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java Tue Nov 17 12:25:34 2009
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlet;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * HeadElement interface wrapping a head contribution element
+ * 
+ * @version $Id$
+ */
+public interface HeadElement extends Serializable
+{
+    
+    String getTagName();
+    
+    boolean hasAttribute(String name);
+    
+    String getAttribute(String name);
+    
+    Map<String, String> getAttributeMap();
+    
+    String getTextContent();
+    
+    void setTextContent(String textContent);
+    
+    boolean hasChildHeadElements();
+    
+    Collection<HeadElement> getChildHeadElements();
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/portlet/HeadElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/request/RequestContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/request/RequestContext.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/request/RequestContext.java (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/request/RequestContext.java Tue Nov 17 12:25:34 2009
@@ -28,16 +28,16 @@
 
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.capabilities.CapabilityMap;
+import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.container.url.PortalURL;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
+import org.apache.jetspeed.om.portlet.Language;
+import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.pipeline.Pipeline;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.util.KeyValue;
-import org.apache.jetspeed.om.portlet.Language;
-import org.apache.jetspeed.om.portlet.PortletDefinition;
-import org.apache.jetspeed.container.PortletWindow;
-import org.w3c.dom.Element;
 
 /**
  * Portal Request Context is associated with each request
@@ -430,7 +430,7 @@
      * Merges and returns the head elements contributed by portlets. 
      * @return
      */
-    List<KeyValue<String, Element>> getMergedHeadElements();
+    List<KeyValue<String, HeadElement>> getMergedHeadElements();
     
 }
 

Modified: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/HeadElementsUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/HeadElementsUtils.java?rev=881250&r1=881249&r2=881250&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/HeadElementsUtils.java (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/HeadElementsUtils.java Tue Nov 17 12:25:34 2009
@@ -25,8 +25,8 @@
 
 import org.apache.jetspeed.aggregator.PortletContent;
 import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.portlet.HeadElement;
 import org.apache.jetspeed.portlet.HeaderPhaseSupportConstants;
-import org.w3c.dom.Element;
 
 public class HeadElementsUtils
 {
@@ -36,7 +36,7 @@
     }
     
     @SuppressWarnings("unchecked")
-    public static void aggregateHeadElements(List<KeyValue<String, Element>> aggregatedHeadElements, ContentFragment contentFragment)
+    public static void aggregateHeadElements(List<KeyValue<String, HeadElement>> aggregatedHeadElements, ContentFragment contentFragment)
     {
         List<ContentFragment> childContentFragments = (List<ContentFragment>) contentFragment.getContentFragments();
         
@@ -60,7 +60,7 @@
         }
     }
     
-    public static void aggregateHeadElements(List<KeyValue<String, Element>> aggregatedHeadElements, List<KeyValue<String, Element>> headElements)
+    public static void aggregateHeadElements(List<KeyValue<String, HeadElement>> aggregatedHeadElements, List<KeyValue<String, HeadElement>> headElements)
     {
         // Brief explanation on head element aggregation algorithm (Thanks to Ate for the brilliant ideas!):
         // - Precondition: start from the zero as insertion index.
@@ -74,7 +74,7 @@
         {
             int insertionIndex = 0;
             
-            for (KeyValue<String, Element> kvPair : headElements)
+            for (KeyValue<String, HeadElement> kvPair : headElements)
             {
                 int offset = aggregatedHeadElements.indexOf(kvPair);
                 
@@ -90,15 +90,15 @@
         }
     }
     
-    public static void mergeHeadElementsByHint( List<KeyValue<String, Element>> headElements )
+    public static void mergeHeadElementsByHint( List<KeyValue<String, HeadElement>> headElements )
     {
-        Map<String, Element> firstElementByMergeHint = new HashMap<String, Element>();
+        Map<String, HeadElement> firstElementByMergeHint = new HashMap<String, HeadElement>();
         Map<String, Set<String>> mergedTextContents = new HashMap<String, Set<String>>();
         
-        for (Iterator<KeyValue<String, Element>> it = headElements.iterator(); it.hasNext(); )
+        for (Iterator<KeyValue<String, HeadElement>> it = headElements.iterator(); it.hasNext(); )
         {
-            KeyValue<String, Element> kvPair = it.next();
-            Element element = kvPair.getValue();
+            KeyValue<String, HeadElement> kvPair = it.next();
+            HeadElement element = kvPair.getValue();
             
             if (element.hasAttribute(HeaderPhaseSupportConstants.HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_ATTRIBUTE))
             {
@@ -134,10 +134,10 @@
             }
         }
         
-        for (Map.Entry<String, Element> entry : firstElementByMergeHint.entrySet())
+        for (Map.Entry<String, HeadElement> entry : firstElementByMergeHint.entrySet())
         {
             String mergeHint = entry.getKey();
-            Element firstElement = entry.getValue();
+            HeadElement firstElement = entry.getValue();
             Set<String> textContentSet = mergedTextContents.get(mergeHint);
             
             StringBuilder sb = new StringBuilder(80);



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