portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r707513 - /portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/deployment/impl/JettyDeployPortletAppEventListener.java
Date Fri, 24 Oct 2008 00:24:56 GMT
Author: ate
Date: Thu Oct 23 17:24:56 2008
New Revision: 707513

URL: http://svn.apache.org/viewvc?rev=707513&view=rev
Log:
JS2-871 - Upgrade Pluto container to version 2.0
See:  http://issues.apache.org/jira/browse/JS2-871
- replacing jdom with standard xml handling

Modified:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/deployment/impl/JettyDeployPortletAppEventListener.java

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/deployment/impl/JettyDeployPortletAppEventListener.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/deployment/impl/JettyDeployPortletAppEventListener.java?rev=707513&r1=707512&r2=707513&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/deployment/impl/JettyDeployPortletAppEventListener.java
(original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/deployment/impl/JettyDeployPortletAppEventListener.java
Thu Oct 23 17:24:56 2008
@@ -23,21 +23,26 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Enumeration;
-import java.util.Iterator;
+import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
+
+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.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.deployment.DeploymentEvent;
 import org.apache.jetspeed.deployment.DeploymentException;
 import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
-import org.jdom.Attribute;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
+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;
@@ -160,7 +165,7 @@
         return null;
     }
     
-    protected Document getCurrentJettyContext(File contextFile) throws IOException
+    protected Document getCurrentJettyContext(File contextFile) throws Exception
     {
         InputStream source = null;
         try
@@ -184,7 +189,7 @@
         }
     }
     
-    protected Document getJettyContextTemplate() throws IOException
+    protected Document getJettyContextTemplate() throws Exception
     {
         InputStream source = null;
         try
@@ -208,7 +213,7 @@
         }
     }
     
-    protected Document getJettyContext(String fileName) throws IOException
+    protected Document getJettyContext(String fileName) throws Exception
     {
         JarFile jin = null;
         InputStream source = null;
@@ -216,11 +221,11 @@
         {
             jin = new JarFile(fileName);
             
-            ZipEntry src;
-            Enumeration zipEntries = jin.entries();
-            while (zipEntries.hasMoreElements())
+            JarEntry src;
+            Enumeration<JarEntry> jarEntries = jin.entries();
+            while (jarEntries.hasMoreElements())
             {
-                src = (ZipEntry) zipEntries.nextElement();
+                src = jarEntries.nextElement();
                 String target = src.getName();
                 if ("META-INF/jetspeed-jetty-context.xml".equals(target))
                 {
@@ -261,28 +266,29 @@
     
     protected void updateJettyContext(String contextName, String warPath, Document context)
     {
-        Element root = context.getRootElement();
-        Iterator iter = root.getChildren("Set").iterator();
+        Element root = context.getDocumentElement();
+        NodeList sets = root.getElementsByTagName("Set");
         boolean foundSetWar = false;
         boolean foundSetContextPath = false;
         boolean foundSetConfigurationClasses = false;
         
-        while (iter.hasNext())
+        
+        for (int i = 0, size = sets.getLength(); i < size; i++)
         {
-            Element set = (Element)iter.next();
-            String name = set.getAttribute("name").getPortletName();
+            Element set = (Element)sets.item(i);
+            String name = set.getAttribute("name");
             if (name.equals("contextPath"))
             {
-                set.setText("/"+contextName);
+                set.setTextContent("/"+contextName);
                 foundSetContextPath = true;
             }
             else if (name.equals("resourceBase"))
             {
-                iter.remove();
+                root.removeChild(set);
             }
             else if (name.equals("war"))
             {
-                set.setText(warPath);
+                set.setTextContent(warPath);
                 foundSetWar = true;
             }
             else if (name.equals("configurationClasses"))
@@ -292,21 +298,49 @@
         }        
         if (!foundSetContextPath)
         {
-            root.addContent(new Element("Set").setAttribute(new Attribute("name", "contextPath")).setText("/"+contextName));
+            Element set = context.createElement("Set");
+            set.setAttribute("name", "contextPath");
+            set.setTextContent("/"+contextName);
+            root.appendChild(set);
         }
         if (!foundSetWar)
         {
-            root.addContent(new Element("Set").setAttribute(new Attribute("name", "war")).setText(warPath));
+            Element set = context.createElement("Set");
+            set.setAttribute("name", "war");
+            set.setTextContent(warPath);
+            root.appendChild(set);
         }
         if (!foundSetConfigurationClasses)
         {
-            Element array = new Element("Array").setAttribute(new Attribute("type","java.lang.String"));
-            array.addContent(new Element("Item").setText("org.mortbay.jetty.webapp.WebInfConfiguration"));
-            array.addContent(new Element("Item").setText("org.mortbay.jetty.plus.webapp.EnvConfiguration"));
-            array.addContent(new Element("Item").setText("org.mortbay.jetty.plus.webapp.Configuration"));
-            array.addContent(new Element("Item").setText("org.mortbay.jetty.webapp.JettyWebXmlConfiguration"));
-            array.addContent(new Element("Item").setText("org.mortbay.jetty.webapp.TagLibConfiguration"));
-            root.addContent(new Element("Set").setAttribute(new Attribute("name", "configurationClasses")).setContent(array));
+            Element set = context.createElement("Set");
+            set.setAttribute("name", "configurationClasses");
+            
+            root.appendChild(set);
+            
+            Element array = context.createElement("Array");
+            array.setAttribute("type", "java.lang.String");
+            
+            set.appendChild(array);
+
+            Element item = context.createElement("Item");
+            item.setTextContent("org.mortbay.jetty.webapp.WebInfConfiguration");
+            array.appendChild(item);
+
+            item = context.createElement("Item");
+            item.setTextContent("org.mortbay.jetty.plus.webapp.EnvConfiguration");
+            array.appendChild(item);
+
+            item = context.createElement("Item");
+            item.setTextContent("org.mortbay.jetty.plus.webapp.Configuration");
+            array.appendChild(item);
+
+            item = context.createElement("Item");
+            item.setTextContent("org.mortbay.jetty.webapp.JettyWebXmlConfiguration");
+            array.appendChild(item);
+
+            item = context.createElement("Item");
+            item.setTextContent("org.mortbay.jetty.webapp.TagLibConfiguration");
+            array.appendChild(item);
         }
     }
     
@@ -321,8 +355,27 @@
         try
         {
             output = new FileOutputStream(contextFile);
-            XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
-            xmlOutputter.output(context, output);
+            DOMSource domSource = new DOMSource(context);
+            StreamResult streamResult = new StreamResult(output);
+            TransformerFactory tf = TransformerFactory.newInstance();
+            Transformer transformer = tf.newTransformer();
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            if (context.getDoctype() != null)
+            {
+                transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, context.getDoctype().getPublicId());
+                transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, context.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
         {
@@ -340,12 +393,12 @@
         }
     }
 
-    protected Document parseJettyContext(InputStream source) throws IOException 
+    protected Document parseJettyContext(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
@@ -357,16 +410,7 @@
                 return null;
             }
         });
-        try
-        {
-            Document document = saxBuilder.build(source);
-            return document;
-        }
-        catch (JDOMException e)
-        {
-            IOException ioException = new IOException("Parse failure: "+e.getMessage());
-            ioException.fillInStackTrace();
-            throw ioException;
-        }
+        Document document = builder.parse(source);
+        return document;
     }
 }



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


Mime
View raw message