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 2006/11/23 14:12:57 UTC

svn commit: r478563 - in /portals/jetspeed-2/trunk/components: deploy-tool/src/java/org/apache/jetspeed/tools/deploy/ portal/src/java/org/apache/jetspeed/util/descriptor/

Author: ate
Date: Thu Nov 23 05:12:56 2006
New Revision: 478563

URL: http://svn.apache.org/viewvc?view=rev&rev=478563
Log:
Enhancement JS2-614: Jetspeed Deploy compliant with servlet spec 2.4
Patch provided by Nicolas Dutertry
See: http://issues.apache.org/jira/browse/JS2-614

Added:
    portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java   (with props)
    portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java   (with props)
    portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java   (with props)
Modified:
    portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
    portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java

Modified: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java?view=diff&rev=478563&r1=478562&r2=478563
==============================================================================
--- portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java (original)
+++ portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java Thu Nov 23 05:12:56 2006
@@ -45,30 +45,49 @@
 {
     public static void main(String[] args) throws Exception
     {
-        if (args.length < 2 || args.length > 3 || args.length == 3 && !(args[0].equalsIgnoreCase("-s")))
+        if (args.length < 2)
         {
-            System.out.println("Usage: java -jar jetspeed-deploy-tools-<version>.jar [-s] INPUT OUTPUT");
-            System.out.println("Options:");
-            System.out
-                            .println("  -s: stripLoggers - remove commons-logging[version].jar and/or log4j[version].jar from war");
-            System.out.println("                     (required when targetting application servers like JBoss)");
-
+            printUsage();
             System.exit(1);
             return;
         }
-        if ( args.length == 3 )
-        {
-            new JetspeedDeploy(args[1], args[2], true);
-        }
-        else
-        {
-            new JetspeedDeploy(args[0], args[1], false);
+        
+        boolean stripLoggers = false;
+        String version = null;
+        for(int i = 0; i < args.length-2; i++) {
+            String option = args[i];
+            if(option.equals("-s")) {
+                stripLoggers = true;
+            } else if(option.equals("-v") && i < args.length-3) {
+                version = args[i+1];
+                i++;
+            } else {
+                // invalid option
+                printUsage();
+                System.exit(1);
+                return;
+            }
         }
+        
+        new JetspeedDeploy(args[args.length-2], args[args.length-1], stripLoggers, version);
+    }
+    
+    private static void printUsage() {
+        System.out.println("Usage: java -jar jetspeed-deploy-tools-<version>.jar [options] INPUT OUTPUT");
+        System.out.println("Options:");
+        System.out.println("  -s: stripLoggers - remove commons-logging[version].jar and/or log4j[version].jar from war");
+        System.out.println("                     (required when targetting application servers like JBoss)");
+        System.out.println("  -v VERSION: force servlet specification version to handle web.xml");
+        System.out.println("                     (default will automatically determine version)");
     }
 
     private final byte[] buffer = new byte[4096];
 
-    public JetspeedDeploy(String inputName, String outputName, boolean stripLoggers) throws Exception
+    public JetspeedDeploy(String inputName, String outputName, boolean stripLoggers) throws Exception {
+        this(inputName, outputName, stripLoggers, null);
+    }
+    
+    public JetspeedDeploy(String inputName, String outputName, boolean stripLoggers, String forcedVersion) throws Exception
     {
         File tempFile = null;
         JarFile jin = null;
@@ -91,6 +110,7 @@
             Document webXml = null;
             Document portletXml = null;
             Document contextXml = null;
+            boolean taglibFound = false;
             ZipEntry src;
             InputStream source;
             Enumeration zipEntries = jin.entries();
@@ -116,6 +136,10 @@
                         System.out.println("Found META-INF/context.xml");
                         contextXml = parseXml(source);
                     }
+                    else if ("WEB-INF/tld/portlet.tld".equals(target))
+                    {
+                        taglibFound = true;
+                    }
                     else
                     {
                         if ( stripLoggers && target.endsWith(".jar") &&
@@ -141,9 +165,12 @@
             {
                 throw new IllegalArgumentException("WEB-INF/portlet.xml");
             }
-
-            JetspeedWebApplicationRewriter webRewriter = new JetspeedWebApplicationRewriter(webXml,
-                                                                                            portletApplicationName);
+            
+            JetspeedWebApplicationRewriterFactory webRewriterFactory = new JetspeedWebApplicationRewriterFactory();
+            JetspeedWebApplicationRewriter webRewriter = webRewriterFactory.getInstance(
+                    webXml,
+                    portletApplicationName,
+                    forcedVersion);
             webRewriter.processWebXML();
             JetspeedContextRewriter contextRewriter = new JetspeedContextRewriter(contextXml, portletApplicationName);
             contextRewriter.processContextXML();
@@ -153,7 +180,7 @@
             addFile("WEB-INF/portlet.xml", portletXml, jout);
             addFile("META-INF/context.xml", contextXml, jout);
 
-            if (webRewriter.isPortletTaglibAdded())
+            if (webRewriter.isPortletTaglibAdded() || !taglibFound)
             {
                 System.out.println("Attempting to add portlet.tld to war...");
                 InputStream is = this.getClass().getResourceAsStream("/org/apache/jetspeed/tools/deploy/portlet.tld");

Modified: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java?view=diff&rev=478563&r1=478562&r2=478563
==============================================================================
--- portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java (original)
+++ portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java Thu Nov 23 05:12:56 2006
@@ -18,8 +18,11 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
 import org.jdom.Parent;
 import org.jdom.xpath.XPath;
 
@@ -32,24 +35,15 @@
  * @version $Id: WebDescriptorUtilities.java,v 1.2 2004/05/12 22:25:04 taylor
  *                Exp $
  */
-public class JetspeedWebApplicationRewriter
+public abstract class JetspeedWebApplicationRewriter
 {
     public static final String JETSPEED_CONTAINER = "JetspeedContainer";
-    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\")]";
-    public static final String PORTLET_TAGLIB_XPATH = "/web-app/taglib/taglib-uri[contains(child::text(), \"http://java.sun.com/portlet\")]";
+    public static final String JETSPEED_SERVLET_CLASS = "org.apache.jetspeed.container.JetspeedContainerServlet";
+    public static final String JETSPEED_SERVLET_DISPLAY_NAME = "Jetspeed Container";
+    public static final String JETSPEED_SERVLET_DESCRIPTION = "MVC Servlet for Jetspeed Portlet Applications";
+    public static final String NAMESPACE_PREFIX = "js";
     protected static final String WEB_XML_PATH = "WEB-INF/web.xml";
 
-    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"};
-    
-    protected static final String[] ELEMENTS_BEFORE_TAGLIB_MAPPING = new String[]{"icon", "display-name",
-            "description", "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
-            "servlet-mapping", "session-config", "mime-mapping", "welcome-file-list", "error-page", "taglib"};
-      
     private Document document;
     private String portletApplication;
     private boolean changed = false;
@@ -87,9 +81,9 @@
         {
             Element root = document.getRootElement();
         
-            Object jetspeedServlet = XPath.selectSingleNode(document, JETSPEED_SERVLET_XPATH);
-            Object jetspeedServletMapping = XPath.selectSingleNode(document, JETSPEED_SERVLET_MAPPING_XPATH);
-            Object portletTaglib = XPath.selectSingleNode(document, PORTLET_TAGLIB_XPATH);
+            Object jetspeedServlet = getXPath(getJetspeedServletXPath()).selectSingleNode(document);
+            Object jetspeedServletMapping = getXPath(getJetspeedServletMappingXPath()).selectSingleNode(document);
+            Object portletTaglib = getXPath(getPortletTagLibXPath()).selectSingleNode(document);
             
             if (!document.hasRootElement())
             {
@@ -99,20 +93,7 @@
         
             if (jetspeedServlet == null)
             {
-                Element jetspeedServletElement = new Element("servlet");
-                Element servletName = (Element) new Element("servlet-name").addContent(JETSPEED_CONTAINER);
-                Element servletDspName = (Element) new Element("display-name").addContent("Jetspeed Container");
-                Element servletDesc = (Element) new Element("description")
-                        .addContent("MVC Servlet for Jetspeed Portlet Applications");
-                Element servletClass = (Element) new Element("servlet-class")
-                        .addContent("org.apache.jetspeed.container.JetspeedContainerServlet");
-                jetspeedServletElement.addContent(servletName);
-                jetspeedServletElement.addContent(servletDspName);
-                jetspeedServletElement.addContent(servletDesc);
-                jetspeedServletElement.addContent(servletClass);
-                insertContextNameParam(jetspeedServletElement);
-                insertLoadOnStartup(jetspeedServletElement);
-                insertElementCorrectly(root, jetspeedServletElement, ELEMENTS_BEFORE_SERVLET);
+                insertJetspeedServlet(root);
                 changed = true;
             }
             else
@@ -121,11 +102,11 @@
                 if (jetspeedServlet instanceof Element)
                 {
                     Parent jetspeedServletElement =((Element)jetspeedServlet).getParent();
-                    if (null == XPath.selectSingleNode(jetspeedServletElement, "init-param/param-name[contains(child::text(), \"contextName\")]"))
+                    if (null == getXPath("js:init-param/js:param-name[contains(child::text(), \"contextName\")]").selectSingleNode(jetspeedServletElement))
                     {
                       insertContextNameParam((Element)jetspeedServletElement);
                     }
-                    if (null == XPath.selectSingleNode(jetspeedServletElement, "load-on-startup"))
+                    if (null == getXPath("js:load-on-startup").selectSingleNode(jetspeedServletElement))
                     {
                         insertLoadOnStartup((Element) jetspeedServletElement);
                     }
@@ -134,29 +115,13 @@
     
             if (jetspeedServletMapping == null)
             {
-    
-                Element jetspeedServletMappingElement = new Element("servlet-mapping");
-    
-                Element servletMapName = (Element) new Element("servlet-name").addContent(JETSPEED_CONTAINER);
-                Element servletUrlPattern = (Element) new Element("url-pattern").addContent("/container/*");
-    
-                jetspeedServletMappingElement.addContent(servletMapName);
-                jetspeedServletMappingElement.addContent(servletUrlPattern);
-    
-                insertElementCorrectly(root, jetspeedServletMappingElement, ELEMENTS_BEFORE_SERVLET_MAPPING);
+                insertJetspeedServletMapping(root);
                 changed = true;
             }
             
             if(portletTaglib == null)
             {
-                Element taglib = new Element ("taglib");
-                Element taguri = (Element) new Element("taglib-uri").addContent("http://java.sun.com/portlet");
-                Element taglocation = (Element) new Element("taglib-location").addContent("/WEB-INF/tld/portlet.tld");
-                
-                taglib.addContent(taguri);
-                taglib.addContent(taglocation);
-                
-                insertElementCorrectly(root, taglib, ELEMENTS_BEFORE_TAGLIB_MAPPING);
+                insertPortletTagLib(root);
                 changed = true;
                 portletTaglibAdded = true;
             }
@@ -168,20 +133,22 @@
     
     }
     
-    private void insertContextNameParam(Element jetspeedServletElement)
+    protected void insertContextNameParam(Element jetspeedServletElement)
     {
-      Element param2Name = (Element) new Element("param-name").addContent("contextName");
-        Element param2Value = (Element) new Element("param-value").addContent(portletApplication); 
-        Element init2Param = new Element("init-param");
+        Namespace namespace = jetspeedServletElement.getNamespace();
+        Element param2Name = (Element) new Element("param-name", namespace).addContent("contextName");
+        Element param2Value = (Element) new Element("param-value", namespace).addContent(portletApplication); 
+        Element init2Param = new Element("init-param", namespace);
         init2Param.addContent(param2Name);
         init2Param.addContent(param2Value);
         jetspeedServletElement.addContent(init2Param);                    
         
     }
     
-    private void insertLoadOnStartup(Element jetspeedServletElement)
+    protected void insertLoadOnStartup(Element jetspeedServletElement)
     {
-        Element loadOnStartup = (Element) new Element("load-on-startup").addContent("0");
+        Namespace namespace = jetspeedServletElement.getNamespace();
+        Element loadOnStartup = (Element) new Element("load-on-startup", namespace).addContent("0");
         jetspeedServletElement.addContent(loadOnStartup);        
     }
     
@@ -236,7 +203,6 @@
         }
     }
     
-    
     /**
      * @return Returns the portletTaglibAdded.
      */
@@ -244,4 +210,74 @@
     {
         return portletTaglibAdded;
     }
+    
+    /**
+     * Returns the xpath containing the namespace prefix 'js' mapped to the document
+     * default namespace.
+     * 
+     * @param path
+     * @return XPath
+     * @throws JDOMException
+     */
+    protected XPath getXPath(String path) throws JDOMException
+    {
+        XPath xpath = XPath.newInstance(path);
+        Element root = document.getRootElement();
+        if(root != null)
+        {
+            if(StringUtils.isNotEmpty(root.getNamespaceURI()))
+            {
+                xpath.addNamespace(NAMESPACE_PREFIX, root.getNamespaceURI());
+            }
+        }
+        return xpath;
+    }
+    
+    /**
+     * Returns the jetspeed servlet xpath.
+     * The returned path must contain the namespace prefix 'js'.
+     * 
+     * @return jetspeed servlet xpath
+     */
+    protected abstract String getJetspeedServletXPath();
+    
+    /**
+     * Returns the jetspeed servlet mapping xpath.
+     * The returned path must contain the namespace prefix 'js'.
+     * 
+     * @return jetspeed servlet mapping xpath
+     */
+    protected abstract String getJetspeedServletMappingXPath();
+    
+    /**
+     * Returns the portlet taglib xpath.
+     * The returned path must contain the namespace prefix 'js'.
+     * 
+     * @return portlet taglib xpath
+     */
+    protected abstract String getPortletTagLibXPath();
+    
+    /**
+     * Inserts the jetspeed servlet into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected abstract void insertJetspeedServlet(Element root) throws Exception;
+    
+    /**
+     * Inserts the jetspeed servlet mapping into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected abstract void insertJetspeedServletMapping(Element root) throws Exception;
+    
+    /**
+     * Inserts the portlet taglib into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected abstract void insertPortletTagLib(Element root) throws Exception;
 }

Added: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java?view=auto&rev=478563
==============================================================================
--- portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java (added)
+++ portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java Thu Nov 23 05:12:56 2006
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.tools.deploy;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+/**
+ * Utilities for manipulating the web.xml deployment descriptor version 2.3
+ * 
+ * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver </a>
+ * @author <a href="mailto:mavery@einnovation.com">Matt Avery </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: WebDescriptorUtilities.java,v 1.2 2004/05/12 22:25:04 taylor
+ *                Exp $
+ */
+class JetspeedWebApplicationRewriter2_3 extends JetspeedWebApplicationRewriter
+{
+    public static final String JETSPEED_SERVLET_XPATH = "/js:web-app/js:servlet/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
+    public static final String JETSPEED_SERVLET_MAPPING_XPATH = "/js:web-app/js:servlet-mapping/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
+    public static final String PORTLET_TAGLIB_XPATH = "/js:web-app/js:taglib/js:taglib-uri[contains(child::text(), \"http://java.sun.com/portlet\")]";
+    
+    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"};
+    
+    protected static final String[] ELEMENTS_BEFORE_TAGLIB_MAPPING = new String[]{"icon", "display-name",
+            "description", "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
+            "servlet-mapping", "session-config", "mime-mapping", "welcome-file-list", "error-page", "taglib"};
+
+    
+    public JetspeedWebApplicationRewriter2_3(Document doc, String portletApplication)
+    {
+        super(doc, portletApplication);
+    }
+
+    public JetspeedWebApplicationRewriter2_3(Document doc)
+    {
+        super(doc);
+    }
+    
+    /**
+     * Returns the jetspeed servlet xpath.
+     * 
+     * @return jetspeed servlet xpath
+     */
+    protected String getJetspeedServletXPath()
+    {
+        return JETSPEED_SERVLET_XPATH;
+    }
+    
+    /**
+     * Returns the jetspeed servlet mapping xpath.
+     * 
+     * @return jetspeed servlet mapping xpath
+     */
+    protected String getJetspeedServletMappingXPath()
+    {
+        return JETSPEED_SERVLET_MAPPING_XPATH;
+    }
+
+    /**
+     * Returns the portlet taglib xpath.
+     * 
+     * @return portlet taglib xpath
+     */
+    protected String getPortletTagLibXPath()
+    {
+        return PORTLET_TAGLIB_XPATH;
+    }
+
+    /**
+     * Inserts the jetspeed servlet into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected void insertJetspeedServlet(Element root) throws Exception
+    {
+        Namespace namespace = root.getNamespace();
+        Element jetspeedServletElement = new Element("servlet", namespace);
+        Element servletName = (Element) new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
+        Element servletDspName = (Element) new Element("display-name", namespace).addContent(JETSPEED_SERVLET_DISPLAY_NAME);
+        Element servletDesc = (Element) new Element("description", namespace)
+                .addContent(JETSPEED_SERVLET_DESCRIPTION);
+        Element servletClass = (Element) new Element("servlet-class", namespace)
+                .addContent(JETSPEED_SERVLET_CLASS);
+        jetspeedServletElement.addContent(servletName);
+        jetspeedServletElement.addContent(servletDspName);
+        jetspeedServletElement.addContent(servletDesc);
+        jetspeedServletElement.addContent(servletClass);
+        insertContextNameParam(jetspeedServletElement);
+        insertLoadOnStartup(jetspeedServletElement);
+        insertElementCorrectly(root, jetspeedServletElement, ELEMENTS_BEFORE_SERVLET);
+    }
+
+    /**
+     * Inserts the jetspeed servlet mapping into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected void insertJetspeedServletMapping(Element root) throws Exception
+    {
+        Namespace namespace = root.getNamespace();
+        Element jetspeedServletMappingElement = new Element("servlet-mapping", namespace);
+        
+        Element servletMapName = (Element) new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
+        Element servletUrlPattern = (Element) new Element("url-pattern", namespace).addContent("/container/*");
+
+        jetspeedServletMappingElement.addContent(servletMapName);
+        jetspeedServletMappingElement.addContent(servletUrlPattern);
+
+        insertElementCorrectly(root, jetspeedServletMappingElement, ELEMENTS_BEFORE_SERVLET_MAPPING);
+    }
+
+    /**
+     * Inserts the portlet taglib into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected void insertPortletTagLib(Element root) throws Exception
+    {
+        Namespace namespace = root.getNamespace();
+        Element taglib = new Element ("taglib", namespace);
+        Element taguri = (Element) new Element("taglib-uri", namespace).addContent("http://java.sun.com/portlet");
+        Element taglocation = (Element) new Element("taglib-location", namespace).addContent("/WEB-INF/tld/portlet.tld");
+        
+        taglib.addContent(taguri);
+        taglib.addContent(taglocation);
+        
+        insertElementCorrectly(root, taglib, ELEMENTS_BEFORE_TAGLIB_MAPPING);
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java?view=auto&rev=478563
==============================================================================
--- portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java (added)
+++ portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java Thu Nov 23 05:12:56 2006
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.tools.deploy;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+/**
+ * Utilities for manipulating the web.xml deployment descriptor version 2.4
+ * 
+ * @author Nicolas Dutertry
+ */
+class JetspeedWebApplicationRewriter2_4 extends JetspeedWebApplicationRewriter
+{
+    public static final String JETSPEED_SERVLET_XPATH = "/js:web-app/js:servlet/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
+    public static final String JETSPEED_SERVLET_MAPPING_XPATH = "/js:web-app/js:servlet-mapping/js:servlet-name[contains(child::text(), \"JetspeedContainer\")]";
+    public static final String JSP_CONFIG_XPATH = "/js:web-app/js:jsp-config";
+    public static final String PORTLET_TAGLIB_XPATH = "/js:web-app/js:jsp-config/js:taglib/js:taglib-uri[contains(child::text(), \"http://java.sun.com/portlet\")]";
+    
+    protected static final String[] ELEMENTS_BEFORE_SERVLET = new String[]{"description", "display-name", "icon", 
+            "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet"};
+    protected static final String[] ELEMENTS_BEFORE_SERVLET_MAPPING = new String[]{"description", "display-name", "icon", 
+            "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
+            "servlet-mapping"};
+    
+    protected static final String[] ELEMENTS_BEFORE_JSP_CONFIG = new String[]{"description", "display-name", "icon", 
+        "distributable", "context-param", "filter", "filter-mapping", "listener", "servlet",
+        "servlet-mapping", "session-config", "mime-mapping", "welcome-file-list", "error-page", "jsp-config"};
+    
+    protected static final String[] ELEMENTS_BEFORE_TAGLIB_MAPPING = new String[]{"taglib"};
+      
+    public JetspeedWebApplicationRewriter2_4(Document doc, String portletApplication)
+    {
+        super(doc, portletApplication);
+    }
+
+    public JetspeedWebApplicationRewriter2_4(Document doc)
+    {
+        super(doc);
+    }
+    
+    /**
+     * Returns the jetspeed servlet xpath.
+     * 
+     * @return jetspeed servlet xpath
+     */
+    protected String getJetspeedServletXPath()
+    {
+        return JETSPEED_SERVLET_XPATH;
+    }
+    
+    /**
+     * Returns the jetspeed servlet mapping xpath.
+     * 
+     * @return jetspeed servlet mapping xpath
+     */
+    protected String getJetspeedServletMappingXPath()
+    {
+        return JETSPEED_SERVLET_MAPPING_XPATH;
+    }
+
+    /**
+     * Returns the portlet taglib xpath.
+     * 
+     * @return portlet taglib xpath
+     */
+    protected String getPortletTagLibXPath()
+    {
+        return PORTLET_TAGLIB_XPATH;
+    }
+
+    /**
+     * Inserts the jetspeed servlet into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected void insertJetspeedServlet(Element root) throws Exception
+    {
+        Namespace namespace = root.getNamespace();
+        Element jetspeedServletElement = new Element("servlet", namespace);
+        Element servletName = (Element) new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
+        Element servletDspName = (Element) new Element("display-name", namespace).addContent(JETSPEED_SERVLET_DISPLAY_NAME);
+        Element servletDesc = (Element) new Element("description", namespace)
+                .addContent(JETSPEED_SERVLET_DESCRIPTION);
+        Element servletClass = (Element) new Element("servlet-class", namespace)
+                .addContent(JETSPEED_SERVLET_CLASS);
+        // order is important 
+        jetspeedServletElement.addContent(servletDesc);
+        jetspeedServletElement.addContent(servletDspName);
+        jetspeedServletElement.addContent(servletName);
+        jetspeedServletElement.addContent(servletClass);
+        insertContextNameParam(jetspeedServletElement);
+        insertLoadOnStartup(jetspeedServletElement);
+        insertElementCorrectly(root, jetspeedServletElement, ELEMENTS_BEFORE_SERVLET);
+    }
+
+    /**
+     * Inserts the jetspeed servlet mapping into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected void insertJetspeedServletMapping(Element root) throws Exception
+    {
+        Namespace namespace = root.getNamespace();
+        Element jetspeedServletMappingElement = new Element("servlet-mapping", namespace);
+        
+        Element servletMapName = (Element) new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
+        Element servletUrlPattern = (Element) new Element("url-pattern", namespace).addContent("/container/*");
+
+        jetspeedServletMappingElement.addContent(servletMapName);
+        jetspeedServletMappingElement.addContent(servletUrlPattern);
+
+        insertElementCorrectly(root, jetspeedServletMappingElement, ELEMENTS_BEFORE_SERVLET_MAPPING);
+    }
+
+    /**
+     * Inserts the portlet taglib into web.xml
+     * 
+     * @param root
+     * @throws Exception
+     */
+    protected void insertPortletTagLib(Element root) throws Exception
+    {
+        Namespace namespace = root.getNamespace();
+        Element jspConfig = (Element)getXPath(JSP_CONFIG_XPATH).selectSingleNode(root.getDocument());
+        if(jspConfig == null)
+        {
+            jspConfig = new Element("jsp-config", namespace);
+            insertElementCorrectly(root, jspConfig, ELEMENTS_BEFORE_JSP_CONFIG);
+        }
+        Element taglib = new Element ("taglib", namespace);
+        Element taguri = (Element) new Element("taglib-uri", namespace).addContent("http://java.sun.com/portlet");
+        Element taglocation = (Element) new Element("taglib-location", namespace).addContent("/WEB-INF/tld/portlet.tld");
+        
+        taglib.addContent(taguri);
+        taglib.addContent(taglocation);
+        
+        insertElementCorrectly(jspConfig, taglib, ELEMENTS_BEFORE_TAGLIB_MAPPING);
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java?view=auto&rev=478563
==============================================================================
--- portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java (added)
+++ portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java Thu Nov 23 05:12:56 2006
@@ -0,0 +1,74 @@
+package org.apache.jetspeed.tools.deploy;
+
+import org.jdom.Document;
+
+/**
+ * @author Nicolas Dutertry
+ */
+public class JetspeedWebApplicationRewriterFactory {
+    
+    /** 
+     * Returns an instance of JetspeedWebApplicationRewriter.
+     * 
+     * @param doc
+     * @return JetspeedWebApplicationRewriter
+     * @throws Exception
+     */
+    public JetspeedWebApplicationRewriter getInstance(Document doc) throws Exception
+    {
+        return getInstance(doc, null, null);
+    }
+    
+    /** 
+     * Returns an instance of JetspeedWebApplicationRewriter.
+     * 
+     * @param doc
+     * @return JetspeedWebApplicationRewriter
+     * @throws Exception
+     */
+    public JetspeedWebApplicationRewriter getInstance(Document doc, String portletApplication) throws Exception
+    {
+        return getInstance(doc, portletApplication, null);
+    }
+    
+    /** 
+     * Returns an instance of JetspeedWebApplicationRewriter.
+     * 
+     * @param doc
+     * @param portletApplication
+     * @param forcedVersion
+     * @return JetspeedWebApplicationRewriter
+     * @throws Exception
+     */
+    public JetspeedWebApplicationRewriter getInstance(Document doc, String portletApplication, String forcedVersion) throws Exception
+    {
+        String version = forcedVersion;
+        if(version == null)
+        {
+            version = doc.getRootElement().getAttributeValue("version", "2.3");
+        }
+        
+        try
+        {
+            // Check version is a valid number
+            Double.parseDouble(version);
+        }
+        catch(NumberFormatException e)
+        {
+            throw new Exception("Unable to create JetspeedWebApplicationRewriter for version " + version, e);
+        }
+        
+        if(version.equals("2.3"))
+        {
+            return new JetspeedWebApplicationRewriter2_3(doc, portletApplication);
+        }
+        else if(version.compareTo("2.4") >= 0)
+        {
+            return new JetspeedWebApplicationRewriter2_4(doc, portletApplication);
+        }
+        else
+        {
+            throw new Exception("Unable to create JetspeedWebApplicationRewriter for version " + version);
+        }
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java?view=diff&rev=478563&r1=478562&r2=478563
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java Thu Nov 23 05:12:56 2006
@@ -44,6 +44,7 @@
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
 import org.apache.jetspeed.tools.deploy.JetspeedWebApplicationRewriter;
+import org.apache.jetspeed.tools.deploy.JetspeedWebApplicationRewriterFactory;
 import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
 import org.apache.jetspeed.util.DirectoryHelper;
 import org.apache.jetspeed.util.FileSystemHelper;
@@ -572,8 +573,8 @@
                 webXmlIn.close();
             }
 
-
-            JetspeedWebApplicationRewriter rewriter = new JetspeedWebApplicationRewriter(doc);
+            JetspeedWebApplicationRewriterFactory rewriterFactory = new JetspeedWebApplicationRewriterFactory();
+            JetspeedWebApplicationRewriter rewriter = rewriterFactory.getInstance(doc);
             rewriter.processWebXML();
             
             if (rewriter.isChanged())



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