Author: ajaquith
Date: Sat Jan 30 15:31:01 2010
New Revision: 904794
URL: http://svn.apache.org/viewvc?rev=904794&view=rev
Log:
dded convenience accessors getHistory() and getAttachments() to
AbstractPageActionBean so that subclasses can inherit them. This also means
template JSPs now have easy JSTL access to page history and attachments.
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AbstractPageActionBean.java
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AbstractPageActionBean.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AbstractPageActionBean.java?rev=904794&r1=904793&r2=904794&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AbstractPageActionBean.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AbstractPageActionBean.java
Sat Jan 30 15:31:01 2010
@@ -21,23 +21,73 @@
package org.apache.wiki.action;
+import java.util.Collections;
+import java.util.List;
+
+import net.sourceforge.stripes.action.DontBind;
import net.sourceforge.stripes.validation.Validate;
import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.attachment.AttachmentManager;
+import org.apache.wiki.content.PageNotFoundException;
+import org.apache.wiki.providers.ProviderException;
+import org.apache.wiki.util.PageTimeComparator;
/**
* Abstract {...@link WikiActionBean} subclass used by all ActionBeans that
use and
* process {...@link org.apache.wiki.api.WikiPage} objects bound to the
* <code>page</code> request parameter. In particular, this subclass contains
- * special processing logic that ensures that, the <code>page</code>
- * properties of this object and its related {...@link
org.apache.wiki.WikiContext}
- * are set to the same value. When {...@link #setPage(WikiPage)} is called by,
for
- * example, the Stripes controller, the underlying
+ * special processing logic that ensures that, the <code>page</code> properties
+ * of this object and its related {...@link org.apache.wiki.WikiContext} are
set to
+ * the same value. When {...@link #setPage(WikiPage)} is called by, for
example,
+ * the Stripes controller, the underlying
* {...@link
org.apache.wiki.ui.stripes.WikiActionBeanContext#setPage(WikiPage)}
* method is called also.
*/
public class AbstractPageActionBean extends AbstractActionBean
{
+ private List<WikiPage> m_attachments = null;
+
+ private List<WikiPage> m_history = null;
+
+ private PageTimeComparator HISTORY_COMPARATOR = new PageTimeComparator(
PageTimeComparator.Order.DESCENDING );
+
+ /**
+ * Lists the attachments for this WikiPage.
+ *
+ * @return the attachments, possibly as a zero-length list
+ * @throws ProviderException if the provider cannot fetch the history
+ */
+ @DontBind
+ public List<WikiPage> getAttachments() throws ProviderException
+ {
+ if( m_attachments == null )
+ {
+ AttachmentManager mgr =
getContext().getEngine().getAttachmentManager();
+ m_attachments = Collections.unmodifiableList( mgr.listAttachments(
getPage() ) );
+ }
+ return m_attachments;
+ }
+
+ /**
+ * Returns the page history.
+ *
+ * @return the history
+ * @throws ProviderException if the provider cannot fetch the history
+ * @throws PageNotFoundException if the page doesn't exist
+ */
+ @DontBind
+ public List<WikiPage> getHistory() throws ProviderException,
PageNotFoundException
+ {
+ if( m_history == null )
+ {
+ List<WikiPage> history =
getContext().getEngine().getVersionHistory( getPage().getName() );
+ Collections.sort( history, HISTORY_COMPARATOR );
+ m_history = Collections.unmodifiableList( history );
+ }
+ return m_history;
+ }
+
/**
* Returns the WikiPage; defaults to <code>null</code>.
*
@@ -51,8 +101,8 @@
/**
* Sets the WikiPage property for this ActionBean, and also sets the
* WikiActionBeanContext's page property to the same value by calling
- * {...@link
org.apache.wiki.ui.stripes.WikiActionBeanContext#setPage(WikiPage)}.
- * Note that because of the {...@link Validate} annotation, the
+ * {...@link
org.apache.wiki.ui.stripes.WikiActionBeanContext#setPage(WikiPage)}
+ * . Note that because of the {...@link Validate} annotation, the
* <code>page</code> field will be required by any executing event handler
* method. To change this property, subclasses should override this method
* and supply a <code>Validate( required = false )</code> annotation.