From: Wolfgang M. M. <wol...@us...> - 2004-09-20 13:13:02
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30760/src/org/exist/client Modified Files: InteractiveClient.java Log Message: Index: InteractiveClient.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/client/InteractiveClient.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** InteractiveClient.java 8 Sep 2004 14:37:07 -0000 1.37 --- InteractiveClient.java 20 Sep 2004 13:12:52 -0000 1.38 *************** *** 85,88 **** --- 85,89 ---- import org.exist.util.serializer.SAXSerializer; import org.exist.util.serializer.SAXSerializerPool; + import org.exist.xmldb.CollectionManagementServiceImpl; import org.exist.xmldb.DatabaseInstanceManager; import org.exist.xmldb.IndexQueryService; *************** *** 578,586 **** } getResources(); } else if (args[0].equalsIgnoreCase("edit")) { if (args.length == 2) { editResource(args[1]); } else { ! messageln("Please give a resource name."); } } else if (args[0].equalsIgnoreCase("get")) { --- 579,595 ---- } getResources(); + } else if (args[0].equalsIgnoreCase("cp")) { + if (args.length != 3) { + messageln("cp requires two arguments."); + return true; + } + copy(args[1], args[2]); + getResources(); + } else if (args[0].equalsIgnoreCase("edit")) { if (args.length == 2) { editResource(args[1]); } else { ! messageln("Please specify a resource."); } } else if (args[0].equalsIgnoreCase("get")) { *************** *** 1327,1330 **** --- 1336,1364 ---- } + private final void copy(String source, String destination) throws XMLDBException { + CollectionManagementServiceImpl mgtService = (CollectionManagementServiceImpl) + current.getService("CollectionManagementService", "1.0"); + String destName = null; + Collection destCol = resolveCollection(destination); + if(destCol == null) { + int p = destination.lastIndexOf('/'); + if(p < 0) { + destName = destination; + destination = current.getName(); + } else { + destName = destination.substring(p + 1); + destination = destination.substring(0, p); + } + } + Resource srcDoc = resolveResource(source); + if(srcDoc != null) { + String resourcePath = srcDoc.getParentCollection().getName() + '/' + srcDoc.getId(); + messageln("Copying resource " + resourcePath + " to " + destination); + mgtService.copyResource(resourcePath, destination, destName); + } else + messageln("Copying collection " + source + " to " + destination); + mgtService.copy(source, destination, destName); + } + private final void reindex() throws XMLDBException { IndexQueryService service = (IndexQueryService) *************** *** 2300,2303 **** --- 2334,2361 ---- } + private Collection resolveCollection(String path) throws XMLDBException { + return DatabaseManager.getCollection(properties.getProperty("uri") + + path, properties.getProperty("user"), properties.getProperty("password")); + } + + private Resource resolveResource(String path) throws XMLDBException { + String collectionPath; + String resourceName = path; + int p = path.lastIndexOf('/'); + if(p < 0) { + collectionPath = current.getName(); + } else { + collectionPath = path.substring(0, p); + resourceName = path.substring(p + 1); + } + Collection collection = resolveCollection(collectionPath); + if(collection == null) { + messageln("Collection " + collectionPath + " not found."); + return null; + } + messageln("Locating resource " + resourceName + " in collection " + collection.getName()); + return collection.getResource(resourceName); + } + private String[] splitProperty(String key) { String value = properties.getProperty(key); *************** *** 2361,2365 **** os.write((byte[]) data); os.close(); ! } else { OutputStreamWriter writer = new OutputStreamWriter(os, Charset .forName(properties.getProperty("encoding"))); --- 2419,2423 ---- os.write((byte[]) data); os.close(); ! } else { OutputStreamWriter writer = new OutputStreamWriter(os, Charset .forName(properties.getProperty("encoding"))); |