/** * Retrieve the name of the document this attachment belonged to. * * @return the name of the owner document, in the {@code Space.Document} format */ public String getDocName() { return this.deletedAttachment.getDocName(); }
@Override public DeletedAttachment next() { Long item = this.data.next(); try { DeletedAttachment result = HibernateDeletedAttachmentsReader.this.store.getDeletedAttachment( item, HibernateDeletedAttachmentsReader.this.context.get(), true); HibernateDeletedAttachmentsReader.this.logger.debug("Loaded [{}@{}#{}] from the database trash", result.getDocName(), result.getFilename(), result.getId()); return result; } catch (Exception ex) { HibernateDeletedAttachmentsReader.this.logger.error( "Failed to read deleted attachment from the database store: {}", ex.getMessage(), ex); } return null; }
@Override public DeletedAttachment next() { Long item = this.data.next(); try { DeletedAttachment result = HibernateDeletedAttachmentsReader.this.store.getDeletedAttachment( item, HibernateDeletedAttachmentsReader.this.context.get(), true); HibernateDeletedAttachmentsReader.this.logger.debug("Loaded [{}@{}#{}] from the database trash", result.getDocName(), result.getFilename(), result.getId()); return result; } catch (Exception ex) { HibernateDeletedAttachmentsReader.this.logger.error( "Failed to read deleted attachment from the database store: {}", ex.getMessage(), ex); } return null; }
@Override public boolean discardEntity(DeletedAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity); this.logger.debug("Deleted deleted attachment [{}@{}#{}] from the database trash", entity.getDocName(), entity.getFilename(), entity.getId()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@Override public boolean discardEntity(DeletedAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity); this.logger.debug("Deleted deleted attachment [{}@{}#{}] from the database trash", entity.getDocName(), entity.getFilename(), entity.getId()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@Override public boolean storeEntity(DeletedAttachment entity) { if (entity == null) { return true; } try { XWikiAttachment attachment = entity.restoreAttachment(null, this.context.get()); this.store.saveToRecycleBin(attachment, entity.getDeleter(), entity.getDate(), this.context.get(), false); this.logger.debug("Imported deleted attachment [{}@{}#{}] into the filesystem trash store", entity.getDocName(), entity.getFilename(), entity.getId()); return true; } catch (XWikiException ex) { this.logger.error("Failed to store deleted attachment into the filesystem store: {}", ex.getMessage(), ex); return false; } } }
@Override public boolean storeEntity(DeletedAttachment entity) { if (entity == null) { return true; } try { XWikiAttachment attachment = entity.restoreAttachment(null, this.context.get()); this.store.saveToRecycleBin(attachment, entity.getDeleter(), entity.getDate(), this.context.get(), false); this.logger.debug("Imported deleted attachment [{}@{}#{}] into the filesystem trash store", entity.getDocName(), entity.getFilename(), entity.getId()); return true; } catch (XWikiException ex) { this.logger.error("Failed to store deleted attachment into the filesystem store: {}", ex.getMessage(), ex); return false; } } }
/** * Restore a {@link XWikiAttachment} from a {@link DeletedAttachment}. Note that this method does not actually * restore the attachment to its owner document, it simply recomposes an {@link XWikiAttachment} object from the * saved data. * * @return restored attachment * @param attachment optional object where to put the attachment data, if not <code>null</code> * @param context the current {@link XWikiContext context} * @throws XWikiException If an exception occurs while the Attachment is restored from the XML. See * {@link XWikiAttachment#fromXML(String)}. */ public XWikiAttachment restoreAttachment(XWikiAttachment attachment, XWikiContext context) throws XWikiException { XWikiAttachment result = attachment; if (result == null) { result = new XWikiAttachment(); } result.fromXML(getXml()); if (result.getDoc() == null || !(this.getDocName().equals(result.getDoc().getFullName()))) { result.setDoc(context.getWiki().getDocument(this.getDocName(), context)); } return result; } }
+ "immediately after it has been deleted from the wiki"); if (!da.getDocName().equals(doc.getFullName())) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION,