kstaken 2003/08/05 01:47:00
Modified: config commands.xml java/src/org/apache/xindice/client/xmldb/xmlrpc CollectionImpl.java java/src/org/apache/xindice/tools XMLTools.java Added: java/src/org/apache/xindice/tools/command XUpdate.java Log: Adding an XUpdate command line tool. Supports running XUpdate against a full collection or a single file. The XUpdate commands are read from a file stored in the file system. The file is specified with -f and if a single document is being updated the name is specified with -n. Requires a collection context specified with -c. Revision Changes Path 1.5 +6 -1 xml-xindice/config/commands.xml Index: commands.xml =================================================================== RCS file: /home/cvs/xml-xindice/config/commands.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- commands.xml 2 Nov 2002 06:23:50 -0000 1.4 +++ commands.xml 5 Aug 2003 08:47:00 -0000 1.5 @@ -84,6 +84,11 @@ class="org.apache.xindice.tools.command.XPathQuery" helpclass="document" description="Queries a Collection using XPath" /> + <command switch="xupdate" + name="xupdate_query" + class="org.apache.xindice.tools.command.XUpdate" + helpclass="document" + description="Updates a Collection using XUpdate" /> <command switch="export" name="export" class="org.apache.xindice.tools.command.ExportTree" 1.28 +2 -2 xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java Index: CollectionImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- CollectionImpl.java 4 Aug 2003 03:01:57 -0000 1.27 +++ CollectionImpl.java 5 Aug 2003 08:47:00 -0000 1.28 @@ -636,7 +636,7 @@ return rs; } catch (Exception e) { - +e.printStackTrace(); throw FaultCodes.createXMLDBException(FaultCodes.QRY_PROCESSING_ERROR, "Query error", e); } } 1.20 +3 -1 xml-xindice/java/src/org/apache/xindice/tools/XMLTools.java Index: XMLTools.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/tools/XMLTools.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- XMLTools.java 4 Aug 2003 03:01:57 -0000 1.19 +++ XMLTools.java 5 Aug 2003 08:47:00 -0000 1.20 @@ -694,6 +694,8 @@ 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(); 1.1 xml-xindice/java/src/org/apache/xindice/tools/command/XUpdate.java Index: XUpdate.java =================================================================== package org.apache.xindice.tools.command; /* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xindice" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999-2001, The dbXML * Group, L.L.C., http://www.dbxmlgroup.com. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: XUpdate.java,v 1.1 2003/08/05 08:47:00 kstaken Exp $ */ import org.apache.xindice.tools.XMLTools; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.ResourceIterator; import org.xmldb.api.base.ResourceSet; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.XMLResource; import org.xmldb.api.modules.XUpdateQueryService; import java.util.Hashtable; import java.util.StringTokenizer; import java.io.File; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; /** * XUpdate runs an XUpdate query stored in a file against the specified collection or * document. * * @author Kimbro Staken <[EMAIL PROTECTED]> */ public class XUpdate extends Command { public boolean execute(Hashtable table) throws Exception { Collection col = null; try { if ((String) table.get(XMLTools.COLLECTION) == null) { System.out.println("ERROR : Collection name and switch required"); return false; } if ((String) 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); // Nomalize the collection URI String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION), (String) table.get(XMLTools.LOCAL)); // Read in the XUpdate commands from the file StringBuffer commands = new StringBuffer(); File file = new File((String) table.get(XMLTools.FILE_PATH)); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); String line; while ((line = reader.readLine()) != null) { commands.append(line); } reader.close(); // Get the collection reference for the requested collection col = DatabaseManager.getCollection(colstring); if (col == null) { System.out.println("ERROR : Collection not found!"); return false; } // To run XUpdate commands we use the XUpdateQueryService XUpdateQueryService service = null; service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0"); long result = 0; // See if we're updating one document or the whole collection. if (name == null) { result = service.update(commands.toString()); } else { 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")) { log.warn(e); } return false; } finally { if (col != null) { col.close(); } } return true; } }