From: Sebastian B. <bo...@us...> - 2004-08-29 18:14:36
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7466/src/org/exist/client Modified Files: InteractiveClient.java Log Message: add an "edit" command to the interactive client Index: InteractiveClient.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/client/InteractiveClient.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** InteractiveClient.java 7 Aug 2004 15:04:08 -0000 1.35 --- InteractiveClient.java 29 Aug 2004 18:14:26 -0000 1.36 *************** *** 21,24 **** --- 21,26 ---- package org.exist.client; + import java.awt.Cursor; + import java.awt.Dimension; import java.io.BufferedReader; import java.io.BufferedWriter; *************** *** 58,61 **** --- 60,64 ---- import java.util.TreeSet; + import javax.swing.JOptionPane; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; *************** *** 294,297 **** --- 297,301 ---- messageln("put [file pattern] upload file or directory" + " to the database"); + messageln("edit [resource] open the resource for editing"); messageln("mkcol collection create new sub-collection in " + "current collection"); *************** *** 574,577 **** --- 578,587 ---- } 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")) { if (args.length < 2) { *************** *** 1081,1084 **** --- 1091,1139 ---- /** + * @param args + */ + private void editResource(String name) { + try { + + final Resource res = retrieve(name, properties.getProperty( + OutputKeys.INDENT, "yes")); + DocumentView view = new DocumentView(getCollection(), res, properties); + view.setSize(new Dimension(640, 400)); + if (res.getResourceType().equals("XMLResource")) + view.setText((String) res.getContent()); + else + view.setText(new String((byte[]) res.getContent())); + + // lock the resource for editing + UserManagementService service = (UserManagementService) + current.getService("UserManagementService", "1.0"); + User user = service.getUser(properties.getProperty("user")); + String lockOwner = service.hasUserLock(res); + if((lockOwner == null) || (JOptionPane.showConfirmDialog(this.frame, + "Resource is already locked by user " + lockOwner + + ". Should I try to relock it?", + "Resource locked", + JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)) { + try { + service.lockResource(res, user); + } catch(XMLDBException ex) { + System.out.println(ex.getMessage()); + JOptionPane.showMessageDialog(this.frame, + "Resource cannot be locked. Opening read-only."); + view.setReadOnly(); + } + view.setVisible(true); + } else { + view.dispose(); + this.frame.setCursor(Cursor.getDefaultCursor()); + } + } catch (IllegalArgumentException ex) { + messageln("Illegal argument: " + ex.getMessage()); + } catch (XMLDBException ex) { + messageln("XMLDB error: " + ex.getMessage()); + } + } + + /** * @param String filename of the file that contains the schema */ |