Sergiu,
Please don't introduce new APIs using String instead of DocumentReference.
Thanks
-Vincent
On Jan 11, 2010, at 1:46 AM, sdumitriu (SVN) wrote:
> Author: sdumitriu
> Date: 2010-01-11 01:46:18 +0100 (Mon, 11 Jan 2010)
> New Revision: 26101
>
> Added:
>
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/DeletedAttachment.java
> Modified:
> platform/core/trunk/xwiki-core/pom.xml
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
>
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/DeletedAttachment.java
>
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAction.java
>
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
>
> platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties
> Log:
> XWIKI-4739: New APIs for accessing deleted attachments from the trash
> Done.
>
> XE-584: Attachment trash
> Added L10N resources.
>
> Modified: platform/core/trunk/xwiki-core/pom.xml
> ===================================================================
> --- platform/core/trunk/xwiki-core/pom.xml 2010-01-11 00:46:10 UTC (rev
> 26100)
> +++ platform/core/trunk/xwiki-core/pom.xml 2010-01-11 00:46:18 UTC (rev
> 26101)
> @@ -888,7 +888,9 @@
> <configuration>
> <includes>
> **/api/Api.java,
> + **/api/DeletedAttachment.java,
> **/api/User.java,
> + **/doc/DeletedAttachment.jave,
> **/xmlrpc/ConfluenceRpcInterface,
> **/xmlrpc/Attachment.java,
> **/xmlrpc/SpaceSummary.java,
> @@ -912,7 +914,9 @@
> **/*AttachmentVersioningStore.java,
> **/api/StatsService.java,
> **/stats/**/*.java,
> - **/store/hibernate/query/*.java
> + **/store/hibernate/query/*.java,
> + **/store/AttachmentRecycleBinStore.java,
> + **/store/hibernate/HibernateAttachmentRecycleBinStore.java
> </includes>
> <excludes>
> **/RenamePageReplaceLinkHandler.java,
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
> ===================================================================
> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
> 2010-01-11 00:46:10 UTC (rev 26100)
> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -69,6 +69,7 @@
> import org.apache.commons.httpclient.util.URIUtil;
> import org.apache.commons.lang.RandomStringUtils;
> import org.apache.commons.lang.StringUtils;
> +import org.apache.commons.lang.math.NumberUtils;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.commons.net.smtp.SMTPClient;
> @@ -100,6 +101,7 @@
> import com.xpn.xwiki.api.Document;
> import com.xpn.xwiki.api.User;
> import com.xpn.xwiki.criteria.api.XWikiCriteriaService;
> +import com.xpn.xwiki.doc.DeletedAttachment;
> import com.xpn.xwiki.doc.XWikiAttachment;
> import com.xpn.xwiki.doc.XWikiAttachmentArchive;
> import com.xpn.xwiki.doc.XWikiDeletedDocument;
> @@ -1423,6 +1425,7 @@
> /**
> * @deprecated since 2.2M1 use {...@link #getDocument(DocumentReference,
> XWikiContext)} instead
> */
> + @Deprecated
> public XWikiDocument getDocument(String fullname, XWikiContext context)
> throws XWikiException
> {
> XWikiDocument doc = new XWikiDocument();
> @@ -1433,6 +1436,7 @@
> /**
> * @deprecated since 2.2M1 use {...@link #getDocument(DocumentReference,
> XWikiContext)} instead
> */
> + @Deprecated
> public XWikiDocument getDocument(String web, String fullname,
> XWikiContext context) throws XWikiException
> {
> int i1 = fullname.lastIndexOf(".");
> @@ -1528,6 +1532,69 @@
> }
> }
>
> + /**
> + * Retrieve all the deleted attachments that belonged to a certain
> document. Note that this does not distinguish
> + * between different incarnations of a document name, and it does not
> require that the document still exists, it
> + * returns all the attachments that at the time of their deletion had a
> document with the specified name as their
> + * owner.
> + *
> + * @param docName the {...@link XWikiDocument#getFullName() name} of the
> owner document
> + * @param context the current request context
> + * @return A list with all the deleted attachments which belonged to the
> specified document. If no such attachments
> + * are found in the trash, an empty list is returned.
> + * @throws XWikiException if an error occurs while loading the
> attachments
> + */
> + public List<DeletedAttachment> getDeletedAttachments(String docName,
> XWikiContext context) throws XWikiException
> + {
> + if (hasAttachmentRecycleBin(context)) {
> + XWikiDocument doc = new XWikiDocument();
> + doc.setFullName(docName, context);
> + return
> getAttachmentRecycleBinStore().getAllDeletedAttachments(doc, context, true);
> + }
> + return null;
> + }
> +
> + /**
> + * Retrieve all the deleted attachments that belonged to a certain
> document and had the specified name. Multiple
> + * versions can be returned since the same file can be uploaded and
> deleted several times, creating different
> + * instances in the trash. Note that this does not distinguish between
> different incarnations of a document name,
> + * and it does not require that the document still exists, it returns
> all the attachments that at the time of their
> + * deletion had a document with the specified name as their owner.
> + *
> + * @param docName the {...@link DeletedAttachment#getDocName() name of
> the document} the attachment belonged to
> + * @param filename the {...@link DeletedAttachment#getFilename() name}
> of the attachment to search for
> + * @param context the current request context
> + * @return A list with all the deleted attachments which belonged to the
> specified document and had the specified
> + * filename. If no such attachments are found in the trash, an
> empty list is returned.
> + * @throws XWikiException if an error occurs while loading the
> attachments
> + */
> + public List<DeletedAttachment> getDeletedAttachments(String docName,
> String filename, XWikiContext context)
> + throws XWikiException
> + {
> + if (hasAttachmentRecycleBin(context)) {
> + XWikiDocument doc = new XWikiDocument();
> + doc.setFullName(docName, context);
> + XWikiAttachment attachment = new XWikiAttachment(doc, filename);
> + return
> getAttachmentRecycleBinStore().getAllDeletedAttachments(attachment, context,
> true);
> + }
> + return null;
> + }
> +
> + /**
> + * Retrieve a specific attachment from the trash.
> + *
> + * @param id the unique identifier of the entry in the trash
> + * @return specified attachment from the trash, {...@code null} if not
> found
> + * @throws XWikiException if an error occurs while loading the
> attachments
> + */
> + public DeletedAttachment getDeletedAttachment(String id, XWikiContext
> context) throws XWikiException
> + {
> + if (hasAttachmentRecycleBin(context)) {
> + return
> getAttachmentRecycleBinStore().getDeletedAttachment(NumberUtils.toInt(id),
> context, true);
> + }
> + return null;
> + }
> +
> public XWikiRenderingEngine getRenderingEngine()
> {
> return this.renderingEngine;
> @@ -5601,7 +5668,7 @@
> /**
> * @return the cache factory creating local caches.
> * @since 1.5M2.
> - * @deprecated Since 1.7M1, use {...@link CacheManager} component
> instead using {...@link Utils#getComponent(Class)}
> + * @deprecated Since 1.7M1, use {...@link CacheManager} component
> instead using {...@link Utils#getComponent(Class)}
> */
> @Deprecated
> public CacheFactory getLocalCacheFactory()
>
> Added:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/DeletedAttachment.java
> ===================================================================
> ---
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/DeletedAttachment.java
> (rev 0)
> +++
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/DeletedAttachment.java
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -0,0 +1,219 @@
> +/*
> + * See the NOTICE file distributed with this work for additional
> + * information regarding copyright ownership.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package com.xpn.xwiki.api;
> +
> +import java.util.Calendar;
> +import java.util.Date;
> +
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +
> +import com.xpn.xwiki.XWikiConfig;
> +import com.xpn.xwiki.XWikiContext;
> +import com.xpn.xwiki.XWikiException;
> +import com.xpn.xwiki.doc.XWikiDocument;
> +import com.xpn.xwiki.util.Programming;
> +
> +/**
> + * Information about a deleted attachment in the recycle bin. Note that this
> does not hold much information about the
> + * real attachment, but only meta-information relevant to the trash:
> original document and filename, deleter, deletion
> + * date. The attachment can be accessed using {...@link #getAttachment()}.
> + * <p>
> + * This object is immutable, since entries in the trash can not be modified.
> + * </p>
> + *
> + * @version $Id$
> + * @since 2.2M1
> + */
> +public class DeletedAttachment extends Api
> +{
> + /** Logging helper object. */
> + private static final Log LOG =
> LogFactory.getLog(DeletedAttachment.class);
> +
> + /** The internal object wrapped by this API. */
> + private final com.xpn.xwiki.doc.DeletedAttachment deletedAttachment;
> +
> + /**
> + * Simple constructor, initializes a new API object with the current
> {...@link com.xpn.xwiki.XWikiContext context} and
> + * the specified protected {...@link com.xpn.xwiki.doc.DeletedAttachment
> deleted attachment} object.
> + *
> + * @param deletedAttachment the internal object wrapped by this API
> + * @param context the current request context
> + */
> + public DeletedAttachment(com.xpn.xwiki.doc.DeletedAttachment
> deletedAttachment, XWikiContext context)
> + {
> + super(context);
> + this.deletedAttachment = deletedAttachment;
> + }
> +
> + /**
> + * Retrieve the internal entry index, used to uniquely identify this
> entity in the trash. This is needed because a
> + * file can be attached and deleted multiple times, so the document name
> and filename are not enough to uniquely
> + * identify a deleted attachment.
> + *
> + * @return internal identifier of the corresponding trash entry
> + */
> + public long getId()
> + {
> + return this.deletedAttachment.getId();
> + }
> +
> + /**
> + * Retrieve the original name of this attachment.
> + *
> + * @return the original filename, for example {...@code MyPhoto.png}
> + */
> + public String getFilename()
> + {
> + return this.deletedAttachment.getFilename();
> + }
> +
> + /**
> + * 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();
> + }
> +
> + /**
> + * Retrieve the name of the user who deleted this attachment.
> + *
> + * @return the user who deleted the attachment, as its document name
> (e.g. {...@code XWiki.Admin})
> + */
> + public String getDeleter()
> + {
> + return this.deletedAttachment.getDeleter();
> + }
> +
> + /**
> + * Retrieve the date and time this attachment has been deleted.
> + *
> + * @return the date of the deletion
> + */
> + public Date getDate()
> + {
> + return this.deletedAttachment.getDate();
> + }
> +
> + /**
> + * Access to the real attachment object.
> + *
> + * @return the attachment as it was before being deleted, and as it
> currently is in the recycle bin
> + */
> + public Attachment getAttachment()
> + {
> + try {
> + Document doc = this.context.getWiki().getDocument(getDocName(),
> this.context).newDocument(this.context);
> + return new Attachment(doc,
> this.deletedAttachment.restoreAttachment(null, this.context), this.context);
> + } catch (XWikiException ex) {
> + LOG.warn("Failed to parse deleted attachment: " +
> ex.getMessage(), ex);
> + return null;
> + }
> + }
> +
> + /**
> + * Privileged access to the internal object wrapped by this API.
> + *
> + * @return original deleted attachment if the current user has
> programming rights, else {...@code null}.
> + */
> + @Programming
> + public com.xpn.xwiki.doc.DeletedAttachment getDeletedAttachment()
> + {
> + if (hasProgrammingRights()) {
> + return this.deletedAttachment;
> + } else {
> + return null;
> + }
> + }
> +
> + /**
> + * Check if the current user has the right to restore the attachment.
> + *
> + * @return {...@code true} if the current user can restore this
> document, {...@code false} otherwise
> + */
> + public boolean canRestore()
> + {
> + // FIXME Temporary disabled until this action is implemented.
> + // As a workaround, the attachment can be downloaded and re-attached.
> + return false;
> + }
> +
> + /**
> + * Check if the current user has the right to permanently delete the
> attachment from the trash.
> + *
> + * @return {...@code true} if the current user can purge this document,
> {...@code false} otherwise
> + * @xwikicfg xwiki.store.recyclebin.adminWaitDays How many days should
> an administrator wait before being able to
> + * permanently delete this document from the recycle bin. 0 by
> default.
> + * @xwikicfg xwiki.store.recyclebin.waitDays How many days should a
> normal user with "delete" right wait before
> + * being able to permanently delete this document from the
> recycle bin. 7 by default.
> + */
> + public boolean canDelete()
> + {
> + try {
> + XWikiDocument doc = new XWikiDocument();
> + doc.setFullName(getDocName(), this.context);
> + if (!hasAdminRights()
> + &&
> !getXWikiContext().getWiki().getRightService().checkAccess("delete", doc,
> this.context)) {
> + return false;
> + }
> + String waitdays;
> + XWikiConfig config = getXWikiContext().getWiki().getConfig();
> + if (hasAdminRights()) {
> + waitdays =
> config.getProperty("xwiki.store.recyclebin.adminWaitDays", "0");
> + } else {
> + waitdays =
> config.getProperty("xwiki.store.recyclebin.waitDays", "7");
> + }
> + int seconds = (int) (Double.parseDouble(waitdays) * 24 * 60 * 60
> + 0.5);
> + Calendar cal = Calendar.getInstance();
> + cal.setTime(getDate());
> + cal.add(Calendar.SECOND, seconds);
> + return cal.before(Calendar.getInstance());
> + } catch (Exception ex) {
> + // Public APIs should not throw exceptions
> + LOG.warn("Exception while checking if entry [" + getId() + "]
> can be removed from the recycle bin", ex);
> + return false;
> + }
> + }
> +
> + /**
> + * Permanently delete this attachment from the trash. Throws an access
> denied exception if the user does not have
> + * the right to perform this action, which will trigger the generic
> Access Denied message. Any other failures will
> + * be silently ignored.
> + *
> + * @throws XWikiException if the user does not have the right to perform
> this action
> + */
> + public void delete() throws XWikiException
> + {
> + if (this.canDelete()) {
> + try {
> +
> this.context.getWiki().getAttachmentRecycleBinStore().deleteFromRecycleBin(getId(),
> this.context, true);
> + } catch (Exception ex) {
> + LOG.warn("Failed to purge deleted attachment", ex);
> + }
> + } else {
> + java.lang.Object[] args = {this.getFilename(),
> this.getDocName()};
> + throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS,
> XWikiException.ERROR_XWIKI_ACCESS_DENIED,
> + "Cannot permanently delete attachment {...@{1} from the
> trash", null, args);
> + }
> + }
> +}
>
>
> Property changes on:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/DeletedAttachment.java
> ___________________________________________________________________
> Name: svn:keywords
> + Author Id Revision HeadURL
> Name: svn:eol-style
> + native
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
> ===================================================================
> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
> 2010-01-11 00:46:10 UTC (rev 26100)
> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -30,6 +30,7 @@
> import org.apache.commons.logging.LogFactory;
> import org.suigeneris.jrcs.diff.delta.Chunk;
> import org.xwiki.query.QueryManager;
> +import org.xwiki.rendering.renderer.PrintRendererFactory;
> import org.xwiki.rendering.syntax.Syntax;
>
> import com.xpn.xwiki.XWikiContext;
> @@ -41,14 +42,16 @@
> import com.xpn.xwiki.plugin.query.XWikiQuery;
> import com.xpn.xwiki.stats.impl.DocumentStats;
> import com.xpn.xwiki.user.api.XWikiUser;
> +import com.xpn.xwiki.util.Programming;
> import com.xpn.xwiki.web.Utils;
> import com.xpn.xwiki.web.XWikiEngineContext;
> -import org.xwiki.rendering.renderer.PrintRendererFactory;
>
> public class XWiki extends Api
> {
> + /** Logging helper object. */
> protected static final Log LOG = LogFactory.getLog(XWiki.class);
>
> + /** The internal object wrapped by this API. */
> private com.xpn.xwiki.XWiki xwiki;
>
> /**
> @@ -77,10 +80,11 @@
> }
>
> /**
> - * Priviledge API allowing to access the underlying main XWiki Object
> + * Privileged API allowing to access the underlying main XWiki Object
> *
> - * @return Priviledged Main XWiki Object
> + * @return Privileged Main XWiki Object
> */
> + @Programming
> public com.xpn.xwiki.XWiki getXWiki()
> {
> if (hasProgrammingRights()) {
> @@ -165,8 +169,87 @@
> }
>
> /**
> - * Returns wether a document exists or not
> + * Retrieve all the deleted attachments that belonged to a certain
> document. Note that this does not distinguish
> + * between different incarnations of a document name, and it does not
> require that the document still exists, it
> + * returns all the attachments that at the time of their deletion had a
> document with the specified name as their
> + * owner.
> *
> + * @param docName the {...@link XWikiDocument#getFullName() name} of the
> owner document
> + * @return A list with all the deleted attachments which belonged to the
> specified document. If no such attachments
> + * are found in the trash, an empty list is returned.
> + */
> + public List<DeletedAttachment> getDeletedAttachments(String docName)
> + {
> + try {
> + List<com.xpn.xwiki.doc.DeletedAttachment> attachments =
> + this.xwiki.getDeletedAttachments(docName, this.context);
> + if (attachments == null || attachments.isEmpty()) {
> + attachments = Collections.emptyList();
> + }
> + List<DeletedAttachment> result = new
> ArrayList<DeletedAttachment>(attachments.size());
> + for (com.xpn.xwiki.doc.DeletedAttachment attachment :
> attachments) {
> + result.add(new DeletedAttachment(attachment, this.context));
> + }
> + return result;
> + } catch (Exception ex) {
> + LOG.warn("Failed to retrieve deleted attachments", ex);
> + }
> + return Collections.emptyList();
> + }
> +
> + /**
> + * Retrieve all the deleted attachments that belonged to a certain
> document and had the specified name. Multiple
> + * versions can be returned since the same file can be uploaded and
> deleted several times, creating different
> + * instances in the trash. Note that this does not distinguish between
> different incarnations of a document name,
> + * and it does not require that the document still exists, it returns
> all the attachments that at the time of their
> + * deletion had a document with the specified name as their owner.
> + *
> + * @param docName the {...@link DeletedAttachment#getDocName() name of
> the document} the attachment belonged to
> + * @param filename the {...@link DeletedAttachment#getFilename() name}
> of the attachment to search for
> + * @return A list with all the deleted attachments which belonged to the
> specified document and had the specified
> + * filename. If no such attachments are found in the trash, an
> empty list is returned.
> + */
> + public List<DeletedAttachment> getDeletedAttachments(String docName,
> String filename)
> + {
> + try {
> + List<com.xpn.xwiki.doc.DeletedAttachment> attachments =
> + this.xwiki.getDeletedAttachments(docName, filename,
> this.context);
> + if (attachments == null) {
> + attachments = Collections.emptyList();
> + }
> + List<DeletedAttachment> result = new
> ArrayList<DeletedAttachment>(attachments.size());
> + for (com.xpn.xwiki.doc.DeletedAttachment attachment :
> attachments) {
> + result.add(new DeletedAttachment(attachment, this.context));
> + }
> + return result;
> + } catch (Exception ex) {
> + LOG.warn("Failed to retrieve deleted attachments", ex);
> + }
> + return Collections.emptyList();
> + }
> +
> + /**
> + * Retrieve a specific attachment from the trash.
> + *
> + * @param id the unique identifier of the entry in the trash
> + * @return specified attachment from the trash, {...@code null} if not
> found
> + */
> + public DeletedAttachment getDeletedAttachment(String id)
> + {
> + try {
> + com.xpn.xwiki.doc.DeletedAttachment attachment =
> this.xwiki.getDeletedAttachment(id, this.context);
> + if (attachment != null) {
> + return new DeletedAttachment(attachment, this.context);
> + }
> + } catch (Exception ex) {
> + LOG.warn("Failed to retrieve deleted attachment", ex);
> + }
> + return null;
> + }
> +
> + /**
> + * Returns whether a document exists or not
> + *
> * @param fullname Fullname of the XWiki document to be loaded
> * @return true if the document exists, false if not
> * @throws XWikiException
> @@ -2643,7 +2726,7 @@
> */
> public QueryManager getQueryManager()
> {
> - return (QueryManager) Utils.getComponent(QueryManager.class,
> "secure");
> + return Utils.getComponent(QueryManager.class, "secure");
> }
>
> /**
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/DeletedAttachment.java
> ===================================================================
> ---
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/DeletedAttachment.java
> 2010-01-11 00:46:10 UTC (rev 26100)
> +++
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/DeletedAttachment.java
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -158,7 +158,7 @@
> /**
> * Setter for {...@link #filename}.
> *
> - * @param filename The attachment filename. Used only by hibernate.
> + * @param filename The attachment filename to set. Used only by
> hibernate.
> */
> protected void setFilename(String filename)
> {
> @@ -178,7 +178,7 @@
> /**
> * Setter for {...@link #date}.
> *
> - * @param date The date of delete action to set. Used only by Hibernate.
> + * @param date The date of the delete action to set. Used only by
> Hibernate.
> */
> protected void setDate(Date date)
> {
> @@ -188,7 +188,7 @@
> /**
> * Getter for {...@link #deleter}.
> *
> - * @return The user which has removed the document.
> + * @return the user who deleted the attachment, as its document name
> (e.g. {...@code XWiki.Admin})
> */
> public String getDeleter()
> {
> @@ -228,9 +228,9 @@
> /**
> * Export {...@link XWikiAttachment} to {...@link DeletedAttachment}.
> *
> - * @param doc Deleted attachment.
> - * @param context The current context. Used in the XML export.
> - * @throws XWikiException If an exception occurs during the XML export.
> + * @param attachment the deleted attachment
> + * @param context the current context, used in the XML export
> + * @throws XWikiException if an exception occurs during the XML export
> */
> protected void setAttachment(XWikiAttachment attachment, XWikiContext
> context) throws XWikiException
> {
> @@ -238,11 +238,13 @@
> }
>
> /**
> - * Restore a {...@link XWikiAttachment} from a {...@link
> DeletedAttachment}.
> + * 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 attachment object to restore, if not
> <code>null</code>.
> - * @param context The current {...@link XWikiContext context}.
> + * @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)}.
> */
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAction.java
> ===================================================================
> ---
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAction.java
> 2010-01-11 00:46:10 UTC (rev 26100)
> +++
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAction.java
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -67,8 +67,14 @@
> if (!ddapi.canDelete()) {
> throw new
> XWikiException(XWikiException.MODULE_XWIKI_ACCESS,
> XWikiException.ERROR_XWIKI_ACCESS_DENIED,
> - "You can't delete from recycle bin before some time
> has passed");
> + "You are not allowed to delete a document from the
> trash "
> + + "immediately after it has been deleted from
> the wiki");
> }
> + if (!dd.getFullName().equals(doc.getFullName())) {
> + throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> + XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION,
> + "The specified trash entry does not match the
> current document");
> + }
> xwiki.getRecycleBinStore().deleteFromRecycleBin(doc, index,
> context, true);
> }
> sendRedirect(response, Utils.getRedirect("view", context));
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
> ===================================================================
> ---
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
> 2010-01-11 00:46:10 UTC (rev 26100)
> +++
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -21,21 +21,58 @@
>
> import java.util.ArrayList;
>
> +import org.apache.commons.lang.math.NumberUtils;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +
> +import com.xpn.xwiki.XWiki;
> import com.xpn.xwiki.XWikiContext;
> import com.xpn.xwiki.XWikiException;
> +import com.xpn.xwiki.doc.DeletedAttachment;
> import com.xpn.xwiki.doc.XWikiAttachment;
> import com.xpn.xwiki.doc.XWikiDocument;
> import com.xpn.xwiki.util.Util;
>
> public class DeleteAttachmentAction extends XWikiAction
> {
> + private static final Log LOG =
> LogFactory.getLog(DeleteAttachmentAction.class);
> +
> + @Override
> public boolean action(XWikiContext context) throws XWikiException
> {
> XWikiRequest request = context.getRequest();
> XWikiResponse response = context.getResponse();
> XWikiDocument doc = context.getDoc();
> XWikiAttachment attachment = null;
> + XWiki xwiki = context.getWiki();
> String filename;
> +
> + // Delete from the trash
> + if (request.getParameter("trashId") != null) {
> + long trashId =
> NumberUtils.toLong(request.getParameter("trashId"));
> + DeletedAttachment da =
> xwiki.getAttachmentRecycleBinStore().getDeletedAttachment(trashId, context,
> true);
> + // If the attachment hasn't been previously deleted (i.e. it's
> not in the deleted attachment store) then
> + // don't try to delete it and instead redirect to the attachment
> list.
> + if (da != null) {
> + com.xpn.xwiki.api.DeletedAttachment daapi = new
> com.xpn.xwiki.api.DeletedAttachment(da, context);
> + if (!daapi.canDelete()) {
> + throw new
> XWikiException(XWikiException.MODULE_XWIKI_ACCESS,
> + XWikiException.ERROR_XWIKI_ACCESS_DENIED,
> + "You are not allowed to delete an attachment from
> the trash "
> + + "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,
> + "The specified trash entry does not match the
> current document");
> + }
> + // TODO: Add a confirmation check
> +
> xwiki.getAttachmentRecycleBinStore().deleteFromRecycleBin(trashId, context,
> true);
> + }
> + sendRedirect(response, Utils.getRedirect("attach", context));
> + return false;
> + }
> +
> if (context.getMode() == XWikiContext.MODE_PORTLET) {
> filename = request.getParameter("filename");
> } else {
> @@ -49,7 +86,7 @@
>
> // An attachment can be indicated either using an id, or using the
> filename.
> if (request.getParameter("id") != null) {
> - int id = Integer.parseInt(request.getParameter("id"));
> + int id = NumberUtils.toInt(request.getParameter("id"));
> attachment = newdoc.getAttachmentList().get(id);
> } else {
> attachment = newdoc.getAttachment(filename);
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties
> ===================================================================
> ---
> platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties
> 2010-01-11 00:46:10 UTC (rev 26100)
> +++
> platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties
> 2010-01-11 00:46:18 UTC (rev 26101)
> @@ -1893,6 +1893,23 @@
> xe.index.trash.documents.delete.failed=Failed to delete:
> xe.index.trash.documents.deleteInformation=Deleted by {0} on {1}
>
> +xe.index.attachmentsTrash=Deleted Attachments
> +xe.index.trash.attachments.empty=No deleted attachments
> +xe.index.trash.attachments.datt.filename=Attachment
> +xe.index.trash.attachments.datt.docName=Document
> +xe.index.trash.attachments.datt.date=Deleted on
> +xe.index.trash.attachments.datt.deleter=Deleted by
> +xe.index.trash.attachments.actions=
> +xe.index.trash.attachments.actions.restore.tooltip=Restore attachment
> +xe.index.trash.attachments.actions.restore.text=[restore]
> +xe.index.trash.attachments.actions.cannotRestore.tooltip=The attachment
> cannot be restored to its original location because another file with the
> same name has been attached
> +xe.index.trash.attachments.actions.cannotRestore.text=[cannot restore]
> +xe.index.trash.attachments.actions.delete.tooltip=Permanently delete
> attachment
> +xe.index.trash.attachments.actions.delete.text=[delete]
> +xe.index.trash.attachments.delete.inProgress=Permanently deleting
> attachment...
> +xe.index.trash.attachments.delete.done=Attachment permanently deleted
> +xe.index.trash.attachments.delete.failed=Failed to delete:
> +
> xe.document.copy=Copy a document
> xe.document.copying=Copying document {0} to {1}
> xe.document.copy.source=Source Document:
>
> _______________________________________________
> notifications mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/notifications
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs