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/16 20:05:43 UTC

svn commit: r705301 - in /portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools: ./ src/main/java/org/apache/jetspeed/tools/deploy/

Author: ate
Date: Thu Oct 16 11:05:42 2008
New Revision: 705301

URL: http://svn.apache.org/viewvc?rev=705301&view=rev
Log:
Replacing jdom/jaxen based XPath usage with standard Java 1.5 XPath solution

Modified:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/pom.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedContextRewriter.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/pom.xml?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/pom.xml Thu Oct 16 11:05:42 2008
@@ -43,22 +43,6 @@
       <artifactId>jetspeed-api</artifactId>
       <scope>provided</scope>
     </dependency>
-    <dependency>
-      <groupId>jdom</groupId>
-      <artifactId>jdom</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>commons-lang</groupId>
-      <artifactId>commons-lang</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>jaxen</groupId>
-      <artifactId>jaxen</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>saxpath</groupId>
-      <artifactId>saxpath</artifactId>
-    </dependency>
 
   </dependencies>
 

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedContextRewriter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedContextRewriter.java?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedContextRewriter.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedContextRewriter.java Thu Oct 16 11:05:42 2008
@@ -16,8 +16,8 @@
  */
 package org.apache.jetspeed.tools.deploy;
 
-import org.jdom.Document;
-import org.jdom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * Utilities for manipulating the context.xml deployment descriptor
@@ -44,26 +44,26 @@
             {
                 // get root Context
                 Element root = null;
-                if (!document.hasRootElement())
+                if (!document.hasChildNodes())
                 {
-                    root = new Element("Context");
-                    document.setRootElement(root);
+                    root = document.createElement("Context");
+                    document.appendChild(root);
                 }
                 else
                 {
-                    root = document.getRootElement();
+                    root = document.getDocumentElement();
                 }   
                 
                 // set Context path
-                String pathAttribute = root.getAttributeValue("path");
-                if ((pathAttribute == null) || !pathAttribute.equals("/" + portletApplication))
+                String pathAttribute = root.getAttribute("path");
+                if ((pathAttribute.equals("")) || !pathAttribute.equals("/" + portletApplication))
                 {
                     root.setAttribute("path", "/" + portletApplication);
                 }
                 
                 // set Context docBase
-                String docBaseAttribute = root.getAttributeValue("docBase");
-                if ((docBaseAttribute == null) || !docBaseAttribute.equals(portletApplication))
+                String docBaseAttribute = root.getAttribute("docBase");
+                if ((docBaseAttribute.equals("")) || !docBaseAttribute.equals(portletApplication))
                 {
                     root.setAttribute("docBase", portletApplication);
                 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java Thu Oct 16 11:05:42 2008
@@ -27,10 +27,17 @@
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 
-import org.jdom.Document;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -181,7 +188,7 @@
             addFile("WEB-INF/web.xml", webXml, jout);
             addFile("WEB-INF/portlet.xml", portletXml, jout);
             addFile("META-INF/context.xml", contextXml, jout);
-
+            
             if (!taglibFound)
             {
                 System.out.println("Attempting to add portlet.tld to war...");
@@ -282,10 +289,10 @@
 
     protected Document parseXml(InputStream source) throws Exception
     {
-        // Parse using the local dtds instead of remote dtds. This
-        // allows to deploy the application offline
-        SAXBuilder saxBuilder = new SAXBuilder();
-        saxBuilder.setEntityResolver(new EntityResolver()
+        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+        domFactory.setNamespaceAware(true); // never forget this!
+        DocumentBuilder builder = domFactory.newDocumentBuilder();
+        builder.setEntityResolver(new EntityResolver()
         {
             public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException,
                             java.io.IOException
@@ -297,7 +304,7 @@
                 return null;
             }
         });
-        Document document = saxBuilder.build(source);
+        Document document = builder.parse(source);
         return document;
     }
 
@@ -327,11 +334,30 @@
     {
         if (source != null)
         {
-            jos.putNextEntry(new ZipEntry(path));
-            XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
             try
             {
-                xmlOutputter.output(source, jos);
+                jos.putNextEntry(new ZipEntry(path));
+                DOMSource domSource = new DOMSource(source);
+                StreamResult streamResult = new StreamResult(jos);
+                TransformerFactory tf = TransformerFactory.newInstance();
+                Transformer transformer = tf.newTransformer();
+                transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+                if (source.getDoctype() != null)
+                {
+                    transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, source.getDoctype().getPublicId());
+                    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, source.getDoctype().getSystemId());
+                }
+                transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");
+                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+                transformer.transform(domSource, streamResult);
+            }
+            catch (TransformerConfigurationException e)
+            {
+                throw new IOException(e.getMessage());
+            }
+            catch (TransformerException e)
+            {
+                throw new IOException(e.getMessage());
             }
             finally
             {

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java Thu Oct 16 11:05:42 2008
@@ -17,15 +17,20 @@
 package org.apache.jetspeed.tools.deploy;
 
 import java.util.Arrays;
+import java.util.Iterator;
 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;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 
 /**
  * Utilities for manipulating the web.xml deployment descriptor
@@ -38,6 +43,51 @@
  */
 public abstract class JetspeedWebApplicationRewriter
 {
+    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();
+        }
+    }
+    
     public static final String JETSPEED_CONTAINER = "JetspeedContainer";
     public static final String JETSPEED_SERVLET_CLASS = "org.apache.jetspeed.container.JetspeedContainerServlet";
     public static final String JETSPEED_SERVLET_DISPLAY_NAME = "Jetspeed Container";
@@ -46,19 +96,38 @@
     protected static final String WEB_XML_PATH = "WEB-INF/web.xml";
 
     private Document document;
+    private String namespace;
+    private String prefix;
+    private Element  root;
     private String portletApplication;
     private boolean changed = false;
     private boolean portletTaglibAdded = false;
+    private XPath xpath;
+
+    
     
     public JetspeedWebApplicationRewriter(Document doc, String portletApplication)
     {
-            this.document = doc;
-            this.portletApplication = portletApplication;
+        this(doc);
+        this.portletApplication = portletApplication;
     }
 
     public JetspeedWebApplicationRewriter(Document doc)
     {
-            this.document = doc;
+        this.document = doc;
+        this.root = doc.getDocumentElement();
+        this.namespace = root.getNamespaceURI();
+        xpath = XPathFactory.newInstance().newXPath();
+        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));
+        }
     }
     
     /**
@@ -80,16 +149,15 @@
     {
         try
         {
-            Element root = document.getRootElement();
-        
-            Object jetspeedServlet = getXPath(getJetspeedServletXPath()).selectSingleNode(document);
-            Object jetspeedServletMapping = getXPath(getJetspeedServletMappingXPath()).selectSingleNode(document);
-            Object portletTaglib = getXPath(getPortletTagLibXPath()).selectSingleNode(document);
+            Element root = document.getDocumentElement();
+            Object jetspeedServlet =xpath.evaluate(getJetspeedServletXPath(), document, XPathConstants.NODE);
+            Object jetspeedServletMapping = xpath.evaluate(getJetspeedServletMappingXPath(), document, XPathConstants.NODE);
+            Object portletTaglib = xpath.evaluate(getPortletTagLibXPath(), document, XPathConstants.NODE);
             
-            if (!document.hasRootElement())
+            if (!document.hasChildNodes())
             {
-                root = new Element("web-app");
-                document.setRootElement(root);
+                root = document.createElement("web-app");
+                document.appendChild(root);
             }
         
             if (jetspeedServlet == null)
@@ -102,12 +170,12 @@
                 // double check for register at Init
                 if (jetspeedServlet instanceof Element)
                 {
-                    Parent jetspeedServletElement =((Element)jetspeedServlet).getParent();
-                    if (null == getXPath("js:init-param/js:param-name[contains(child::text(), \"contextName\")]").selectSingleNode(jetspeedServletElement))
+                    Element jetspeedServletElement = (Element)((Element)jetspeedServlet).getParentNode();
+                    if (null == xpath.evaluate(prefix+"init-param/"+prefix+"param-name[contains(child::text(), \"contextName\")]",jetspeedServletElement, XPathConstants.NODE))
                     {
                       insertContextNameParam((Element)jetspeedServletElement);
                     }
-                    if (null == getXPath("js:load-on-startup").selectSingleNode(jetspeedServletElement))
+                    if (null == xpath.evaluate(prefix+"load-on-startup", jetspeedServletElement, XPathConstants.NODE))
                     {
                         insertLoadOnStartup((Element) jetspeedServletElement);
                     }
@@ -136,21 +204,23 @@
     
     protected void insertContextNameParam(Element jetspeedServletElement)
     {
-        Namespace namespace = jetspeedServletElement.getNamespace();
-        Element param2Name = new Element("param-name", namespace).addContent("contextName");
-        Element param2Value = new Element("param-value", namespace).addContent(portletApplication); 
-        Element init2Param = new Element("init-param", namespace);
-        init2Param.addContent(param2Name);
-        init2Param.addContent(param2Value);
-        jetspeedServletElement.addContent(init2Param);                    
-        
+        String namespace = jetspeedServletElement.getNamespaceURI();
+        Element init2Param = jetspeedServletElement.getOwnerDocument().createElementNS(namespace, "init-param");        
+        jetspeedServletElement.appendChild(init2Param);                    
+        Element param2Name = jetspeedServletElement.getOwnerDocument().createElementNS(namespace, "param-name");
+        param2Name.setTextContent("contextName");
+        Element param2Value = jetspeedServletElement.getOwnerDocument().createElementNS(namespace, "param-value");
+        param2Value.setTextContent(portletApplication);
+        init2Param.appendChild(param2Name);
+        init2Param.appendChild(param2Value);        
     }
     
     protected void insertLoadOnStartup(Element jetspeedServletElement)
     {
-        Namespace namespace = jetspeedServletElement.getNamespace();
-        Element loadOnStartup = new Element("load-on-startup", namespace).addContent("0");
-        jetspeedServletElement.addContent(loadOnStartup);        
+        String namespace = jetspeedServletElement.getNamespaceURI();
+        Element loadOnStartup = jetspeedServletElement.getOwnerDocument().createElementNS(namespace, "load-on-startup");
+        loadOnStartup.setTextContent("0");
+        jetspeedServletElement.appendChild(loadOnStartup);        
     }
     
     public boolean isChanged()
@@ -165,45 +235,53 @@
      * </p>
      * 
      * @param root
-     *            JDom element representing the &lt; web-app &gt;
+     *            element representing the &lt; web-app &gt;
      * @param toInsert
-     *            JDom element to insert into the web.xml hierarchy.
+     *            element to insert into the web.xml hierarchy.
      * @param elementsBefore
      *            an array of web.xml elements that should be defined before the
      *            element we want to insert. This order should be the order
-     *            defined by the web.xml's DTD type definition.
+     *            defined by the web.xml's DTD or XSD type definition.
      */
     protected void insertElementCorrectly( Element root, Element toInsert, String[] elementsBefore )
