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 rw...@apache.org on 2005/02/02 04:09:50 UTC
cvs commit: jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy JetspeedContextRewriter.java JetspeedDeployFactory.java JetspeedDeploy.java JetspeedWebApplicationRewriter.java
rwatler 2005/02/01 19:09:50
Modified: components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy
JetspeedDeploy.java
JetspeedWebApplicationRewriter.java
Added: components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy
JetspeedContextRewriter.java
JetspeedDeployFactory.java
Log:
War Infusion PAM Implementation
Revision Changes Path
1.8 +62 -41 jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
Index: JetspeedDeploy.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JetspeedDeploy.java 25 Aug 2004 02:27:05 -0000 1.7
+++ JetspeedDeploy.java 2 Feb 2005 03:09:50 -0000 1.8
@@ -28,6 +28,9 @@
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
/**
* Makes a web application Deploy-ready for Jetspeed.
@@ -36,7 +39,7 @@
* @author <a href="mailto:dsundstrom@gluecode.com">David Sean Taylor</a>
* @version $Id$
*/
-public class JetspeedDeploy
+public class JetspeedDeploy implements Deploy
{
public static void main(String[] args) throws Exception
{
@@ -78,12 +81,13 @@
String portletApplicationName = getPortletApplicationName(outputName);
jin = new JarInputStream(new FileInputStream(inputName));
jout = new JarOutputStream(new FileOutputStream(outputName), jin.getManifest());
-
+
// copy over all of the files in the input war to the output
- // war except for web.xml and portlet.xml, which we parse for
- // use later
+ // war except for web.xml, portlet.xml, and context.xml which
+ // we parse for use later
Document webXml = null;
Document portletXml = null;
+ Document contextXml = null;
ZipEntry src;
while ((src = jin.getNextEntry()) != null)
{
@@ -98,12 +102,17 @@
System.out.println("Found WEB-INF/portlet.xml");
portletXml = parseXml(jin);
}
+ else if ("META-INF/context.xml".equals(target))
+ {
+ System.out.println("Found META-INF/context.xml");
+ contextXml = parseXml(jin);
+ }
else
{
addFile(target, jin, jout);
}
}
-
+
if (webXml == null)
{
throw new IllegalArgumentException("WEB-INF/web.xml");
@@ -112,24 +121,20 @@
{
throw new IllegalArgumentException("WEB-INF/portlet.xml");
}
-
- JetspeedWebApplicationRewriter rewriter = new JetspeedWebApplicationRewriter(webXml, portletApplicationName, registerAtInit);
- rewriter.processWebXML();
-
-
-
- // mung the web.xml
- //webXml.getRootElement().setAttribute("foo", "bar");
-
- // write the web.xml and portlet.xml files
+
+ JetspeedWebApplicationRewriter webRewriter = new JetspeedWebApplicationRewriter(webXml, portletApplicationName, registerAtInit);
+ webRewriter.processWebXML();
+ JetspeedContextRewriter contextRewriter = new JetspeedContextRewriter(contextXml, portletApplicationName);
+ contextRewriter.processContextXML();
+
+ // write the web.xml, portlet.xml, and context.xml files
addFile("WEB-INF/web.xml", webXml, jout);
addFile("WEB-INF/portlet.xml", portletXml, jout);
-
- if(rewriter.isPortletTaglibAdded())
+ addFile("META-INF/context.xml", contextXml, jout);
+
+ if(webRewriter.isPortletTaglibAdded())
{
System.out.println("Attempting to add portlet.tld to war...");
- //File portletTld = new File("../../portal/src/webapp/WEB-INF/tld/portlet.tld");
- //System.out.println("Looking for portlet.tld in " + portletTld);
InputStream is = this.getClass().getResourceAsStream("/org/apache/jetspeed/tools/deploy/portlet.tld");
if(is == null)
{
@@ -137,19 +142,19 @@
}
else
{
- System.out.println("Adding portlet.tld to war...");
-
- addFile("WEB-INF/tld/portlet.tld", is, jout);
- is.close();
+ System.out.println("Adding portlet.tld to war...");
+
+ addFile("WEB-INF/tld/portlet.tld", is, jout);
+ is.close();
}
}
-
+
jout.close();
}
catch (IOException e)
{
e.printStackTrace();
-
+
if(jin != null)
{
try
@@ -173,14 +178,28 @@
new File(outputName).delete();
}
}
-
+
private Document parseXml(InputStream jin) 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()
+ {
+ 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 = saxBuilder.build(new UncloseableInputStream(jin));
return document;
}
- public void addFile(String path, InputStream source, JarOutputStream jos) throws IOException
+ private void addFile(String path, InputStream source, JarOutputStream jos) throws IOException
{
jos.putNextEntry(new ZipEntry(path));
try {
@@ -192,24 +211,26 @@
jos.closeEntry();
}
}
-
- public void addFile(String path, Document source, JarOutputStream jos) throws IOException {
- jos.putNextEntry(new ZipEntry(path));
-
- XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
- try {
- xmlOutputter.output(source, jos);
- } finally {
- jos.closeEntry();
+
+ private void addFile(String path, Document source, JarOutputStream jos) throws IOException {
+ if (source != null)
+ {
+ jos.putNextEntry(new ZipEntry(path));
+ XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
+ try {
+ xmlOutputter.output(source, jos);
+ } finally {
+ jos.closeEntry();
+ }
}
}
-
+
private String getPortletApplicationName(String path)
{
File file = new File(path);
String name = file.getName();
String portletApplicationName = name;
-
+
int index = name.lastIndexOf(".");
if (index > -1)
{
@@ -217,7 +238,7 @@
}
return portletApplicationName;
}
-
+
private class UncloseableInputStream extends InputStream {
private final InputStream in;
@@ -261,4 +282,4 @@
return in.markSupported();
}
}
-}
\ No newline at end of file
+}
1.12 +1 -27 jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java
Index: JetspeedWebApplicationRewriter.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- JetspeedWebApplicationRewriter.java 16 Aug 2004 21:29:14 -0000 1.11
+++ JetspeedWebApplicationRewriter.java 2 Feb 2005 03:09:50 -0000 1.12
@@ -23,12 +23,7 @@
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Parent;
-import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
/**
* Utilities for manipulating the web.xml deployment descriptor
@@ -94,29 +89,8 @@
public void processWebXML()
throws Exception
{
- SAXBuilder builder = new SAXBuilder();
- Writer webXmlWriter = null;
- InputStream webXmlIn = null;
-
try
{
- // Use the local dtd instead of remote dtd. This
- // allows to deploy the application offline
- 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"));
- }
- else return null;
- }
- });
-
-
Element root = document.getRootElement();
Object jetspeedServlet = XPath.selectSingleNode(document, JETSPEED_SERVLET_XPATH);
@@ -277,4 +251,4 @@
{
return portletTaglibAdded;
}
-}
\ No newline at end of file
+}
1.1 jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedContextRewriter.java
Index: JetspeedContextRewriter.java
===================================================================
/*
* Copyright 2000-2005 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;
/**
* Utilities for manipulating the context.xml deployment descriptor
*
* @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
* @version $Id: JetspeedContextRewriter.java,v 1.1 2005/02/02 03:09:50 rwatler Exp $
*/
public class JetspeedContextRewriter
{
private Document document;
private String portletApplication;
private boolean changed = false;
public JetspeedContextRewriter(Document doc, String portletApplication)
{
this.document = doc;
this.portletApplication = portletApplication;
}
public void processContextXML()
throws Exception
{
if (document != null)
{
try
{
// get root Context
Element root = null;
if (!document.hasRootElement())
{
root = new Element("Context");
document.setRootElement(root);
}
else
{
root = document.getRootElement();
}
// set Context path
String pathAttribute = root.getAttributeValue("path");
if ((pathAttribute == null) || !pathAttribute.equals("/" + portletApplication))
{
root.setAttribute("path", "/" + portletApplication);
changed = true;
}
// set Context docBase
String docBaseAttribute = root.getAttributeValue("docBase");
if ((docBaseAttribute == null) || !docBaseAttribute.equals(portletApplication))
{
root.setAttribute("docBase", portletApplication);
changed = true;
}
}
catch (Exception e)
{
throw new Exception("Unable to process context.xml for infusion " + e.toString(), e);
}
}
}
}
1.1 jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeployFactory.java
Index: JetspeedDeployFactory.java
===================================================================
/*
* Copyright 2000-2005 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;
/**
* Factory component used to create JetspeedDeploy instances
*
* @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
* @version $Id: JetspeedDeployFactory.java,v 1.1 2005/02/02 03:09:50 rwatler Exp $
*/
public class JetspeedDeployFactory implements DeployFactory
{
/**
* JetspeedDeployFactory
*/
public JetspeedDeployFactory()
{
}
/**
* getInstance
*
* @param inputWarPath
* @param outputWarPath
* @param registerAtInit
* @return JetspeedDeploy instance
*/
public Deploy getInstance(String inputWarPath, String outputWarPath, boolean registerAtInit) throws Exception
{
return new JetspeedDeploy(inputWarPath, outputWarPath, registerAtInit);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org