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/02/23 19:09:11 UTC
svn commit: r155040 - in lenya/trunk/src/webapp/lenya: pubs/default/config/
pubs/default/config/menus/
pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/
pubs/default/lenya/usecases/workflow/ resources/i18n/
Author: andreas
Date: Wed Feb 23 10:09:08 2005
New Revision: 155040
URL: http://svn.apache.org/viewcvs?view=rev&rev=155040
Log:
publish and deactivate implemented using usecase framework
Added:
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/deactivate.jx
Modified:
lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp
lenya/trunk/src/webapp/lenya/pubs/default/config/usecases.xconf
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/publish.jx
lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml
Modified: lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp?view=diff&r1=155039&r2=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp Wed Feb 23 10:09:08 2005
@@ -244,8 +244,8 @@
<block>
<item uc:usecase="workflow.submit" wf:event="submit" href="?"><i18n:text>Submit</i18n:text></item>
<item uc:usecase="workflow.reject" wf:event="reject" href="?"><i18n:text>Reject</i18n:text></item>
- <item uc:usecase="workflow.publish" wf:event="publish" href="?"><i18n:text>Publish</i18n:text></item>
- <item uc:usecase="deactivate" uc:step="showscreen" wf:event="deactivate" href="?task-id=deactivateDocument"><i18n:text>Deactivate</i18n:text></item>
+ <item uc:usecase="workflow.publish" href="?"><i18n:text>Publish</i18n:text></item>
+ <item uc:usecase="workflow.deactivate" href="?"><i18n:text>Deactivate</i18n:text></item>
</block><block>
<item uc:usecase="schedule" uc:step="showscreen" href="?"><i18n:text>Schedule</i18n:text></item>
</block>
Modified: lenya/trunk/src/webapp/lenya/pubs/default/config/usecases.xconf
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/usecases.xconf?view=diff&r1=155039&r2=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/config/usecases.xconf (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/config/usecases.xconf Wed Feb 23 10:09:08 2005
@@ -12,4 +12,8 @@
logger="lenya.usecases.workflow"
class="org.apache.lenya.defaultpub.cms.usecases.Publish"/>
+ <component-instance name="default/workflow.deactivate"
+ logger="lenya.usecases.workflow"
+ class="org.apache.lenya.defaultpub.cms.usecases.Deactivate"/>
+
</xconf>
Added: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java?view=auto&rev=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java (added)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java Wed Feb 23 10:09:08 2005
@@ -0,0 +1,181 @@
+/*
+ * 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.defaultpub.cms.usecases;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.util.DocumentVisitor;
+import org.apache.lenya.cms.publication.util.OrderedDocumentSet;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
+
+/**
+ * Deactivate usecase handler.
+ *
+ * @version $Id:$
+ */
+public class Deactivate extends DocumentUsecase implements DocumentVisitor {
+
+ /**
+ * Checks if the workflow event is supported and the parent of the document
+ * exists in the live area.
+ *
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
+ */
+ protected void doCheckPreconditions() throws Exception {
+ super.doCheckPreconditions();
+
+ String event = getEvent();
+
+ if (!getWorkflowInstance(getSourceDocument()).canInvoke(getSituation(), event)) {
+ setParameter(Publish.ALLOW_SINGLE_DOCUMENT, Boolean.toString(false));
+ addInfoMessage("The single document cannot be deactivated because the workflow event cannot be invoked.");
+ } else {
+ setParameter(Publish.ALLOW_SINGLE_DOCUMENT, Boolean.toString(true));
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+ if (isSubtreeEnabled()) {
+ deactivateAll(getSourceDocument());
+ } else {
+ deactivate(getSourceDocument());
+ }
+ }
+
+ /**
+ * Deactivates a document.
+ * @param authoringDocument The authoring document.
+ */
+ protected void deactivate(Document authoringDocument) {
+
+ Publication publication = authoringDocument.getPublication();
+ boolean success = false;
+
+ try {
+ Document liveDocument = publication.getAreaVersion(authoringDocument,
+ Publication.LIVE_AREA);
+ publication.deleteDocument(liveDocument);
+
+ triggerWorkflow(getEvent(), authoringDocument);
+ success = true;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Deactivate document [" + authoringDocument + "]. Success: ["
+ + success + "]");
+ }
+ }
+
+ }
+
+ /**
+ * @return The event to invoke.
+ */
+ private String getEvent() {
+ return "deactivate";
+ }
+
+ /**
+ * Deactivates a document or the subtree below a document, based on the
+ * parameter SUBTREE.
+ * @param document The document.
+ */
+ protected void deactivateAll(Document document) {
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Deactivating document [" + document + "]");
+ getLogger().debug("Subtree deactivation: [" + isSubtreeEnabled() + "]");
+ }
+
+ try {
+
+ OrderedDocumentSet set = new OrderedDocumentSet();
+ SiteManager manager = document.getPublication().getSiteManager(document
+ .getIdentityMap());
+ Document[] descendants = manager.getRequiringResources(document);
+
+ set = new OrderedDocumentSet(descendants);
+ set.add(document);
+ set.visitDescending(this);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Publishing completed.");
+ }
+ }
+
+ /**
+ * Returns whether subtree publishing is enabled.
+ * @return A boolean value.
+ */
+ protected boolean isSubtreeEnabled() {
+ String value = getParameterAsString(Publish.SUBTREE);
+ return value != null;
+ }
+
+ /**
+ * @throws PublicationException
+ * @see org.apache.lenya.cms.publication.util.DocumentVisitor#visitDocument(org.apache.lenya.cms.publication.Document)
+ */
+ public void visitDocument(Document document) throws PublicationException {
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Visiting resource [" + document + "]");
+ }
+
+ try {
+ deactivateAllLanguageVersions(document);
+ } catch (WorkflowException e) {
+ throw new PublicationException(e);
+ }
+ }
+
+ /**
+ * Publishes all existing language versions of a document.
+ * @param document The document.
+ * @throws PublicationException if an error occurs.
+ * @throws WorkflowException
+ */
+ protected void deactivateAllLanguageVersions(Document document) throws PublicationException,
+ WorkflowException {
+ String[] languages = document.getPublication().getLanguages();
+ DocumentFactory factory = document.getIdentityMap().getFactory();
+ for (int i = 0; i < languages.length; i++) {
+ Document version = factory.getLanguageVersion(document, languages[i]);
+ if (version.exists()) {
+ WorkflowInstance instance = getWorkflowInstance(version);
+ if (instance.canInvoke(getSituation(), getEvent())) {
+ deactivate(version);
+ }
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
Modified: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java?view=diff&r1=155039&r2=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java Wed Feb 23 10:09:08 2005
@@ -27,7 +27,6 @@
import org.apache.lenya.cms.publication.util.OrderedDocumentSet;
import org.apache.lenya.cms.site.SiteManager;
import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
@@ -40,10 +39,11 @@
protected static final String MISSING_DOCUMENTS = "missingDocuments";
protected static final String SUBTREE = "subtree";
+ protected static final String ALLOW_SINGLE_DOCUMENT = "allowSingleDocument";
/**
- * Checks if the workflow event is supported and the parent of the
- * document exists in the live area.
+ * Checks if the workflow event is supported and the parent of the document
+ * exists in the live area.
*
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
*/
@@ -54,8 +54,11 @@
Document document = getSourceDocument();
if (!getWorkflowInstance(getSourceDocument()).canInvoke(getSituation(), event)) {
- addErrorMessage("Cannot publish document [" + document.getId()
- + "]: workflow event not supported.");
+ setParameter(ALLOW_SINGLE_DOCUMENT, Boolean.toString(false));
+ addInfoMessage("The single document cannot be published because the workflow event cannot be invoked.");
+ }
+ else {
+ setParameter(ALLOW_SINGLE_DOCUMENT, Boolean.toString(true));
}
Publication publication = document.getPublication();
@@ -121,7 +124,7 @@
* @return The event to invoke.
*/
private String getEvent() {
- return getParameterAsString(InvokeWorkflow.EVENT);
+ return "publish";
}
/**
@@ -141,9 +144,9 @@
OrderedDocumentSet set = new OrderedDocumentSet();
SiteManager manager = document.getPublication().getSiteManager(document
.getIdentityMap());
- Document[] ancestors = manager.getRequiringResources(document);
+ Document[] descendants = manager.getRequiringResources(document);
- set = new OrderedDocumentSet(ancestors);
+ set = new OrderedDocumentSet(descendants);
set.add(document);
set.visitAscending(this);
} catch (Exception e) {
Added: lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/deactivate.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/deactivate.jx?view=auto&rev=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/deactivate.jx (added)
+++ lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/deactivate.jx Wed Feb 23 10:09:08 2005
@@ -0,0 +1,93 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!-- $Id: login.jx 123986 2005-01-03 15:23:11Z andreas $ -->
+
+<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:title><i18n:text>Deactivate</i18n:text></page:title>
+ <page:body>
+ <div class="lenya-box">
+ <div class="lenya-box-title">
+ <i18n:text>Deactivate</i18n:text>
+ </div>
+ <div class="lenya-box-body">
+ <form>
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
+ <table class="lenya-table-noborder">
+ <tr>
+ <td class="lenya-entry-caption" valign="top"><i18n:text>Document</i18n:text>:</td>
+ <td valign="top">
+ <jx:out value="${usecase.getParameter('document').getId()}"/>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <ul>
+ <jx:forEach var="message" items="${usecase.getErrorMessages()}">
+ <li>
+ <i18n:text>
+ <jx:out value="${message}"/>
+ </i18n:text>
+ </li>
+ </jx:forEach>
+ <jx:forEach var="message" items="${usecase.getInfoMessages()}">
+ <li>
+ <i18n:text>
+ <jx:out value="${message}"/>
+ </i18n:text>
+ </li>
+ </jx:forEach>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <td/>
+ <td>
+ <jx:choose>
+ <jx:when test="${usecase.getParameter('allowSingleDocument').equals('false')}">
+ <input type="checkbox" checked="checked" disabled="disabled"/>
+ <input name="subtree" type="hidden" value="on"/>
+ </jx:when>
+ <jx:when test="${usecase.getParameter('subtree') == null}">
+ <input name="subtree" type="checkbox"/>
+ </jx:when>
+ <jx:otherwise>
+ <input name="subtree" type="checkbox" checked="checked"/>
+ </jx:otherwise>
+ </jx:choose>
+ <i18n:text>deactivate complete subtree</i18n:text>
+ </td>
+ </tr>
+ <tr>
+ <td/>
+ <td>
+ <input i18n:attr="value" type="submit" name="submit" value="Deactivate"/>
+  
+ <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ </div>
+ </div>
+ </page:body>
+</page:page>
Modified: lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/publish.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/publish.jx?view=diff&r1=155039&r2=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/publish.jx (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/workflow/publish.jx Wed Feb 23 10:09:08 2005
@@ -67,7 +67,18 @@
<tr>
<td/>
<td>
- <input name="subtree" type="checkbox"/>
+ <jx:choose>
+ <jx:when test="${usecase.getParameter('allowSingleDocument').equals('false')}">
+ <input type="checkbox" checked="checked" disabled="disabled"/>
+ <input name="subtree" type="hidden" value="on"/>
+ </jx:when>
+ <jx:when test="${usecase.getParameter('subtree') == null}">
+ <input name="subtree" type="checkbox"/>
+ </jx:when>
+ <jx:otherwise>
+ <input name="subtree" type="checkbox" checked="checked"/>
+ </jx:otherwise>
+ </jx:choose>
<i18n:text>publish complete subtree</i18n:text>
</td>
</tr>
Modified: lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml?view=diff&r1=155039&r2=155040
==============================================================================
--- lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml (original)
+++ lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml Wed Feb 23 10:09:08 2005
@@ -237,6 +237,7 @@
<message key="Deactivate Document">Dokument deaktivieren</message>
<message key="deactivate-doc">Dokument {0} deaktivieren</message>
<message key="deactivate-doc?">Wollen Sie das Dokument {0} wirklich deaktivieren?</message>
+ <message key="deactivate complete subtree">den gesamten Teilbaum deaktivieren</message>
<message key="Delete Document">Dokument löschen</message>
<message key="cannot-deactivate-unless-children-deactivated">Dieses Dokument kann erst deaktiviert werden, wenn alle untergeordneten Dokumente deaktiviert worden sind.</message>
<message key="delete-language-versions?">Wollen Sie wirklich alle Sprachversionen des Dokuments {0} löschen?</message>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org