-    throws Exception
     {
-        List allChildren = root.getChildren();
-        List elementsBeforeList = Arrays.asList(elementsBefore);
-        toInsert.detach();
-        int insertAfter = 0;
-        int count = 0;
-        for (int i = 0; i < allChildren.size(); i++)
+        NodeList allChildren = root.getChildNodes();
+        List<String> elementsBeforeList = Arrays.asList(elementsBefore);
+        Node insertBefore = null;
+        for (int i = 0; i < allChildren.getLength(); i++)
         {
-            Element element = (Element) allChildren.get(i);
-            if (elementsBeforeList.contains(element.getName()))
+            Node node = allChildren.item(i);
+            if (insertBefore == null)
+            {
+                insertBefore = node;
+            }
+            if (node.getNodeType() == Node.ELEMENT_NODE)
             {
-                // determine the Content index of the element to insert after
-                insertAfter = root.indexOf(element);
+                if (elementsBeforeList.contains(node.getNodeName()))
+                {
+                    insertBefore = null;
+                }
+                else
+                {
+                    break;
+                }
             }
-            count++;
         }
-    
-        insertAfter = (count == 0) ? 0 : insertAfter + 1;
-        
-        try
+        if (insertBefore == null)
         {
-            root.addContent(insertAfter, toInsert);
+            root.appendChild(toInsert);
         }
-        catch (ArrayIndexOutOfBoundsException e)
+        else
         {
-            root.addContent(toInsert);
+            root.insertBefore(toInsert, insertBefore);
         }
     }
     
