From: Jean-Marc V. <jm...@us...> - 2004-07-09 09:19:42
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/collections In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21188/src/org/exist/collections Modified Files: Collection.java Log Message: Refactoring: extract method private void manageDocumentInformation(DBBroker broker, String name, DocumentImpl oldDoc, DocumentImpl document ) Index: Collection.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/collections/Collection.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Collection.java 5 Jul 2004 20:02:46 -0000 1.34 --- Collection.java 9 Jul 2004 09:19:32 -0000 1.35 *************** *** 733,737 **** Permission.UPDATE)) throw new PermissionDeniedException( ! "Document exists and update is not allowed"); if (!(getPermissions().validate(broker.getUser(), Permission.UPDATE) || getPermissions().validate(broker.getUser(), Permission.WRITE))) --- 733,737 ---- Permission.UPDATE)) throw new PermissionDeniedException( ! "Document \""+name+"\" exists and update is not allowed"); if (!(getPermissions().validate(broker.getUser(), Permission.UPDATE) || getPermissions().validate(broker.getUser(), Permission.WRITE))) *************** *** 743,760 **** throw new PermissionDeniedException( "Not allowed to write to collection " + getName()); ! // if an old document exists, save the new document with a temporary ! // document name ! if (oldDoc != null) { ! document = new DocumentImpl(broker, name, this); ! document.setCreated(oldDoc.getCreated()); ! document.setLastModified(System.currentTimeMillis()); ! document.setPermissions(oldDoc.getPermissions()); ! } else { ! document = new DocumentImpl(broker, name, this); ! document.setCreated(System.currentTimeMillis()); ! document.getPermissions().setOwner(broker.getUser()); ! document.getPermissions().setGroup( ! broker.getUser().getPrimaryGroup()); ! } // setup triggers Trigger trigger = null; --- 743,750 ---- throw new PermissionDeniedException( "Not allowed to write to collection " + getName()); ! ! document = new DocumentImpl(broker, name, this); ! manageDocumentInformation(broker, name, oldDoc, document ); ! // setup triggers Trigger trigger = null; *************** *** 890,893 **** --- 880,903 ---- } + /** If an old document exists, keep information about the document + * @param broker + * @param name + * @param oldDoc + * @param document + */ + private void manageDocumentInformation(DBBroker broker, String name, DocumentImpl oldDoc, + DocumentImpl document ) { + if (oldDoc != null) { + document.setCreated(oldDoc.getCreated()); + document.setLastModified(System.currentTimeMillis()); + document.setPermissions(oldDoc.getPermissions()); + } else { + document.setCreated(System.currentTimeMillis()); + document.getPermissions().setOwner(broker.getUser()); + document.getPermissions().setGroup( + broker.getUser().getPrimaryGroup()); + } + } + public DocumentImpl addDocument(DBBroker broker, String name, InputSource source) throws EXistException, LockException, *************** *** 932,949 **** "Not allowed to write to collection " + getName()); ! // if an old document exists, save the new document with a temporary ! // document name ! if (oldDoc != null) { ! document = new DocumentImpl(broker, name, this); ! document.setCreated(oldDoc.getCreated()); ! document.setLastModified(System.currentTimeMillis()); ! document.setPermissions(oldDoc.getPermissions()); ! } else { ! document = new DocumentImpl(broker, name, this); ! document.setCreated(System.currentTimeMillis()); ! document.getPermissions().setOwner(broker.getUser()); ! document.getPermissions().setGroup( ! broker.getUser().getPrimaryGroup()); ! } // setup triggers Trigger trigger = null; --- 942,948 ---- "Not allowed to write to collection " + getName()); ! document = new DocumentImpl(broker, name, this); ! manageDocumentInformation(broker, name, oldDoc, document ); ! // setup triggers Trigger trigger = null; *************** *** 1129,1148 **** throw new PermissionDeniedException( "not allowed to write to collection " + getName()); ! // if an old document exists, save the new document with a temporary ! // document name ! if (oldDoc != null) { ! document = new DocumentImpl(broker, name, ! this); ! document.setCreated(oldDoc.getCreated()); ! document.setLastModified(System.currentTimeMillis()); ! document.setPermissions(oldDoc.getPermissions()); ! } else { ! document = new DocumentImpl(broker, name, ! this); ! document.setCreated(System.currentTimeMillis()); ! document.getPermissions().setOwner(broker.getUser()); ! document.getPermissions().setGroup( ! broker.getUser().getPrimaryGroup()); ! } // setup triggers Trigger trigger = null; --- 1128,1135 ---- throw new PermissionDeniedException( "not allowed to write to collection " + getName()); ! ! document = new DocumentImpl(broker, name, this); ! manageDocumentInformation(broker, name, oldDoc, document ); ! // setup triggers Trigger trigger = null; *************** *** 1285,1304 **** blob = new BinaryDocument(broker, name, this); ! if (oldDoc != null) { ! blob.setCreated(oldDoc.getCreated()); ! blob.setLastModified(System.currentTimeMillis()); ! blob.setPermissions(oldDoc.getPermissions()); ! LOG.debug("removing old document " + oldDoc.getFileName()); ! if (oldDoc instanceof BinaryDocument) ! broker.removeBinaryResource((BinaryDocument) oldDoc); ! else ! broker.removeDocument(getName() + '/' + oldDoc.getFileName()); ! } else { ! blob.setCreated(System.currentTimeMillis()); ! blob.getPermissions().setOwner(broker.getUser()); ! blob.getPermissions().setGroup( ! broker.getUser().getPrimaryGroup()); } broker.storeBinaryResource(blob, data); addDocument(broker, blob); --- 1272,1302 ---- blob = new BinaryDocument(broker, name, this); ! // if (oldDoc != null) { ! // blob.setCreated(oldDoc.getCreated()); ! // blob.setLastModified(System.currentTimeMillis()); ! // blob.setPermissions(oldDoc.getPermissions()); ! // ! // LOG.debug("removing old document " + oldDoc.getFileName()); ! // if (oldDoc instanceof BinaryDocument) ! // broker.removeBinaryResource((BinaryDocument) oldDoc); ! // else ! // broker.removeDocument(getName() + '/' + oldDoc.getFileName()); ! // } else { ! // blob.setCreated(System.currentTimeMillis()); ! // blob.getPermissions().setOwner(broker.getUser()); ! // blob.getPermissions().setGroup( ! // broker.getUser().getPrimaryGroup()); ! // } ! manageDocumentInformation(broker, name, oldDoc, blob ); ! ! if (oldDoc != null) { ! LOG.debug("removing old document " + oldDoc.getFileName()); ! if (oldDoc instanceof BinaryDocument) ! broker.removeBinaryResource((BinaryDocument) oldDoc); ! else ! broker.removeDocument(getName() + '/' + oldDoc.getFileName()); } + broker.storeBinaryResource(blob, data); addDocument(broker, blob); |