On Jan 12, 2010, at 7:37 PM, tmortagne (SVN) wrote:
> Author: tmortagne
> Date: 2010-01-12 19:37:07 +0100 (Tue, 12 Jan 2010)
> New Revision: 26113
>
> Modified:
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
> Log:
> XWIKI-4744: DocumentDeleteEvent event does not come with proper user in the source document
>
> 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-12 18:29:37 UTC (rev 26112)
> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 2010-01-12 18:37:07 UTC (rev 26113)
> @@ -4105,6 +4105,8 @@
> if (om != null) {
> XWikiDocument blankDoc = new XWikiDocument(doc.getWikiName(), doc.getSpace(), doc.getName());
> blankDoc.setOriginalDocument(doc);
> + blankDoc.setAuthor(context.getUser());
> + blankDoc.setContentAuthor(context.getUser());
> om.notify(new DocumentDeleteEvent(doc.getWikiName() + ":" + doc.getFullName()), blankDoc, context);
hmmm I was wondering if setAuthor in delete event is correct or not. I think it's missing some comments to explain it.
Does it mean that we consider the deleted document as having been written by the user who's deleted it? (which doesn't make complete sense, does it?)
The source document should have the author as the original one I think, unless we consider the "source" as not representing the deleted document. But then what is it representing?
Thanks
-Vincent
Hello,
I'm looking at the grammar file for XWiki 2.0 syntax in wikimodel
and noticed that syntax on the following form is explicitly
allowed:
[[link containing [[image:image references]] in the text]]
From the javacc-file:
| <#REFERENCE_IMAGE: "[[image:" ("~" ~[] | ~["]"] | "]" ~["]"] )* "]]" >
| <#REFERENCE: ( "[[" ( <REFERENCE_IMAGE> | "~" ~[] | ~["]"] | "]"
~["]"] )* "]]" ) >
^^^^^^^^^^^^^^^
Why is this here?
I'm guessing that this is a mistake, or am I missing something?
Best regards,
/Andreas Jonsson
Hi
To develop the GBlog application I just took the XML from the Blog application and replace its content with mine. So far so good. But lately I see problems with Panels and I am not quite sure if this is related to duplicate GUID in the Panels Document or Object. So I have a few questions:
1) Where and by what is the GUID used?
2) How can I create GUIDs inside or outside of XWiki?
Cheers - Andy
Hi devs,
I committed a friendly UI for viewing the contents of the recycle bin
(just for documents, for the attachments there are some API changes
needed), and I was wondering where to put it. Right now it adds another
tab in the AllDocs wiki index, called "Deleted Documents", and I'm not
sure if it's the best thing to do.
+ it's one place where all the things in the wiki can be seen
+ it's easy to find
- the AllDocs page is getting crowded (another tab won't fit on small
displays)
- the recycle bin is not exactly a place with valid wiki documents
A possible improvement would be to rename the new tab to Trash and also
add the deleted attachments in there, as another table.
An alternative would be to add a new page similar to AllDocs, called
Trash, and which would have tabs for all the recycle bins. This could be
linked from the QuickLinks panel only for admins, and from the "This
document does not exist, there are versions in the [recycle bin]" message.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
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 {0}@{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
> notifications(a)xwiki.org
> http://lists.xwiki.org/mailman/listinfo/notifications
Hi,
Since we have failed the 2.2M1 release date I propose the following new schedule:
Original dates:
* 2.2M1: 28 Dec 2009
* 2.2M2: 18 Jan 2010
* 2.2RC1: 1st Feb 2010
* 2.2 RC2/Finale: 8 Feb 2010
New dates:
* 2.2M1: 11th of Jan (or 12th of Jan since Jean-Vincent is almost ready to include the new profile UI + new watchlist UI and he may need one day more)
* 2.2M2: 25th of Jan (one week more, i.e. 2 weeks in total - That's ok since we've almost done all planned stuff in 2.2M1 - see http://enterprise.xwiki.org/xwiki/bin/view/Main/Roadmap)
* 2.2RC1: 1st Feb
* 2.2 RC2/Finale: 8 Feb
Here's my +1
Thanks
-Vincent
Hi devs,
As I mentioned already I'm modifying all APIs in XWikiDocument to use References (I'm adding new APIs and deprecating old ones).
While doing this I'm also fixing names for new APIs. So far I'm modifying 3 things:
- replace Vector by List
- replace Object by XObject in API. For example: getxWikiObjects() --> getXObjects(), getObjects(String classname) --> getXObjects(DocumentReference classnameReference)
- replace Class by XClass in API. For example: getxWikiClasses --> getXClasses()
Note1: I wanted to use getObject and getClass but getClass is reserved already.
Note2: in the new model we won't have this problem since we'll intelligently use another name for object definitions, something like ObjectDefinition :). We could also change Object but it's less problematic and it's probably ok to keep it.
Here's my +1
Thanks
-Vincent
Hi Devs,
As the existing Wiki Importer ( GSOC PROJECT - SANDBOX
<http://svn.xwiki.org/svnroot/xwiki/sandbox/gsoc/importexport/>) have
few set backs in architecture, i would like to make a proposal to
modify and enhance to make it better.
Here is my proposal :
http://gsoc.myxwiki.org/xwiki/bin/view/Import+Export+other+wikis/Wiki+Impor…
- A new Wiki model api ( Wiki, Wiki Page, Wiki Page Revision, Wiki
Attachment ) which adheres to XWiki Standards.
- Separation of Import process, Parsing the import data into a abstract wiki
model will be a component. Clients can use it to make their own custom
implementation. This abstract model is used by the other XWiki component /
client code (Groovy & velocity ) to load the data into XWiki with standard
features and little customization (like Preserving history, default names,
attachments etc.. ).
- Using the existing XWiki model api or xwiki-bridge rather than coming up
with a new one.
But the issues here is, i dont have all the things which are needed and it
has lot more methods which are of no use in import process. Can i proceed
with a custom wiki model like this. ?
- As wiki importer process large streams of data, would it be wise to design
the API more stream oriented and include few stream oriented methods.?
I would like to have your suggestions on this.
Thanks
-Arun Reddy
This has been discussed on IRC but I wanted to send out an email before
creating a design proposal and JIRA issue.
Summary:
Actions need to be ported out of the old core into their own components.
It is important that the new Action model be in place so that newly added
actions do not have to be ported as well.
Current Situation:
There is an Action interface, an ActionManager, and an XWikiServlet which
work but design is not finished.
Use cases:
1. When a browser supports gzip compression, the response should be passed
through a discrete gzip Action component. However if the requested material
is already compressed (images), it should not be gzip'd.
2. If the user is not logged in and the action they are requesting does not
alter the database (Registration) the request should be passed to a cache Action.
If the cache contains the desired page then it is returned, otherwise it is passed
on to the requested action and when returned it is added to the cache.
3. If desired, a filter Action may catch requests depending on user agent, ip
address etc. And reroute the request. Banned!
I'd love to hear more use cases, I'll post this to the design proposal page
after I go for a walk.
Caleb James DeLisle
Hi devs,
In order to solve the ancient XWIKI-37 (Deleted attachments not
accessible via document history) and XWIKI-2254 (Attachment recycle
bin), we need an API for accessing and handling deleted attachments.
Note that the functionality already exists, it only needs to be
exposed.
I have implemented an API similar to the one for deleted documents:
(a) the class com.xpn.xwiki.api.DeletedAttachment:
- public DeletedAttachment(com.xpn.xwiki.doc.DeletedAttachment,
XWikiContext);
- public String getFilename();
- public String getDocName();
- public long getDocId();
- public Date getDate();
- public String getDeleter();
- public long getId();
- public boolean canUndelete();
- public boolean canDelete();
- public com.xpn.xwiki.doc.DeletedAttachment getDeletedAttachment();
- public Attachment getAttachment();
(b) 3 getDeletedAttachment(s) methods in com.xpn.xwiki.api.XWiki:
- public List<DeletedAttachment> getDeletedAttachments(String docName);
- public List<DeletedAttachment> getDeletedAttachments(String
docName, String filename);
- public DeletedAttachment getDeletedAttachment(String docName,
String filename, String id);
In addition, I need to find the right place for a delete() method.
Since there was no delete() method for deleted documents either, I'd
propose to:
(c) add delete() to the DeletedAttachment and DeletedDocument API classes.
The alternative is to add it to the XWiki class.
I know that the old API should rarely be changed, since it is going to
be replaced by the new model, but I think that this change is OK
because:
* I don't think the old API is going to be removed that soon
* The change is not dangerous because it only adds new stuff, and does
not modify or remove anything
* The added functionality is very similar to the existing one for
deleted documents, so it doesn't really add new stuff, it adds missing
stuff that should have already been there for a long time.
* It would be nice for our users to be able to manage deleted
attachments now, not much later when the new model is fully adopted.
To sum up, I'm +1 for:
1) adding the API for deleted attachments ( see above (a) and (b) )
2) adding a delete() method to the DeletedAttachment and
DeletedDocument API classes (c).
--
Sergiu Dumitriu
http://purl.org/net/sergiu/