+    protected String getNamespacePrefix()
+    {
+        return prefix;
+    }
+    
     /**
      * @return Returns the portletTaglibAdded.
      */
@@ -212,31 +290,14 @@
         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
+    protected XPath getXPath()
     {
-        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'.
+     * The returned path must contain the namespace prefix.
      * 
      * @return jetspeed servlet xpath
      */
@@ -244,7 +305,7 @@
     
     /**
      * Returns the jetspeed servlet mapping xpath.
-     * The returned path must contain the namespace prefix 'js'.
+     * The returned path must contain the namespace prefix.
      * 
      * @return jetspeed servlet mapping xpath
      */
@@ -252,7 +313,7 @@
     
     /**
      * Returns the portlet taglib xpath.
-     * The returned path must contain the namespace prefix 'js'.
+     * The returned path must contain the namespace prefix.
      * 
      * @return portlet taglib xpath
      */

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_3.java Thu Oct 16 11:05:42 2008
@@ -16,9 +16,8 @@
  */
 package org.apache.jetspeed.tools.deploy;
 
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.Namespace;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * Utilities for manipulating the web.xml deployment descriptor version 2.3
@@ -63,7 +62,7 @@
      */
     protected String getJetspeedServletXPath()
     {
-        return JETSPEED_SERVLET_XPATH;
+        return JETSPEED_SERVLET_XPATH.replace("js:", getNamespacePrefix());
     }
     
     /**
@@ -73,7 +72,7 @@
      */
     protected String getJetspeedServletMappingXPath()
     {
-        return JETSPEED_SERVLET_MAPPING_XPATH;
+        return JETSPEED_SERVLET_MAPPING_XPATH.replace("js:", getNamespacePrefix());
     }
 
     /**
@@ -83,7 +82,7 @@
      */
     protected String getPortletTagLibXPath()
     {
-        return PORTLET_TAGLIB_XPATH;
+        return PORTLET_TAGLIB_XPATH.replace("js:", getNamespacePrefix());
     }
 
     /**
@@ -94,18 +93,20 @@
      */
     protected void insertJetspeedServlet(Element root) throws Exception
     {
-        Namespace namespace = root.getNamespace();
-        Element jetspeedServletElement = new Element("servlet", namespace);
-        Element servletName = new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
-        Element servletDspName = new Element("display-name", namespace).addContent(JETSPEED_SERVLET_DISPLAY_NAME);
-        Element servletDesc = new Element("description", namespace)
-                .addContent(JETSPEED_SERVLET_DESCRIPTION);
-        Element servletClass = new Element("servlet-class", namespace)
-                .addContent(JETSPEED_SERVLET_CLASS);
-        jetspeedServletElement.addContent(servletName);
-        jetspeedServletElement.addContent(servletDspName);
-        jetspeedServletElement.addContent(servletDesc);
-        jetspeedServletElement.addContent(servletClass);
+        String namespace = root.getNamespaceURI();
+        Element jetspeedServletElement = root.getOwnerDocument().createElementNS(namespace, "servlet");
+        Element servletName = root.getOwnerDocument().createElementNS(namespace, "servlet-name");
+        servletName.setTextContent(JETSPEED_CONTAINER);
+        Element servletDspName = root.getOwnerDocument().createElementNS(namespace, "display-name");
+        servletDspName.setTextContent(JETSPEED_SERVLET_DISPLAY_NAME);
+        Element servletDesc = root.getOwnerDocument().createElementNS(namespace, "description");
+        servletDesc.setTextContent(JETSPEED_SERVLET_DESCRIPTION);
+        Element servletClass = root.getOwnerDocument().createElementNS(namespace, "servlet-class");
+        servletClass.setTextContent(JETSPEED_SERVLET_CLASS);
+        jetspeedServletElement.appendChild(servletName);
+        jetspeedServletElement.appendChild(servletDspName);
+        jetspeedServletElement.appendChild(servletDesc);
+        jetspeedServletElement.appendChild(servletClass);
         insertContextNameParam(jetspeedServletElement);
         insertLoadOnStartup(jetspeedServletElement);
         insertElementCorrectly(root, jetspeedServletElement, ELEMENTS_BEFORE_SERVLET);
@@ -119,14 +120,16 @@
      */
     protected void insertJetspeedServletMapping(Element root) throws Exception
     {
-        Namespace namespace = root.getNamespace();
-        Element jetspeedServletMappingElement = new Element("servlet-mapping", namespace);
+        String namespace = root.getNamespaceURI();
+        Element jetspeedServletMappingElement = root.getOwnerDocument().createElementNS(namespace, "servlet-mapping");
         
-        Element servletMapName = new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
-        Element servletUrlPattern = new Element("url-pattern", namespace).addContent("/container/*");
+        Element servletMapName = root.getOwnerDocument().createElementNS(namespace, "servlet-name");
+        servletMapName.setTextContent(JETSPEED_CONTAINER);
+        Element servletUrlPattern = root.getOwnerDocument().createElementNS(namespace, "url-pattern");
+        servletUrlPattern.setTextContent("/container/*");
 
-        jetspeedServletMappingElement.addContent(servletMapName);
-        jetspeedServletMappingElement.addContent(servletUrlPattern);
+        jetspeedServletMappingElement.appendChild(servletMapName);
+        jetspeedServletMappingElement.appendChild(servletUrlPattern);
 
         insertElementCorrectly(root, jetspeedServletMappingElement, ELEMENTS_BEFORE_SERVLET_MAPPING);
     }
@@ -139,13 +142,15 @@
      */
     protected void insertPortletTagLib(Element root) throws Exception
     {
-        Namespace namespace = root.getNamespace();
-        Element taglib = new Element ("taglib", namespace);
-        Element taguri = new Element("taglib-uri", namespace).addContent("http://java.sun.com/portlet");
-        Element taglocation = new Element("taglib-location", namespace).addContent("/WEB-INF/tld/portlet.tld");
+        String namespace = root.getNamespaceURI();
+        Element taglib = root.getOwnerDocument().createElementNS(namespace, "taglib");
+        Element taguri = root.getOwnerDocument().createElementNS(namespace, "taglib-uri");
+        taguri.setTextContent("http://java.sun.com/portlet");
+        Element taglocation = root.getOwnerDocument().createElementNS(namespace, "taglib-location");
+        taglocation.setTextContent("/WEB-INF/tld/portlet.tld");
         
-        taglib.addContent(taguri);
-        taglib.addContent(taglocation);
+        taglib.appendChild(taguri);
+        taglib.appendChild(taglocation);
         
         insertElementCorrectly(root, taglib, ELEMENTS_BEFORE_TAGLIB_MAPPING);
     }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter2_4.java Thu Oct 16 11:05:42 2008
@@ -16,9 +16,10 @@
  */
 package org.apache.jetspeed.tools.deploy;
 
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.Namespace;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * Utilities for manipulating the web.xml deployment descriptor version 2.4
@@ -62,7 +63,7 @@
      */
     protected String getJetspeedServletXPath()
     {
-        return JETSPEED_SERVLET_XPATH;
+        return JETSPEED_SERVLET_XPATH.replace("js:", getNamespacePrefix());
     }
     
     /**
@@ -72,7 +73,7 @@
      */
     protected String getJetspeedServletMappingXPath()
     {
-        return JETSPEED_SERVLET_MAPPING_XPATH;
+        return JETSPEED_SERVLET_MAPPING_XPATH.replace("js:", getNamespacePrefix());
     }
 
     /**
@@ -82,7 +83,7 @@
      */
     protected String getPortletTagLibXPath()
     {
-        return PORTLET_TAGLIB_XPATH;
+        return PORTLET_TAGLIB_XPATH.replace("js:", getNamespacePrefix());
     }
 
     /**
@@ -93,19 +94,20 @@
      */
     protected void insertJetspeedServlet(Element root) throws Exception
     {
-        Namespace namespace = root.getNamespace();
-        Element jetspeedServletElement = new Element("servlet", namespace);
-        Element servletName = new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
-        Element servletDspName = new Element("display-name", namespace).addContent(JETSPEED_SERVLET_DISPLAY_NAME);
-        Element servletDesc = new Element("description", namespace)
-                .addContent(JETSPEED_SERVLET_DESCRIPTION);
-        Element servletClass = new Element("servlet-class", namespace)
-                .addContent(JETSPEED_SERVLET_CLASS);
-        // order is important 
-        jetspeedServletElement.addContent(servletDesc);
-        jetspeedServletElement.addContent(servletDspName);
-        jetspeedServletElement.addContent(servletName);
-        jetspeedServletElement.addContent(servletClass);
+        String namespace = root.getNamespaceURI();
+        Element jetspeedServletElement = root.getOwnerDocument().createElementNS(namespace, "servlet");
+        Element servletName = root.getOwnerDocument().createElementNS(namespace, "servlet-name");
+        servletName.setTextContent(JETSPEED_CONTAINER);
+        Element servletDspName = root.getOwnerDocument().createElementNS(namespace, "display-name");
+        servletDspName.setTextContent(JETSPEED_SERVLET_DISPLAY_NAME);
+        Element servletDesc = root.getOwnerDocument().createElementNS(namespace, "description");
+        servletDesc.setTextContent(JETSPEED_SERVLET_DESCRIPTION);
+        Element servletClass = root.getOwnerDocument().createElementNS(namespace, "servlet-class");
+        servletClass.setTextContent(JETSPEED_SERVLET_CLASS);
+        jetspeedServletElement.appendChild(servletName);
+        jetspeedServletElement.appendChild(servletDspName);
+        jetspeedServletElement.appendChild(servletDesc);
+        jetspeedServletElement.appendChild(servletClass);
         insertContextNameParam(jetspeedServletElement);
         insertLoadOnStartup(jetspeedServletElement);
         insertElementCorrectly(root, jetspeedServletElement, ELEMENTS_BEFORE_SERVLET);
@@ -119,14 +121,16 @@
      */
     protected void insertJetspeedServletMapping(Element root) throws Exception
     {
-        Namespace namespace = root.getNamespace();
-        Element jetspeedServletMappingElement = new Element("servlet-mapping", namespace);
+        String namespace = root.getNamespaceURI();
+        Element jetspeedServletMappingElement = root.getOwnerDocument().createElementNS(namespace, "servlet-mapping");
         
-        Element servletMapName = new Element("servlet-name", namespace).addContent(JETSPEED_CONTAINER);
-        Element servletUrlPattern = new Element("url-pattern", namespace).addContent("/container/*");
+        Element servletMapName = root.getOwnerDocument().createElementNS(namespace, "servlet-name");
+        servletMapName.setTextContent(JETSPEED_CONTAINER);
+        Element servletUrlPattern = root.getOwnerDocument().createElementNS(namespace, "url-pattern");
+        servletUrlPattern.setTextContent("/container/*");
 
-        jetspeedServletMappingElement.addContent(servletMapName);
-        jetspeedServletMappingElement.addContent(servletUrlPattern);
+        jetspeedServletMappingElement.appendChild(servletMapName);
+        jetspeedServletMappingElement.appendChild(servletUrlPattern);
 
         insertElementCorrectly(root, jetspeedServletMappingElement, ELEMENTS_BEFORE_SERVLET_MAPPING);
     }
@@ -139,19 +143,21 @@
      */
     protected void insertPortletTagLib(Element root) throws Exception
     {
-        Namespace namespace = root.getNamespace();
-        Element jspConfig = (Element)getXPath(JSP_CONFIG_XPATH).selectSingleNode(root.getDocument());
-        if(jspConfig == null)
+        String namespace = root.getNamespaceURI();
+        Element jspConfig = (Element)getXPath().evaluate(JSP_CONFIG_XPATH, root.getOwnerDocument(), XPathConstants.NODE);
+        if (jspConfig == null)
         {
-            jspConfig = new Element("jsp-config", namespace);
+            jspConfig = root.getOwnerDocument().createElementNS(namespace,"jsp-config");
             insertElementCorrectly(root, jspConfig, ELEMENTS_BEFORE_JSP_CONFIG);
         }
-        Element taglib = new Element ("taglib", namespace);
-        Element taguri = new Element("taglib-uri", namespace).addContent("http://java.sun.com/portlet");
-        Element taglocation = new Element("taglib-location", namespace).addContent("/WEB-INF/tld/portlet.tld");
+        Element taglib = root.getOwnerDocument().createElementNS(namespace, "taglib");
+        Element taguri = root.getOwnerDocument().createElementNS(namespace, "taglib-uri");
+        taguri.setTextContent("http://java.sun.com/portlet");
+        Element taglocation = root.getOwnerDocument().createElementNS(namespace, "taglib-location");
+        taglocation.setTextContent("/WEB-INF/tld/portlet.tld");
         
-        taglib.addContent(taguri);
-        taglib.addContent(taglocation);
+        taglib.appendChild(taguri);
+        taglib.appendChild(taglocation);
         
         insertElementCorrectly(jspConfig, taglib, ELEMENTS_BEFORE_TAGLIB_MAPPING);
     }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java?rev=705301&r1=705300&r2=705301&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriterFactory.java Thu Oct 16 11:05:42 2008
@@ -16,7 +16,9 @@
 */
 package org.apache.jetspeed.tools.deploy;
 
-import org.jdom.Document;
+import org.w3c.dom.Document;
+
+//import org.jdom.Document;
 
 /**
  * @author Nicolas Dutertry
@@ -62,7 +64,11 @@
         String version = forcedVersion;
         if(version == null)
         {
-            version = doc.getRootElement().getAttributeValue("version", "2.3");
+            version = doc.getDocumentElement().getAttribute("version");
+            if (version.equals(""))
+            {
+                version = "2.3";
+            }
         }
         
         try



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