You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pe...@apache.org on 2005/01/13 14:08:20 UTC
cvs commit: jakarta-tomcat-catalina/modules/storeconfig/test/src/share/org/apache/catalina/storeconfig StoreContextAppenderTest.java
pero 2005/01/13 05:08:20
Modified: modules/storeconfig/src/share/org/apache/catalina/storeconfig
StandardContextSF.java StoreContextAppender.java
modules/storeconfig/test/src/share/org/apache/catalina/storeconfig
StoreContextAppenderTest.java
Log:
don't save "path" except in server.xml
don't save "docBase" if the webapp is in the host "appBase"
Revision Changes Path
1.2 +1 -1 jakarta-tomcat-catalina/modules/storeconfig/src/share/org/apache/catalina/storeconfig/StandardContextSF.java
Index: StandardContextSF.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/modules/storeconfig/src/share/org/apache/catalina/storeconfig/StandardContextSF.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StandardContextSF.java 8 Jan 2005 11:14:07 -0000 1.1
+++ StandardContextSF.java 13 Jan 2005 13:08:20 -0000 1.2
@@ -81,8 +81,8 @@
else
storeContextSeparate(aWriter, indent,
(StandardContext) aContext);
+ return;
}
- return;
}
}
}
1.2 +60 -11 jakarta-tomcat-catalina/modules/storeconfig/src/share/org/apache/catalina/storeconfig/StoreContextAppender.java
Index: StoreContextAppender.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/modules/storeconfig/src/share/org/apache/catalina/storeconfig/StoreContextAppender.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StoreContextAppender.java 8 Jan 2005 11:14:07 -0000 1.1
+++ StoreContextAppender.java 13 Jan 2005 13:08:20 -0000 1.2
@@ -16,20 +16,26 @@
package org.apache.catalina.storeconfig;
import java.io.File;
+import java.io.IOException;
+
+import javax.print.DocPrintJob;
import org.apache.catalina.Container;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardHost;
/**
- * store StandardCOntext Attributes ...
+ * store StandardContext Attributes ... TODO DefaultContext Handling
+ *
* @author Peter Rossbach
*
*/
public class StoreContextAppender extends StoreAppender {
/*
- * (non-Javadoc)
+ * Print Context Values. <ul><li> Spezial handling to default workDir.
+ * </li><li> Don't save path at external context.xml </li><li> Don't
+ * generate docBase for host.appBase webapps <LI></ul>
*
* @see org.apache.catalina.config.StoreAppender#isPrintValue(java.lang.Object,
* java.lang.Object, java.lang.String,
@@ -38,15 +44,61 @@
public boolean isPrintValue(Object bean, Object bean2, String attrName,
StoreDescription desc) {
boolean isPrint = super.isPrintValue(bean, bean2, attrName, desc);
- if (isPrint && "workDir".equals(attrName)) {
+ if (isPrint) {
StandardContext context = ((StandardContext) bean);
- String defaultWorkDir = getDefaultWorkDir(context);
- isPrint = !defaultWorkDir.equals(context.getWorkDir());
+ if ("workDir".equals(attrName)) {
+ String defaultWorkDir = getDefaultWorkDir(context);
+ isPrint = !defaultWorkDir.equals(context.getWorkDir());
+ } else if ("path".equals(attrName)) {
+ isPrint = desc.isStoreSeparate()
+ && desc.isExternalAllowed()
+ && context.getConfigFile() == null;
+ } else if ("docBase".equals(attrName)) {
+ Container host = context.getParent();
+ if (host instanceof StandardHost) {
+ File appBase = getAppBase(((StandardHost) host));
+ File docBase = getDocBase(context,appBase);
+ isPrint = !appBase.equals(docBase.getParentFile());
+ }
+ }
}
return isPrint;
}
+ protected File getAppBase(StandardHost host) {
+
+ File appBase;
+ File file = new File(host.getAppBase());
+ if (!file.isAbsolute())
+ file = new File(System.getProperty("catalina.base"), host
+ .getAppBase());
+ try {
+ appBase = file.getCanonicalFile();
+ } catch (IOException e) {
+ appBase = file;
+ }
+ return (appBase);
+
+ }
+
+ protected File getDocBase(StandardContext context, File appBase) {
+
+ File docBase;
+ File file = new File(context.getDocBase());
+ if (!file.isAbsolute())
+ file = new File(appBase, context.getDocBase());
+ try {
+ docBase = file.getCanonicalFile();
+ } catch (IOException e) {
+ docBase = file;
+ }
+ return (docBase);
+
+ }
+
/**
+ * Make default Work Dir
+ *
* @param context
* @return
*/
@@ -71,12 +123,9 @@
}
/*
- * Generate a real default StandardContext
- * TODO read and interpret the
- * default context.xml and context.xml.default
- * TODO Cache a Default
- * StandardContext ( with reloading strategy)
- * TODO remove really all
+ * Generate a real default StandardContext TODO read and interpret the
+ * default context.xml and context.xml.default TODO Cache a Default
+ * StandardContext ( with reloading strategy) TODO remove really all
* elements, but detection is hard... To Listener or Valve from same class?>
*
* @see org.apache.catalina.storeconfig.StoreAppender#defaultInstance(java.lang.Object)
1.2 +31 -0 jakarta-tomcat-catalina/modules/storeconfig/test/src/share/org/apache/catalina/storeconfig/StoreContextAppenderTest.java
Index: StoreContextAppenderTest.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/modules/storeconfig/test/src/share/org/apache/catalina/storeconfig/StoreContextAppenderTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StoreContextAppenderTest.java 8 Jan 2005 11:14:08 -0000 1.1
+++ StoreContextAppenderTest.java 13 Jan 2005 13:08:20 -0000 1.2
@@ -12,6 +12,7 @@
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.ContextConfig;
+import java.io.File ;
/**
* @author Peter Rossbach
@@ -99,5 +100,35 @@
.defaultInstance(context);
assertEquals(0, defaultContext.findLifecycleListeners().length);
+ }
+
+ public void testPath() throws Exception {
+ StandardContext defaultContext = (StandardContext) appender
+ .defaultInstance(context);
+ context.setPath("/myapps");
+ assertNull(context.getConfigFile());
+ StoreDescription desc = new StoreDescription();
+ desc.setExternalAllowed(true);
+ desc.setStoreSeparate(true);
+ assertTrue(appender.isPrintValue(context, defaultContext, "path", desc));
+ context.setConfigFile("conf/Catalina/locahost/myapps.xml");
+ assertFalse(appender.isPrintValue(context, defaultContext, "path", desc));
+ desc.setExternalAllowed(false);
+ assertFalse(appender.isPrintValue(context, defaultContext, "path", desc));
+ desc.setExternalAllowed(true);
+ desc.setStoreSeparate(false);
+ assertFalse(appender.isPrintValue(context, defaultContext, "path", desc));
+ }
+
+ public void testDocBase() throws Exception {
+ StandardContext defaultContext = (StandardContext) appender
+ .defaultInstance(context);
+ context.setPath("/myapps");
+ context.setDocBase("myapps");
+ host.setAppBase("webapps");
+ assertFalse(appender.isPrintValue(context, defaultContext, "docBase", null));
+ context.setDocBase(System.getProperty("java.io.tmpdir") + "/myapps");
+ assertTrue(appender.isPrintValue(context, defaultContext, "docBase", null));
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org