You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by by...@apache.org on 2006/11/11 01:58:04 UTC
svn commit: r473607 - in /xml/xindice/trunk: config/
java/src/org/apache/xindice/tools/ java/src/org/apache/xindice/tools/command/
Author: byrne
Date: Fri Nov 10 16:58:03 2006
New Revision: 473607
URL: http://svn.apache.org/viewvc?view=rev&rev=473607
Log:
Added a new HelpCommand accessable through -h or --help.
Help menu no longer prints on errors. Removed some excess printStack statements to help in debuging..
Pagecount can now be set for collections and indexes from the command line using --pagecount.
Todd Byrne
Added:
xml/xindice/trunk/java/src/org/apache/xindice/tools/command/HelpCommand.java
Modified:
xml/xindice/trunk/config/commands.xml
xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java
xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddCollection.java
xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddIndexer.java
Modified: xml/xindice/trunk/config/commands.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/config/commands.xml?view=diff&rev=473607&r1=473606&r2=473607
==============================================================================
--- xml/xindice/trunk/config/commands.xml (original)
+++ xml/xindice/trunk/config/commands.xml Fri Nov 10 16:58:03 2006
@@ -32,6 +32,16 @@
<commands>
<user>
+ <command switch="--help"
+ name="help screen"
+ class="org.apache.xindice.tools.command.HelpCommand"
+ helpclass=""
+ description="Prints the help screen." />
+ <command switch="-h"
+ name="help screen"
+ class="org.apache.xindice.tools.command.HelpCommand"
+ helpclass=""
+ description="Prints the help screen." />
<command switch="ac"
name="add_collection"
class="org.apache.xindice.tools.command.AddCollection"
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java?view=diff&rev=473607&r1=473606&r2=473607
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java Fri Nov 10 16:58:03 2006
@@ -67,7 +67,8 @@
public static final String AUTO_KEY = "autoKey";
public static final String NAMESPACES = "namespaces";
public static final String IMPL_CLASS = "implClass";
-
+ public static final String COMMAND_LIST="__command_list__";
+ public static final String PAGE_COUNT = "pagecount";
private Hashtable table;
protected String location = null;
private boolean initialized = false;
@@ -167,21 +168,15 @@
try {
init();
parseArguments(args);
-
- if (!execute()) {
- printHelp();
- }
+ execute();
} catch (IllegalArgumentException e) {
- printHelp();
- throw new XindiceException("ERROR : " + e.getMessage(), e);
+ throw new XindiceException("ERROR : " + e.getMessage() + " Try -h for help.", e);
} catch (NoSuchElementException e) {
- throw new NoSuchElementException("ERROR : " + e + " Switch found. Parameter missing.");
+ throw new NoSuchElementException("ERROR : " + e + " Switch found. Parameter missing. Try -h for help.");
} catch (NullPointerException e) {
- e.printStackTrace(System.err);
- throw new NullPointerException("ERROR : " + e);
+ throw new NullPointerException("ERROR : " + e + " Try -h for help.");
} catch (Exception e) {
- e.printStackTrace(System.err);
- throw new XindiceException("ERROR : " + e.getMessage(), e);
+ throw new XindiceException("ERROR : " + e.getMessage() + " Try -h for help.", e);
}
}
@@ -199,7 +194,8 @@
if (!at.hasMoreTokens()) {
throw new IllegalArgumentException("No argument found");
}
-
+ // add the command list so that the HelpCommand and print specific help information
+ table.put(COMMAND_LIST,commandsList);
// Action should always be the second token, if not there show help
table.put(ACTION, at.nextToken());
@@ -218,8 +214,6 @@
table.put(EXTENSION, at.nextSwitchToken());
} else if (token.equalsIgnoreCase("-f") || token.equalsIgnoreCase("--filepath")) {
table.put(FILE_PATH, at.nextSwitchToken());
- } else if (token.equalsIgnoreCase("-h") || token.equalsIgnoreCase("--help")) {
- table.put(ACTION, "help");
} else if (token.equalsIgnoreCase("-n") || token.equalsIgnoreCase("--nameOf")) {
table.put(NAME_OF, at.nextSwitchToken());
} else if (token.equalsIgnoreCase("-p") || token.equalsIgnoreCase("--pattern")) {
@@ -256,11 +250,12 @@
table.put(PAGE_SIZE, at.nextSwitchToken());
} else if (token.equalsIgnoreCase("--maxkeysize")) {
table.put(MAX_KEY_SIZE, at.nextSwitchToken());
+ } else if (token.equalsIgnoreCase("--pagecount")) {
+ table.put(PAGE_COUNT, at.nextSwitchToken());
}
} // End of while loop
}
-
-
+
/**
* This method is to carry out execution, after instance variables being setup by process( args )
*/
@@ -283,21 +278,16 @@
}
if (commandClass != null) {
- try {
+ Command command;
+ try {
// Register Xindice Database with xml:db
DatabaseImpl db = new DatabaseImpl();
DatabaseManager.registerDatabase(db);
// Execute command class
- Command command = (Command) Class.forName(commandClass).newInstance();
+ command = (Command) Class.forName(commandClass).newInstance();
command.execute(table);
- // Close Database
- if ("true".equals(table.get(LOCAL))) {
- command = new org.apache.xindice.tools.command.Shutdown();
- command.execute(table);
- }
-
return true;
} catch (XMLDBException e) {
System.err.println("XMLDB Exception " + e.errorCode + ": " + e.getMessage());
@@ -312,12 +302,20 @@
}
return false;
}
+ finally {
+ // Close Database
+ if ("true".equals(table.get(LOCAL))) {
+ command = new org.apache.xindice.tools.command.Shutdown();
+ command.execute(table);
+ }
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("\"" + action + "\" not recognized.");
}
-
- return false;
}
-
-
+
public boolean handleOption(String option, ArgTokenizer at) {
return false;
}
@@ -578,84 +576,5 @@
*/
public String getPassword() {
return (String) table.get(PASSWORD);
- }
-
-
- public void printHelp() {
- NodeList list = getCommands();
-
- // This method relies on two things to format the output for help
- // Method isAdmin() - Tells us if this is an admin instance, used to hide certain output
- // XML file Commands.xml attribute "helpclass" - used to order output
-
- String helpClass; // Holds the helpclass for the current <command> node
- String desc; // Holds the description for the current <command> node
- String cmdswitch; // Holds the switch for the current <command> node
-
-
- // Show the header and switch commands
- System.out.println();
- System.out.println("Xindice Command Tools v" + Xindice.Version);
- System.out.println();
- System.out.println("Format: xindice action [switch] [parameter]");
- System.out.println();
- System.out.println("Switches:");
- System.out.println(" -c Collection context (must always be specified),");
- System.out.println(" can be either canonical name of the collection");
- System.out.println(" or complete xmldb URL");
- System.out.println(" -e File extension for multiple documents");
- System.out.println(" -f File path for document retrieval and storage");
- System.out.println(" -n Name");
- System.out.println(" -p Index pattern");
- System.out.println(" -q Query string");
- System.out.println(" -s Semi-colon delimited list of namespaces for query in ");
- System.out.println(" the form prefix=namespace-uri");
- System.out.println(" -l Use a local database rather then going over the network.");
- System.out.println(" Should be combined with -d to specify the configuration to use.");
- System.out.println(" -d Path to the database configuration to use for the local ");
- System.out.println(" database. Only applies if -l is specified.");
- System.out.println(" -t Specify the data type in collection index");
- System.out.println(" -v Verbose");
- System.out.println(" --pagesize Page size for file pages (default: 4096)");
- System.out.println(" --maxkeysize The maximum size for file keys (default: 0=none)");
- System.out.println();
-
- System.out.println("Actions:");
-
- // Show all elements with helpclass=document
- // Loop over the commands, printing test from description attribute
- for (int i = 0; i < list.getLength(); i++) {
- helpClass = ((Element) list.item(i)).getAttribute("helpclass");
-
- if (helpClass.equals("document")) {
- desc = ((Element) list.item(i)).getAttribute("description");
- cmdswitch = ((Element) list.item(i)).getAttribute("switch");
- System.out.println(" " + StringUtilities.leftJustify(cmdswitch, 13) + desc);
- }
- }
-
- // Loop over the commands, printing text from description attribute
- for (int i = 0; i < list.getLength(); i++) {
- helpClass = ((Element) list.item(i)).getAttribute("helpclass");
-
- if (helpClass.equals("security")) {
- desc = ((Element) list.item(i)).getAttribute("description");
- cmdswitch = ((Element) list.item(i)).getAttribute("switch");
- System.out.println(" " + StringUtilities.leftJustify(cmdswitch, 13) + desc);
- }
- }
-
- System.out.println();
- System.out.println("Examples:");
- System.out.println(" xindice ad -c /db/test -f /tmp/xmldocument -n myxmldocument");
- System.out.println(" xindice dd -c /db/test -n myxmldocument");
- System.out.println(" xindice rd -c /db/test/ocs -f a:\\file.xml -n file.xml");
- System.out.println(" xindice xpath -c /db/test/ocs -q test");
- System.out.println(" xindice xpath -c /db/test -s a=http://somedomain.com/schema.xsd -q /a:foo");
- System.out.println(" xindice xupdate -c /db/test -f /path/to/xupdate.xml");
- System.out.println(" xindice xupdate -c /db/test -n document-to-update.xml -f /path/to/xupdate.xml");
- System.out.println();
- System.out.println("For more information, please read the Xindice - Tools Reference Guide");
- System.out.println();
}
}
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddCollection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddCollection.java?view=diff&rev=473607&r1=473606&r2=473607
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddCollection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddCollection.java Fri Nov 10 16:58:03 2006
@@ -90,11 +90,13 @@
Element filEle = doc.createElement("filer");
filEle.setAttribute("class", "org.apache.xindice.core.filer.BTreeFiler");
if (table.containsKey(XMLTools.PAGE_SIZE)) {
- filEle.setAttribute("pagesize", (String) table.get(XMLTools.PAGE_SIZE));
+ filEle.setAttribute(XMLTools.PAGE_SIZE, (String) table.get(XMLTools.PAGE_SIZE));
}
-
if (table.containsKey(XMLTools.MAX_KEY_SIZE)) {
- filEle.setAttribute("maxkeysize", (String) table.get(XMLTools.MAX_KEY_SIZE));
+ filEle.setAttribute(XMLTools.MAX_KEY_SIZE, (String) table.get(XMLTools.MAX_KEY_SIZE));
+ }
+ if (table.containsKey(XMLTools.PAGE_COUNT)) {
+ filEle.setAttribute(XMLTools.PAGE_COUNT, (String) table.get(XMLTools.PAGE_COUNT));
}
colEle.appendChild(filEle);
Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddIndexer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddIndexer.java?view=diff&rev=473607&r1=473606&r2=473607
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddIndexer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/AddIndexer.java Fri Nov 10 16:58:03 2006
@@ -79,12 +79,15 @@
}
if (table.containsKey(XMLTools.PAGE_SIZE)) {
- idxEle.setAttribute("pagesize", (String) table.get(XMLTools.PAGE_SIZE));
+ idxEle.setAttribute(XMLTools.PAGE_SIZE, (String) table.get(XMLTools.PAGE_SIZE));
}
-
if (table.containsKey(XMLTools.MAX_KEY_SIZE)) {
- idxEle.setAttribute("maxkeysize", (String) table.get(XMLTools.MAX_KEY_SIZE));
+ idxEle.setAttribute(XMLTools.MAX_KEY_SIZE, (String) table.get(XMLTools.MAX_KEY_SIZE));
+ }
+ if (table.containsKey(XMLTools.PAGE_COUNT)) {
+ idxEle.setAttribute(XMLTools.PAGE_COUNT, (String) table.get(XMLTools.PAGE_COUNT));
}
+
// Add Element to the document
doc.appendChild(idxEle);
Added: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/HelpCommand.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/HelpCommand.java?view=auto&rev=473607
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/HelpCommand.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/HelpCommand.java Fri Nov 10 16:58:03 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 1999-2006 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.
+ *
+ * @author <a href="mailto:byrne@apache.org">Todd Byrne</a>
+ */
+package org.apache.xindice.tools.command;
+
+import java.util.Hashtable;
+
+import org.apache.xindice.server.Xindice;
+import org.apache.xindice.util.StringUtilities;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.apache.xindice.tools.XMLTools;
+
+public class HelpCommand extends Command {
+
+ public boolean execute(Hashtable table) throws Exception {
+ NodeList list = (NodeList)table.get(XMLTools.COMMAND_LIST);
+
+ // This method relies on two things to format the output for help
+ // Method isAdmin() - Tells us if this is an admin instance, used to hide certain output
+ // XML file Commands.xml attribute "helpclass" - used to order output
+
+ String helpClass; // Holds the helpclass for the current <command> node
+ String desc; // Holds the description for the current <command> node
+ String cmdswitch; // Holds the switch for the current <command> node
+
+
+ // Show the header and switch commands
+ System.out.println();
+ System.out.println("Xindice Command Tools v" + Xindice.Version);
+ System.out.println();
+ System.out.println("Format: xindice action [switch] [parameter]");
+ System.out.println();
+ System.out.println("Switches:");
+ System.out.println(" -c Collection context (must always be specified),");
+ System.out.println(" can be either canonical name of the collection");
+ System.out.println(" or complete xmldb URL");
+ System.out.println(" -e File extension for multiple documents");
+ System.out.println(" -f File path for document retrieval and storage");
+ System.out.println(" -n Name");
+ System.out.println(" -p Index pattern");
+ System.out.println(" -q Query string");
+ System.out.println(" -s Semi-colon delimited list of namespaces for query in ");
+ System.out.println(" the form prefix=namespace-uri");
+ System.out.println(" -l Use a local database rather then going over the network.");
+ System.out.println(" Should be combined with -d to specify the configuration to use.");
+ System.out.println(" -d Path to the database configuration to use for the local ");
+ System.out.println(" database. Only applies if -l is specified.");
+ System.out.println(" -t Specify the data type in collection index");
+ System.out.println(" -v Verbose");
+ System.out.println(" --pagesize Page size for file pages (default: 4096)");
+ System.out.println(" --maxkeysize The maximum size for file keys (default: 0=none)");
+ System.out.println(" --pagecount Number of pages in the primary storage (default: 1024)");
+ System.out.println();
+
+ System.out.println("Actions:");
+
+ // Show all elements with helpclass=document
+ // Loop over the commands, printing test from description attribute
+ for (int i = 0; i < list.getLength(); i++) {
+ helpClass = ((Element) list.item(i)).getAttribute("helpclass");
+
+ if (helpClass.equals("document")) {
+ desc = ((Element) list.item(i)).getAttribute("description");
+ cmdswitch = ((Element) list.item(i)).getAttribute("switch");
+ System.out.println(" " + StringUtilities.leftJustify(cmdswitch, 13) + desc);
+ }
+ }
+
+ // Loop over the commands, printing text from description attribute
+ for (int i = 0; i < list.getLength(); i++) {
+ helpClass = ((Element) list.item(i)).getAttribute("helpclass");
+
+ if (helpClass.equals("security")) {
+ desc = ((Element) list.item(i)).getAttribute("description");
+ cmdswitch = ((Element) list.item(i)).getAttribute("switch");
+ System.out.println(" " + StringUtilities.leftJustify(cmdswitch, 13) + desc);
+ }
+ }
+
+ System.out.println();
+ System.out.println("Examples:");
+ System.out.println(" xindice ad -c /db/test -f /tmp/xmldocument -n myxmldocument");
+ System.out.println(" xindice dd -c /db/test -n myxmldocument");
+ System.out.println(" xindice rd -c /db/test/ocs -f a:\\file.xml -n file.xml");
+ System.out.println(" xindice xpath -c /db/test/ocs -q test");
+ System.out.println(" xindice xpath -c /db/test -s a=http://somedomain.com/schema.xsd -q /a:foo");
+ System.out.println(" xindice xupdate -c /db/test -f /path/to/xupdate.xml");
+ System.out.println(" xindice xupdate -c /db/test -n document-to-update.xml -f /path/to/xupdate.xml");
+ System.out.println();
+ System.out.println("For more information, please read the Xindice - Tools Reference Guide");
+ System.out.println();
+ return true;
+ }
+
+}