You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/03/29 18:27:59 UTC

svn commit: r159388 - in lenya/trunk/src: java/org/apache/lenya/cms/site/usecases/EmptyTrash.java webapp/WEB-INF/cocoon-xconf.xsl webapp/lenya/usecases/admin/emptyTrash.jx webapp/lenya/usecases/admin/tabs.jx

Author: andreas
Date: Tue Mar 29 08:27:58 2005
New Revision: 159388

URL: http://svn.apache.org/viewcvs?view=rev&rev=159388
Log:
added EmptyTrash usecase

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java
    lenya/trunk/src/webapp/lenya/usecases/admin/emptyTrash.jx
Modified:
    lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
    lenya/trunk/src/webapp/lenya/usecases/admin/tabs.jx

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java?view=auto&rev=159388
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java Tue Mar 29 08:27:58 2005
@@ -0,0 +1,90 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.site.usecases;
+
+import java.util.Arrays;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.util.DocumentSet;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.usecase.AbstractUsecase;
+
+/**
+ * Empty the trash.
+ *
+ * @version $Id:$
+ */
+public class EmptyTrash extends AbstractUsecase {
+    
+    protected static final String DOCUMENTS = "documents";
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+     */
+    protected void initParameters() {
+        super.initParameters();
+        try {
+            Document[] documents = getTrashDocuments();
+            setParameter(DOCUMENTS, Arrays.asList(documents));
+        } catch (SiteException e) {
+            throw new RuntimeException(e);
+        } catch (PublicationException e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+        super.doExecute();
+        
+        DocumentManager documentManager = null;
+        try {
+            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+            Document[] documents = getTrashDocuments();
+            DocumentSet set = new DocumentSet(documents);
+            documentManager.delete(set);
+        }
+        finally {
+            if (documentManager != null) {
+                this.manager.release(documentManager);
+            }
+        }
+    }
+    
+    /**
+     * @return The documents in the trash area.
+     * @throws PublicationException if an error occurs.
+     * @throws SiteException if an error occurs.
+     */
+    protected Document[] getTrashDocuments() throws PublicationException, SiteException {
+        PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+        Publication publication = factory.getPublication(this.manager, getSourceURL());
+        DocumentIdentityMap identityMap = new DocumentIdentityMap();
+        
+        SiteManager siteManager = publication.getSiteManager();
+        Document[] documents = siteManager.getDocuments(identityMap, publication, Publication.TRASH_AREA);
+        return documents;
+    }
+}

Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?view=diff&r1=159387&r2=159388
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Tue Mar 29 08:27:58 2005
@@ -321,6 +321,11 @@
     <component-instance name="admin.ipRanges" logger="lenya.admin" class="org.apache.lenya.cms.ac.usecases.IPRanges">
       <view template="admin/ipRanges" menu="true"/>
     </component-instance>
+    <component-instance name="admin.emptyTrash" logger="lenya.admin" class="org.apache.lenya.cms.site.usecases.EmptyTrash">
+      <view template="admin/emptyTrash" menu="true">
+        <parameter name="tab" value="trash"/>
+      </view>
+    </component-instance>
 
     <!--
     <component-instance name="admin.addIPRange" logger="lenya.admin" class="org.apache.lenya.cms.ac.usecases.AddIPRange"/>

Added: lenya/trunk/src/webapp/lenya/usecases/admin/emptyTrash.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/admin/emptyTrash.jx?view=auto&rev=159388
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/admin/emptyTrash.jx (added)
+++ lenya/trunk/src/webapp/lenya/usecases/admin/emptyTrash.jx Tue Mar 29 08:27:58 2005
@@ -0,0 +1,29 @@
+<page:page
+  xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+  xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+  xmlns="http://www.w3.org/1999/xhtml"
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1"    
+  >
+  
+  <page:body>
+    <jx:import uri="admin/tabs.jx"/>
+    <div id="contentblock1" class="lenya-tab">
+    <h1><i18n:text>Delete Trash</i18n:text></h1>
+      
+    <jx:import uri="templates/messages.jx"/>
+    <p>
+    <strong><i18n:text>Documents in trash</i18n:text>:</strong>
+    </p>
+    <ul style="list-style-type: none">
+      <jx:forEach var="document" items="${usecase.getParameter('documents')}">
+        <li><jx:out value="${document.getId()}"/></li>
+      </jx:forEach>
+    </ul>
+    <form>
+      <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+      <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
+      <input i18n:attr="value" name="submit" type="submit" value="Empty"/>
+    </form>
+    </div>
+  </page:body>
+</page:page>
\ No newline at end of file

Modified: lenya/trunk/src/webapp/lenya/usecases/admin/tabs.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/admin/tabs.jx?view=diff&r1=159387&r2=159388
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/admin/tabs.jx (original)
+++ lenya/trunk/src/webapp/lenya/usecases/admin/tabs.jx Tue Mar 29 08:27:58 2005
@@ -63,7 +63,14 @@
         <jx:set var="urlPrefix" value="${contextPath + steps[1]}"/>
         
         <td>
-          <a class="lenya-tablink" href="/${urlPrefix}/admin/content.html"><i18n:text>Delete Trash</i18n:text></a>
+          <jx:choose>
+            <jx:when test="${usecase.getView().getParameter('tab').equals('trash')}">
+              <a href="?lenya.usecase=admin.emptyTrash" class="lenya-tablink-active"><i18n:text>Delete Trash</i18n:text></a>
+            </jx:when>
+            <jx:otherwise>
+              <a href="?lenya.usecase=admin.emptyTrash" class="lenya-tablink"><i18n:text>Delete Trash</i18n:text></a>
+            </jx:otherwise>
+          </jx:choose>
         </td>
         <td>
           <a class="lenya-tablink" href="/${urlPrefix}/admin/lucene.html"><i18n:text>Search</i18n:text></a>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org