Vadim Gritsenko wrote:
Kevin Ross wrote:
Now, how about that ' XINDICE_HOME catch 22' patch? ;)
Ok, here it is. In short: I found out that XINDICE_DB_HOME is already defined in the Xindice.java and (almost) used in XindiceServlet. Behavior is that XINDICE_DB_HOME is optional, and when present, it overrides other preferences:
- XindiceServlet prefers /WEB-INF directory as default location.
- Embedded database impl prefers directory of the system.xml file as default location.
All this happens only when system.xml contains relative path. Once this patch is applied, following is possible:
set xindice_home=<xindice cvs checkout> set xindice_db_home=<any dir> cd %xindice_home%\bin xindice lc -l -c /db -d ..\config\system.xml
Patch attached.
PS There is still place for improvement... Does it make sense to allow initializing DB with arbitrary system.xml file?
PPS PROP_CMD_HOME was not used anywhere. xmlRpcDriver and getXmlRpcDriver() too. So I took the liberty of removing them.
Vadim
Index: java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java,v
retrieving revision 1.12
diff -u -r1.12 DatabaseImpl.java
--- java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java 17 Jul
2003 14:33:20 -0000 1.12
+++ java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java 30 Jul
2003 01:08:57 -0000
@@ -120,12 +120,13 @@
protected Configuration loadConfiguration() throws FileNotFoundException,
XindiceException, ReadOnlyException {
Configuration config;
+ String configDir = null;
String configFile =
System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
if (configFile != null && !configFile.equals("")) {
-
log.info("Specified configuration file: '" + configFile + "'");
- FileInputStream configXMLFile = new FileInputStream(new
File(configFile));
+ FileInputStream configXMLFile = new FileInputStream(configFile);
config = new Configuration(DOMParser.toDocument(configXMLFile),
false);
+ configDir = new File(configFile).getAbsoluteFile().getParent();
}
else {
log.info("No configuration file specified, going with the default
configuration");
@@ -133,6 +134,24 @@
}
config = config.getChild("root-collection", false);
+ String dbRoot = config.getAttribute(Database.DBROOT,
Database.DBROOT_DEFAULT);
+ if (!new File(dbRoot).isAbsolute()) {
+ // Let's see if the property was specified.
+ String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
+ if (home != null) {
+ config.setAttribute(Database.DBROOT, home + File.separator +
dbRoot);
+ }
+ else if (configDir != null) {
+ config.setAttribute(Database.DBROOT, configDir +
File.separator + dbRoot);
+ }
+ else {
+ log.warn("The database configuration file is not specified and
there was no "
+ + Xindice.PROP_XINDICE_DB_HOME + " property set, "
+ + "so Xindice was unable to determine a database
location. "
+ + "Database will be created relative to the current
directory.");
+ config.setAttribute(Database.DBROOT, new
File(".").getAbsolutePath() + File.separator + dbRoot);
+ }
+ }
return config;
}
Index: java/src/org/apache/xindice/core/Database.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/Database.java,v
retrieving revision 1.21
diff -u -r1.21 Database.java
--- java/src/org/apache/xindice/core/Database.java 14 Jul 2003 19:07:14
-0000 1.21
+++ java/src/org/apache/xindice/core/Database.java 30 Jul 2003 01:08:58
-0000
@@ -73,6 +73,7 @@
import org.apache.xindice.util.ConfigurationException;
import org.apache.xindice.util.Named;
import org.apache.xindice.util.XindiceException;
+import org.apache.xindice.server.Xindice;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -83,11 +84,13 @@
public static final String DBROOT = "dbroot";
public static final String NAME = "name";
- public static final String PROP_XINDICE_HOME = "xindice.home";
private static final String QUERYENGINE = "queryengine";
private static final String COLKEY = "database.xml";
private static final String DATABASE = "database";
private static final String METADATA = "use-metadata";
+
+ public static final String DBROOT_DEFAULT = "./db/";
+
private static Log log = LogFactory.getLog("org.apache.xindice.core");
private static final Map databases = new HashMap(); // String to Database
@@ -120,8 +123,8 @@
try {
database.setConfig(config);
}
- catch (XindiceException x) { // TODO: Configurable
interface should use ConfigurationException instead of XindiceException.
-
+ catch (XindiceException x) {
+ // TODO: Configurable interface should use
ConfigurationException instead of XindiceException.
throw new ConfigurationException(x);
}
@@ -289,13 +292,14 @@
public void setConfig(Configuration config) throws XindiceException {
super.setConfig(config);
- setName(config.getAttribute(NAME));
+ // FIXME: super sets this: setName(config.getAttribute(NAME));
setCanonicalName('/' + getName());
String dbroot = config.getAttribute(DBROOT);
File dbrootDir = new File(dbroot);
if (!dbrootDir.isAbsolute()) {
- dbrootDir = new File(System.getProperty(PROP_XINDICE_HOME),
dbroot);
+ // TODO: Here, DB root already should be absolute. XMLRPC and
Embed drivers take care of it.
+ dbrootDir = new
File(System.getProperty(Xindice.PROP_XINDICE_DB_HOME), dbroot);
}
setCollectionRoot(dbrootDir);
log.info("Database points to " + dbrootDir.getAbsolutePath());
@@ -303,11 +307,11 @@
try {
Configuration queryCfg = config.getChild(QUERYENGINE);
- if (queryCfg != null)
+ if (queryCfg != null) {
this.engine.setConfig(queryCfg);
+ }
}
catch (Exception e) {
-
log.warn(e);
}
Index: java/src/org/apache/xindice/server/Xindice.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/Xindice.java,v
retrieving revision 1.11
diff -u -r1.11 Xindice.java
--- java/src/org/apache/xindice/server/Xindice.java 14 Jul 2003 16:20:58
-0000 1.11
+++ java/src/org/apache/xindice/server/Xindice.java 30 Jul 2003 01:08:58
-0000
@@ -65,8 +65,19 @@
public interface Xindice {
// Global Property Information
+
+ /**
+ * System property specyfying location of the xindice CVS checkout.
+ * Used by the tools to locate configuration file.
+ */
public static final String PROP_XINDICE_HOME = "xindice.home";
- public static final String PROP_CMD_HOME = "cmd.home";
+
+ /**
+ * System property specyfying location of the xindice database.
+ * If present, this property overrides location determined by the
driver.
+ */
+ public static final String PROP_XINDICE_DB_HOME = "xindice.db.home";
+
public static final String PROP_XINDICE_CONFIGURATION =
"xindice.configuration";
// Version Information
Index: java/src/org/apache/xindice/server/XindiceServlet.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/XindiceServlet.java,v
retrieving revision 1.16
diff -u -r1.16 XindiceServlet.java
--- java/src/org/apache/xindice/server/XindiceServlet.java 14 Jul 2003
18:30:55 -0000 1.16
+++ java/src/org/apache/xindice/server/XindiceServlet.java 30 Jul 2003
01:08:59 -0000
@@ -97,8 +97,6 @@
protected Database database;
protected XmlRpcServer xmlrpcServer;
- private String xmlRpcDriver;
-
public void destroy() {
try {
// When the servlet engine goes down we need to close
the
@@ -136,18 +134,6 @@
}
/**
- * Return the XML-RPC driver, a classname or shorthand string informing
- * the XmlRpc package which SAX parser we wish it to use. [Created for
- * unit-testing purposes.]
- *
- * @returns String containing the classname or shorthand name of the SAX
- * parser the XmlRpc package will use.
- */
- public String getXmlRpcDriver() {
- return xmlRpcDriver;
- }
-
- /**
* TODO: verify that if is an error occured, the database will be closed
* propertly
*/
@@ -162,7 +148,6 @@
Configuration rootCollectionConfiguration =
configuration.getChild("root-collection");
if (rootCollectionConfiguration == null) {
-
throw new ConfigurationException("The database
configuration is missing the <root-collection> element");
}
else {
@@ -176,13 +161,12 @@
// the war has not been unpacked. In this
case, we throw an exception and
// ask the user to specify the location of
database root
//
- String dbRoot =
rootCollectionConfiguration.getAttribute(Database.DBROOT, "./db/");
- File dbRootDir = new File(dbRoot);
+ String dbRoot =
rootCollectionConfiguration.getAttribute(Database.DBROOT,
Database.DBROOT_DEFAULT);
//
// If there is no absolute path, we have to
perform some checks.
//
- if (!dbRootDir.isAbsolute()) {
+ if (!new File(dbRoot).isAbsolute()) {
// Stupid hack but spec compliant.
// If getRealPath()
returns null the war archive has not been unpacked.
@@ -190,30 +174,27 @@
String realPath =
servletConfig.getServletContext().getRealPath("/WEB-INF");
// Let's see if the property was
specified.
- String home =
System.getProperty("xindice.db.home");
-
+ String home =
System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
if (home != null) {
-
rootCollectionConfiguration.setAttribute(Database.DBROOT, home +
System.getProperty("file.separator") + dbRoot);
+
rootCollectionConfiguration.setAttribute(Database.DBROOT, home + File.separator
+ dbRoot);
}
else if (realPath != null) {
+ String root = realPath +
File.separator + dbRoot;
log.warn(
"The database root
directory has been set to "
- + realPath
- +
System.getProperty("file.separator")
- + dbRoot
+ + root
+ ". Keep in
mind that if a war upgrade will take place the database will be lost.");
-
-
rootCollectionConfiguration.setAttribute(Database.DBROOT, realPath +
System.getProperty("file.separator") + dbRoot);
+
rootCollectionConfiguration.setAttribute(Database.DBROOT, root);
}
else {
throw new
ConfigurationException(
"The database
configuration points to a relative path, "
- + "but there
was no xindice.home property set. "
+ + "but there
was no " + Xindice.PROP_XINDICE_DB_HOME + " property set. "
+ "Furthermore,
the war was not unpacked by the application server "
+ "so Xindice
was unable to find a database location "
+ "Please check
/WEB-INF/system.xml and set an absolute path "
+ "as the
\"dbroot\" attribute of \"root-collection\" "
- + "or specify a
suitable xindice.db.home system property.");
+ + "or specify a
suitable " + Xindice.PROP_XINDICE_DB_HOME + " system property.");
}
}
