Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/RetrieveDocument.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/RetrieveDocument.java?rev=578602&r1=578601&r2=578602&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/RetrieveDocument.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/RetrieveDocument.java Sun Sep 23 13:33:31 2007
@@ -27,8 +27,6 @@
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Hashtable;
/**
* RetrieveDocument.java is designed to let the user recall or
@@ -38,72 +36,68 @@
*/
public class RetrieveDocument extends Command {
- public boolean execute(Hashtable table) throws Exception {
+ public boolean execute(XMLTools.Config table) throws Exception {
+
+ if (table.getString(XMLTools.COLLECTION) == null) {
+ System.out.println("ERROR : Collection name and switch required");
+ return false;
+ }
+
+ if (table.getString(XMLTools.NAME_OF) == null) {
+ System.out.println("ERROR : Document Key and switch required");
+ return false;
+ }
Collection col = null;
try {
- if (table.get(XMLTools.COLLECTION) != null) {
- // Create a collection instance
- String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
- (String) table.get(XMLTools.LOCAL));
- String docname = (String) table.get(XMLTools.NAME_OF);
-
- col = DatabaseManager.getCollection(colstring);
- // Make sure that the collection was found
- if (col == null) {
- System.out.println("ERROR : Collection not found!");
- return false;
- }
+ // Create a collection instance
+ String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
+ table.getBoolean(XMLTools.LOCAL));
+ col = DatabaseManager.getCollection(colstring);
+ // Make sure that the collection was found
+ if (col == null) {
+ System.out.println("ERROR : Collection not found!");
+ return false;
+ }
- if (table.get(XMLTools.NAME_OF) != null) {
+ String docname = table.getString(XMLTools.NAME_OF);
+ XMLResource resource = (XMLResource) col.getResource(docname);
+ // Verify that we were able to find the document
+ if (resource == null) {
+ System.out.println("ERROR : Document not found!");
+ return false;
+ }
- XMLResource resource = (XMLResource) col.getResource(docname);
- // Verify that we were able to find the document
- if (resource == null) {
- System.out.println("ERROR : Document not found!");
- return false;
+ String documentstr = (String) resource.getContent();
+ String path = table.getString(XMLTools.FILE_PATH);
+ if (documentstr != null && path != null && !"".equals(path)) {
+
+ FileOutputStream out = null;
+ try {
+ File file = new File(table.getString(XMLTools.FILE_PATH));
+ // Create the directory structure if necessary
+ if (file.getParentFile() != null) {
+ file.getParentFile().mkdirs();
}
- String documentstr = (String) resource.getContent();
+ out = new FileOutputStream(file);
- if (documentstr != null && !"".equals(table.get(XMLTools.FILE_PATH))) {
- try {
- File file = new File((String) table.get(XMLTools.FILE_PATH));
- // Create the directory structure if necessary
- if (file.getParentFile() != null) {
- file.getParentFile().mkdirs();
- }
-
- FileOutputStream out = new FileOutputStream(file);
-
- System.out.println("Writing...");
-
- out.write(documentstr.getBytes("utf-8"));
- out.close();
-
- System.out.println("Wrote file " + table.get(XMLTools.FILE_PATH));
-
- } catch (IOException ie) {
- System.out.println("ERROR : " + ie);
- return false;
-
- } catch (NullPointerException e) {
- System.out.println("ERROR : " + e);
- System.out.println("No file destination given");
- return false;
- }
- } else {
- // Send to stdout
- System.out.println(documentstr);
+ System.out.println("Writing...");
+
+ out.write(documentstr.getBytes("utf-8"));
+ out.close();
+
+ System.out.println("Wrote file " + table.getString(XMLTools.FILE_PATH));
+ } finally {
+ if (out != null) {
+ out.close();
}
- } else {
- System.out.println("ERROR : Document Key required");
}
} else {
- System.out.println("ERROR : Collection context required");
+ // Send to stdout
+ System.out.println(documentstr);
}
-
} finally {
// Release the collection object
if (col != null) {
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/Shutdown.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/Shutdown.java?rev=578602&r1=578601&r2=578602&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/Shutdown.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/Shutdown.java Sun Sep 23 13:33:31 2007
@@ -25,8 +25,6 @@
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
-import java.util.Hashtable;
-
/**
* Shutdown.java is designed to let the user shutdown
* the Database.
@@ -36,17 +34,17 @@
public class Shutdown extends Command {
//public boolean execute(Hashtable table, Database db)
- public boolean execute(Hashtable table) throws Exception {
+ public boolean execute(XMLTools.Config table) throws Exception {
- Collection col = null;
- if (table.get(XMLTools.COLLECTION) == null) {
+ if (table.getString(XMLTools.COLLECTION) == null) {
System.out.println("ERROR : Collection context required ");
return false;
}
+ Collection col = null;
try {
// Collection name can be incorrect, use database name instead
- String context = (String) table.get(XMLTools.COLLECTION);
+ String context = table.getString(XMLTools.COLLECTION);
int i = context.indexOf('/', 1);
String db;
if (i >= 0) {
@@ -56,11 +54,12 @@
}
// Get a Collection reference to pass on to individual commands
- String colstring = normalizeCollectionURI(db, (String) table.get(XMLTools.LOCAL));
+ String colstring = normalizeCollectionURI(db, table.getBoolean(XMLTools.LOCAL));
col = DatabaseManager.getCollection(colstring);
if (col != null) {
- DatabaseInstanceManager man = (DatabaseInstanceManager) col.getService("DatabaseInstanceManager", XMLDBAPIVERSION);
+ DatabaseInstanceManager man =
+ (DatabaseInstanceManager) col.getService("DatabaseInstanceManager", XMLDBAPIVERSION);
// Shutdown the server
man.shutdown();
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java?rev=578602&r1=578601&r2=578602&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java Sun Sep 23 13:33:31 2007
@@ -27,8 +27,6 @@
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.DatabaseManager;
-import java.util.Hashtable;
-
/**
* TextQuery is designed to enable the user to query a Collection for
* Documents that match Lucene query.
@@ -37,23 +35,22 @@
*/
public class TextQuery extends Command {
- public boolean execute(Hashtable table) throws Exception {
- if (table.get(XMLTools.COLLECTION) == null) {
+ public boolean execute(XMLTools.Config table) throws Exception {
+ if (table.getString(XMLTools.COLLECTION) == null) {
System.out.println("ERROR : Collection name and switch required");
return false;
}
- if ("".equals(table.get(XMLTools.QUERY))) {
+ if ("".equals(table.getString(XMLTools.QUERY))) {
System.out.println("ERROR : Query and switch required");
return false;
}
-
Collection col = null;
try {
- String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
- (String) table.get(XMLTools.LOCAL));
- String querystring = (String) table.get(XMLTools.QUERY);
+ String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
+ table.getBoolean(XMLTools.LOCAL));
+ String querystring = table.getString(XMLTools.QUERY);
col = DatabaseManager.getCollection(colstring);
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XPathQuery.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XPathQuery.java?rev=578602&r1=578601&r2=578602&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XPathQuery.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XPathQuery.java Sun Sep 23 13:33:31 2007
@@ -20,8 +20,6 @@
package org.apache.xindice.tools.command;
import org.apache.xindice.tools.XMLTools;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
@@ -31,7 +29,6 @@
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.modules.XPathQueryService;
-import java.util.Hashtable;
import java.util.StringTokenizer;
/**
@@ -42,26 +39,23 @@
*/
public class XPathQuery extends Command {
- private static final Log log = LogFactory.getLog(XPathQuery.class);
+ public boolean execute(XMLTools.Config table) throws Exception {
- public boolean execute(Hashtable table) throws Exception {
+ if (table.getString(XMLTools.COLLECTION) == null) {
+ System.out.println("ERROR : Collection name and switch required");
+ return false;
+ }
+
+ if ("".equals(table.getString(XMLTools.QUERY))) {
+ System.out.println("ERROR : Query and switch required");
+ return false;
+ }
Collection col = null;
try {
- if (table.get(XMLTools.COLLECTION) == null) {
- System.out.println("ERROR : Collection name and switch required");
- return false;
- }
-
- if ("".equals(table.get(XMLTools.QUERY))) {
- System.out.println("ERROR : Query and switch required");
- return false;
- }
-
- String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION), (String) table.get(XMLTools.LOCAL));
- String querystring = (String) table.get(XMLTools.QUERY);
- XPathQueryService service = null;
- ResourceIterator results = null;
+ String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
+ table.getBoolean(XMLTools.LOCAL));
+ String querystring = table.getString(XMLTools.QUERY);
col = DatabaseManager.getCollection(colstring);
@@ -70,27 +64,17 @@
return false;
}
- service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
- addNamespaces(service, (String) table.get("namespaces"));
+ XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
+ addNamespaces(service, table.getString(XMLTools.NAMESPACES));
ResourceSet resultSet = service.query(querystring);
- results = resultSet.getIterator();
+ ResourceIterator results = resultSet.getIterator();
while (results.hasMoreResources()) {
XMLResource resource = (XMLResource) results.nextResource();
String documentstr = (String) resource.getContent();
System.out.println(documentstr);
}
-
- } catch (Exception e) {
- System.out.println("ERROR : " + e.getMessage());
- if (table.get(XMLTools.VERBOSE).equals("true")) {
- if (log.isWarnEnabled()) {
- log.warn("ignored exception", e);
- }
- }
- return false;
-
} finally {
if (col != null) {
col.close();
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XUpdate.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XUpdate.java?rev=578602&r1=578601&r2=578602&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XUpdate.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/XUpdate.java Sun Sep 23 13:33:31 2007
@@ -19,8 +19,6 @@
package org.apache.xindice.tools.command;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.xindice.tools.XMLTools;
import org.xmldb.api.DatabaseManager;
@@ -31,7 +29,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
-import java.util.Hashtable;
/**
* XUpdate runs an XUpdate query stored in a file against the specified collection or
@@ -42,32 +39,30 @@
*/
public class XUpdate extends Command {
- private static final Log log = LogFactory.getLog(XUpdate.class);
+ public boolean execute(XMLTools.Config table) throws Exception {
- public boolean execute(Hashtable table) throws Exception {
+ if (table.getString(XMLTools.COLLECTION) == null) {
+ System.out.println("ERROR : Collection name and switch required");
+ return false;
+ }
+
+ if ("".equals(table.getString(XMLTools.FILE_PATH))) {
+ System.out.println("ERROR : Path to file containing XUpdate to execute required");
+ return false;
+ }
Collection col = null;
try {
- if ((String) table.get(XMLTools.COLLECTION) == null) {
- System.out.println("ERROR : Collection name and switch required");
- return false;
- }
-
- if ("".equals(table.get(XMLTools.FILE_PATH))) {
- System.out.println("ERROR : Path to file containing XUpdate to execute required");
- return false;
- }
-
- String name = (String) table.get(XMLTools.NAME_OF);
+ String name = table.getString(XMLTools.NAME_OF);
// Nomalize the collection URI
- String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
- (String) table.get(XMLTools.LOCAL));
+ String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
+ table.getBoolean(XMLTools.LOCAL));
// Read in the XUpdate commands from the file
StringBuffer commands = new StringBuffer();
- File file = new File((String) table.get(XMLTools.FILE_PATH));
+ File file = new File(table.getString(XMLTools.FILE_PATH));
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
@@ -85,12 +80,9 @@
}
// To run XUpdate commands we use the XUpdateQueryService
- XUpdateQueryService service = null;
- service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
-
+ XUpdateQueryService service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
- long result = 0;
-
+ long result;
// See if we're updating one document or the whole collection.
if (name == null) {
result = service.update(commands.toString());
@@ -99,18 +91,7 @@
result = service.updateResource(name, commands.toString());
}
-
System.out.println(result + " documents updated");
-
- } catch (Exception e) {
- System.out.println("ERROR : " + e.getMessage());
- if (table.get(XMLTools.VERBOSE).equals("true")) {
- if (log.isWarnEnabled()) {
- log.warn("ignored exception", e);
- }
- }
- return false;
-
} finally {
if (col != null) {
col.close();
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.