You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by cd...@apache.org on 2006/08/28 04:17:34 UTC

svn commit: r437508 - /portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/install/file/TomcatCrossContextGenerator.java

Author: cdoremus
Date: Sun Aug 27 19:17:33 2006
New Revision: 437508

URL: http://svn.apache.org/viewvc?rev=437508&view=rev
Log:
Refactored much of the work done in main() into createContextFile() to allow use by admin portlet.

Modified:
    portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/install/file/TomcatCrossContextGenerator.java

Modified: portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/install/file/TomcatCrossContextGenerator.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/install/file/TomcatCrossContextGenerator.java?rev=437508&r1=437507&r2=437508&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/install/file/TomcatCrossContextGenerator.java (original)
+++ portals/pluto/trunk/pluto-util/src/main/java/org/apache/pluto/util/install/file/TomcatCrossContextGenerator.java Sun Aug 27 19:17:33 2006
@@ -17,6 +17,9 @@
 
 import java.io.*;
 
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
 /**
  * TODO JavaDoc
  *
@@ -25,7 +28,9 @@
  * @since Dec 11, 2005
  */
 public class TomcatCrossContextGenerator {
-
+	private static final String PLUTO_TEMP_DIR = "PlutoDomain";
+	private static Log LOG = LogFactory.getLog(TomcatCrossContextGenerator.class);
+	
     public static void main(String[] args) throws IOException {
 
         File tomcatHome = new File(args[0]);
@@ -33,23 +38,44 @@
         File conf = new File(tomcatHome, "conf/Catalina/localhost");
 
         File[] files = webapps.listFiles(new PortletFileNameFilter());
-        for(int i=0;i<files.length;i++) {
+        for(int i=0; i < files.length; i++) {
             String fileName = files[i].getName();
-            String contextPath = fileName.substring(0, fileName.indexOf(".war"));
+            String contextName = fileName.substring(0, fileName.indexOf(".war"));
 
-            StringBuffer contents = new StringBuffer();
-            contents.append("<Context ")
-                    .append("path=\"").append(contextPath).append("\" ")
-                    .append("docBase=\"").append(fileName).append("\" ")
-                    .append("crossContext=\"true\">").append("</Context>");
-            File confFile = new File(conf, contextPath+".xml");
-            System.out.println("Writing file: "+confFile.getAbsolutePath());
-            PrintWriter out = new PrintWriter(new FileWriter(confFile));
-            out.println(contents.toString());
-            out.flush();
-            out.close();
+            createContextFile(conf, fileName, contextName);
         }
     }
+
+    /**
+     * Creates a tomcat-specific context deployment descriptor 
+     * and deploys it.
+     * 
+     * @param confDir Tomcat conf directory
+     * @param fileName File name of the war
+     * @param contextName The root name of the context file
+     * @throws IOException If there is a problem 
+     */
+	public static void createContextFile(File confDir, String fileName, String contextName) throws IOException {
+		PrintWriter out = null;
+		try {
+			StringBuffer contents = new StringBuffer();
+			contents.append("<Context ")
+			        .append("path=\"").append(contextName).append("\" ")
+			        .append("docBase=\"../").append(PLUTO_TEMP_DIR).append("/").append(fileName).append("\" ")
+			        .append("crossContext=\"true\">").append("</Context>");
+			File confFile = new File(confDir, contextName+".xml");
+			if (LOG.isInfoEnabled()) {
+				LOG.info("Writing file: "+ confFile.getAbsolutePath());			
+			}
+			out = new PrintWriter(new FileWriter(confFile));
+			out.println(contents.toString());
+		} finally {
+			if (out != null) {
+				out.flush();
+				out.close();							
+			}
+		}
+	}
 
     public static class PortletFileNameFilter implements FilenameFilter {
         public boolean accept(File dir, String name) {