You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/10/31 02:14:31 UTC

svn commit: r709318 - in /portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade: components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/ componen...

Author: ate
Date: Thu Oct 30 18:14:30 2008
New Revision: 709318

URL: http://svn.apache.org/viewvc?rev=709318&view=rev
Log:
JS2-871 - Upgrade Pluto container to version 2.0
See:  http://issues.apache.org/jira/browse/JS2-871
- completion of the JetspeedDescriptorService implementation

Added:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/web-app_2_3.dtd   (props changed)
      - copied unchanged from r709132, portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/web-app_2_3.dtd
Removed:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/web-app_2_3.dtd
Modified:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorServiceImpl.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorService.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/om/portlet/PortletApplication.java

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java?rev=709318&r1=709317&r2=709318&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java Thu Oct 30 18:14:30 2008
@@ -299,9 +299,9 @@
 
 		try
 		{
-            // load the web.xml
-            log.info("Loading portlet.xml and web.xml...." + paName);
+            log.info("Loading deployment descriptors for "+paName+" ....");
 			pa = paWar.createPortletApp(paClassLoader);
+            pa.setApplicationType(paType);
 			if (revision > 0)
 			{
 			    pa.setRevision(revision);

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java?rev=709318&r1=709317&r2=709318&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java Thu Oct 30 18:14:30 2008
@@ -61,22 +61,10 @@
  */
 public class PortletApplicationWar
 {
-    protected static final String WEB_XML_STRING = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>" +
-            "<!DOCTYPE web-app " +
-            "PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' " + 
-           "'http://java.sun.com/dtd/web-app_2_3.dtd'>\n" +
-            "<web-app></web-app>";
-
     public static final String PORTLET_XML_PATH = "WEB-INF/portlet.xml";
     public static final String WEB_XML_PATH = "WEB-INF/web.xml";
     public static final String EXTENDED_PORTLET_XML_PATH = "WEB-INF/jetspeed-portlet.xml";
 
-    protected static final int MAX_BUFFER_SIZE = 1024;
-
-    public static final String JETSPEED_SERVLET_XPATH = "/web-app/servlet/servlet-name[contains(child::text(), \"JetspeedContainer\")]";
-    public static final String JETSPEED_SERVLET_MAPPING_XPATH = "/web-app/servlet-mapping/servlet-name[contains(child::text(), \"JetspeedContainer\")]";
-
     protected static final Log log = LogFactory.getLog("deployment");
 
     protected String paName;
@@ -87,12 +75,6 @@
     private long paChecksum;
     protected JetspeedDescriptorService descriptorService;
 
-    protected static final String[] ELEMENTS_BEFORE_SERVLET = new String[]{"icon", "display-name", "description",
-            "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet"};
-    protected static final String[] ELEMENTS_BEFORE_SERVLET_MAPPING = new String[]{"icon", "display-name",
-            "description", "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
-            "servlet-mapping"};
-
     /**
      * @param warFile
      *            {@link org.apache.jetspeed.util.FileSystemHelper}representing
@@ -162,10 +144,10 @@
      * 
      * @return @throws
      *         PortletApplicationException
-     * @throws IOException
+     * @throws Exception
      * @see org.apache.jetspeed.uitl.descriptor.PortletApplicationDescriptor
      */
-    public PortletApplication createPortletApp(ClassLoader classLoader) throws PortletApplicationException, IOException
+    public PortletApplication createPortletApp(ClassLoader classLoader) throws Exception
     {
         InputStream webXmlStream = getInputStream(WEB_XML_PATH);
         InputStream portletXmlStream = getInputStream(PORTLET_XML_PATH);
@@ -182,6 +164,8 @@
         {
             portletApp = descriptorService.read(webXmlStream, portletXmlStream, extStream);
             validate();
+            portletApp.setName(paName);
+            portletApp.setContextRoot(webAppContextRoot);
             portletApp.setChecksum(paChecksum);
             return portletApp;
         }
@@ -202,8 +186,7 @@
         }
     }
 
-    public PortletApplication createPortletApp() 
-    throws PortletApplicationException, IOException
+    public PortletApplication createPortletApp() throws Exception
     {
         return createPortletApp(this.getClass().getClassLoader());
     }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorServiceImpl.java?rev=709318&r1=709317&r2=709318&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorServiceImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorServiceImpl.java Thu Oct 30 18:14:30 2008
@@ -18,13 +18,23 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Iterator;
 import java.util.Locale;
 import java.util.ResourceBundle;
 
+import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
 
 import org.apache.jetspeed.om.portlet.ContainerRuntimeOption;
 import org.apache.jetspeed.om.portlet.DisplayName;
@@ -38,6 +48,7 @@
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.om.portlet.PublicRenderParameter;
 import org.apache.jetspeed.om.portlet.SecurityConstraint;
+import org.apache.jetspeed.om.portlet.SecurityRole;
 import org.apache.jetspeed.om.portlet.SecurityRoleRef;
 import org.apache.jetspeed.om.portlet.Supports;
 import org.apache.jetspeed.om.portlet.UserAttribute;
@@ -55,6 +66,12 @@
 import org.apache.pluto.om.portlet.Description;
 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
 import org.apache.pluto.services.PortletAppDescriptorService;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 /**
  * Jetspeed Descriptor service for loading portlet applications in a Jetspeed format.
@@ -64,20 +81,66 @@
  */
 public class JetspeedDescriptorServiceImpl implements JetspeedDescriptorService
 {
+    private static class XPathNamespaceContext implements NamespaceContext
+    {
+        private String namespaceURI;
+        private String prefix;
+        
+        public XPathNamespaceContext(String prefix)
+        {
+            this(prefix,XMLConstants.XML_NS_URI);
+        }
+
+        public XPathNamespaceContext(String prefix, String namespaceURI)
+        {
+            this.prefix = prefix;
+            this.namespaceURI = namespaceURI;
+        }
+
+        public String getNamespaceURI(String prefix)
+        {
+            if (prefix == null)
+            {
+                throw new NullPointerException("Null prefix");
+            }
+            else if (this.prefix.equals(prefix))
+            {
+                return namespaceURI;
+            }
+            else if ("xml".equals(prefix))
+            {
+                return XMLConstants.XML_NS_URI;
+            }
+            return XMLConstants.NULL_NS_URI;
+        }
+
+        public String getPrefix(String namespaceURI)
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        @SuppressWarnings("unchecked")
+        public Iterator getPrefixes(String namespaceURI)
+        {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    private static final String NAMESPACE_PREFIX = "js";
+    
     private PortletAppDescriptorService plutoDescriptorService;
+    DocumentBuilderFactory domFactory;
     
     public JetspeedDescriptorServiceImpl(PortletAppDescriptorService plutoDescriptorService)
     {
         this.plutoDescriptorService = plutoDescriptorService;
     }
     
-    public PortletApplication read(InputStream webDescriptor, InputStream portletDescriptor, InputStream jetspeedPortletDescriptor) throws IOException
+    public PortletApplication read(InputStream webDescriptor, InputStream portletDescriptor, InputStream jetspeedPortletDescriptor) throws Exception
     {
-        // TODO: do web.xml loading here
         PortletApplicationDefinition pad = plutoDescriptorService.read(portletDescriptor);
-        // TODO 2.2: do web.xml merge descriptions/display-names/roles/locale-encoding-mapping-list elements
-        //           within the pa, see Portlet Spec 2.0, PLT.25.1
         PortletApplication pa = upgrade(pad);
+        loadWebDescriptor(pa, webDescriptor);
         if (jetspeedPortletDescriptor != null)
         {
             loadJetspeedPortletDescriptor(pa, jetspeedPortletDescriptor);
@@ -85,13 +148,159 @@
         return pa;
     }
 
+    protected void loadWebDescriptor(PortletApplication pa, InputStream webDescriptor) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException
+    {
+        if (domFactory == null)
+        {
+            domFactory = DocumentBuilderFactory.newInstance();
+            domFactory.setNamespaceAware(true);
+        }
+        DocumentBuilder builder = domFactory.newDocumentBuilder();
+        
+        builder.setEntityResolver(new EntityResolver()
+        {
+            public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException,
+                            java.io.IOException
+            {
+                if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
+                {
+                    return new InputSource(getClass().getResourceAsStream("web-app_2_3.dtd"));
+                }
+                return null;
+            }
+        });
+        
+        Document document = builder.parse(webDescriptor);
+        Element root = document.getDocumentElement();
+        String namespace = root.getNamespaceURI();
+
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        String prefix;
+        
+        if(namespace!= null && namespace.length() > 0)
+        {
+            prefix = NAMESPACE_PREFIX+":";
+            xpath.setNamespaceContext(new XPathNamespaceContext(NAMESPACE_PREFIX, namespace));
+        }
+        else
+        {
+            prefix = XMLConstants.DEFAULT_NS_PREFIX;
+            xpath.setNamespaceContext(new XPathNamespaceContext(XMLConstants.DEFAULT_NS_PREFIX));
+        }
+        
+        NodeList nodes;
+        Element element;
+        
+        // retrieve display-name entries
+        nodes = (NodeList)xpath.evaluate("/"+prefix+"web-app/"+prefix+"display-name", document, XPathConstants.NODESET);
+        if (nodes != null)
+        {
+            DisplayName d;
+            for (int i = 0, size = nodes.getLength(); i < size; i++)
+            {
+                element = (Element)nodes.item(i);
+                String lang = element.getAttributeNS(XMLConstants.XML_NS_URI, "lang");
+                if (lang == null)
+                {
+                    lang = "en";
+                }
+                d = pa.getDisplayName(JetspeedLocale.convertStringToLocale(lang));
+                if (d == null)
+                {
+                    d = pa.addDisplayName(lang);
+                }
+                // else: overwrite display-name with last found entry
+                
+                d.setDisplayName(element.getTextContent().trim());
+            }
+        }
+
+        // retrieve description entries
+        nodes = (NodeList)xpath.evaluate("/"+prefix+"web-app/"+prefix+"description", document, XPathConstants.NODESET);
+        if (nodes != null)
+        {
+            Description d;
+            for (int i = 0, size = nodes.getLength(); i < size; i++)
+            {
+                element = (Element)nodes.item(i);
+                String lang = element.getAttributeNS(XMLConstants.XML_NS_URI, "lang");
+                if (lang == null)
+                {
+                    lang = "en";
+                }
+                d = pa.getDescription(JetspeedLocale.convertStringToLocale(lang));
+                if (d == null)
+                {
+                    d = pa.addDescription(lang);
+                }
+                // else: overwrite description with last found entry
+                
+                d.setDescription(element.getTextContent().trim());
+            }
+        }
+        
+        // retrieve security-role
+        nodes = (NodeList)xpath.evaluate("/"+prefix+"web-app/"+prefix+"security-role", document, XPathConstants.NODESET);
+        if (nodes != null)
+        {
+            NodeList children;
+            String roleName;
+            SecurityRole r;
+            Description d;
+            for (int i = 0, nsize = nodes.getLength(); i < nsize; i++)
+            {
+                element = (Element)nodes.item(i);
+                children = element.getElementsByTagName("role-name");
+                if (children != null && children.getLength() != 0)
+                {
+                    roleName = children.item(0).getTextContent().trim();
+                    if (roleName.length() > 0)
+                    {
+                        r = null;
+                        for (SecurityRole sr : pa.getSecurityRoles())
+                        {
+                            if (sr.getName().equals(roleName))
+                            {
+                                r = sr;
+                                break;
+                            }
+                        }
+                        if (r == null)
+                        {
+                            r = pa.addSecurityRole(roleName);
+                        }
+                        // else: overwrite or merge existing descriptions with those of this last found entry
+                        
+                        children = element.getElementsByTagName("description");
+                        if (children != null)
+                        {
+                            for (int j = 0, csize = children.getLength(); j < csize; j++)
+                            {
+                                element = (Element)children.item(j);
+                                String lang = element.getAttributeNS(XMLConstants.XML_NS_URI, "lang");
+                                if (lang == null)
+                                {
+                                    lang = "en";
+                                }
+                                if (r.getDescription(JetspeedLocale.convertStringToLocale(lang)) == null)
+                                {
+                                    d = r.addDescription(lang);
+                                    d.setDescription(element.getTextContent());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        
+        // TODO 2.2: retrieve locale-encoding-mapping-list, see Portlet Spec 2.0, PLT.25.1
+    }
+    
     protected PortletApplication upgrade(PortletApplicationDefinition pa)
     {
         PortletApplication jpa = new PortletApplicationDefinitionImpl();
         jpa.setDefaultNamespace(pa.getDefaultNamespace());
-        //pa.setDescription(pad.get) // TODO: 2.2 should we get this from the web.xml (as well as <display-name> and <security-role>
-        // not upgradable: checksum, revision
-        jpa.setName(pa.getName());
         jpa.setResourceBundle(pa.getResourceBundle());
         jpa.setVersion(pa.getVersion());
         for (org.apache.pluto.om.portlet.PortletDefinition pd : pa.getPortlets())

Propchange: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/web-app_2_3.dtd
------------------------------------------------------------------------------
    cvs2svn:cvs-rev = 1.1

Propchange: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/descriptor/web-app_2_3.dtd
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorService.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorService.java?rev=709318&r1=709317&r2=709318&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorService.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/descriptor/JetspeedDescriptorService.java Thu Oct 30 18:14:30 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.jetspeed.descriptor;
 
-import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.jetspeed.om.portlet.PortletApplication;
@@ -33,7 +32,7 @@
      * Retrieve the PortletApp deployment descriptor
      * (portlet.xml).
      * @return Object representation of the descriptor.
-     * @throws IOException if an IO error occurs.
+     * @throws Exception if an loading or parsing error occurs.
      */
-    PortletApplication read(InputStream webDescriptor, InputStream portletDescriptor, InputStream jetspeedPortletDescriptor) throws IOException;
+    PortletApplication read(InputStream webDescriptor, InputStream portletDescriptor, InputStream jetspeedPortletDescriptor) throws Exception;
 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/om/portlet/PortletApplication.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/om/portlet/PortletApplication.java?rev=709318&r1=709317&r2=709318&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/om/portlet/PortletApplication.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/om/portlet/PortletApplication.java Thu Oct 30 18:14:30 2008
@@ -66,6 +66,7 @@
      * @return The type of portlet application.
      */
     int getApplicationType();
+    void setApplicationType(int type);
 
     /**
      * The checksum on the portlet XML from the last deployment



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