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 2006/09/12 10:39:35 UTC

svn commit: r442524 - in /lenya/trunk/src: java/org/apache/lenya/cms/metadata/dublincore/ modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/ modules/bxe/ modules/bxe/config/cocoon-xconf/ modules/webdav/java/src/org/apache/lenya...

Author: andreas
Date: Tue Sep 12 01:39:34 2006
New Revision: 442524

URL: http://svn.apache.org/viewvc?view=rev&rev=442524
Log:
Added DublinCoreHelper (feel free to add more methods), invoke workflow event when PUTting with WebDAV

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java
    lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/CheckWorkflow.java
Modified:
    lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java
    lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf
    lenya/trunk/src/modules/bxe/sitemap.xmap
    lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java?view=auto&rev=442524
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java Tue Sep 12 01:39:34 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright  1999-2005 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.metadata.dublincore;
+
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.cms.metadata.MetaDataOwner;
+
+/**
+ * Helper class to access dublin core meta data.
+ */
+public class DublinCoreHelper {
+
+    /**
+     * @param owner The owner.
+     * @return The dublin core title.
+     * @throws MetaDataException if the owner has no dublin core meta data.
+     */
+    public static String getTitle(MetaDataOwner owner) throws MetaDataException {
+        return getDublinCore(owner).getFirstValue(DublinCore.ELEMENT_TITLE);
+    }
+    
+    protected static MetaData getDublinCore(MetaDataOwner owner) throws MetaDataException {
+        return owner.getMetaData(DublinCore.DC_NAMESPACE);
+    }
+    
+}

Added: lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/CheckWorkflow.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/CheckWorkflow.java?view=auto&rev=442524
==============================================================================
--- lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/CheckWorkflow.java (added)
+++ lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/CheckWorkflow.java Tue Sep 12 01:39:34 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright  1999-2005 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.workflow.usecases;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.workflow.WorkflowUtil;
+
+/**
+ * Check if a workflow event can be invoked on the current document without actually invoking it.
+ * The event is obtained from the configuration in <code>cocoon.xconf</code>:<code>
+ * <pre>
+ *     &lt;component-instance name=&quot;default/workflow.submit&quot;
+ *                            logger=&quot;lenya.usecases.workflow&quot;
+ *                            class=&quot;org.apache.lenya.cms.workflow.usecases.CheckWorkflow&quot;&gt;
+ *       &lt;event id=&quot;submit&quot;/&gt;
+ *     &lt;/component-instance&gt;
+ * </pre>
+ * </code>
+ * 
+ * @version $Id: InvokeWorkflow.java 426254 2006-07-27 21:27:04Z andreas $
+ */
+public class CheckWorkflow extends DocumentUsecase implements Configurable {
+
+    private String event;
+
+    /**
+     * @return The workflow event to use.
+     */
+    protected String getEvent() {
+        return event;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
+     */
+    protected void doCheckPreconditions() throws Exception {
+        super.doCheckPreconditions();
+
+        if (hasErrors()) {
+            return;
+        }
+
+        Document doc = getSourceDocument();
+        if (!WorkflowUtil.canInvoke(this.manager, getSession(), getLogger(), doc, getEvent())) {
+            String title = DublinCoreHelper.getTitle(doc);
+            addErrorMessage("error-workflow-document", new String[] { getEvent(), title });
+        }
+    }
+
+    protected static final String ELEMENT_EVENT = "event";
+    protected static final String ATTRIBUTE_ID = "id";
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+        super.configure(config);
+        this.event = config.getChild(ELEMENT_EVENT).getAttribute(ATTRIBUTE_ID);
+    }
+
+}

Modified: lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java?view=diff&rev=442524&r1=442523&r2=442524
==============================================================================
--- lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java (original)
+++ lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java Tue Sep 12 01:39:34 2006
@@ -16,11 +16,7 @@
  */
 package org.apache.lenya.cms.workflow.usecases;
 
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.lenya.cms.repository.Node;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
 import org.apache.lenya.cms.usecase.UsecaseException;
 import org.apache.lenya.cms.workflow.WorkflowUtil;
 
@@ -28,46 +24,17 @@
  * Invoke a workflow event on the current document. The event is obtained from the configuration in
  * <code>cocoon.xconf</code>:<code>
  * <pre>
- * &lt;component-instance name=&quot;default/workflow.submit&quot;
- *                        logger=&quot;lenya.usecases.workflow&quot;
- *                        class=&quot;org.apache.lenya.cms.workflow.usecases.InvokeWorkflow&quot;&gt;
- *   &lt;event id=&quot;submit&quot;/&gt;
- * &lt;/component-instance&gt;
+ *   &lt;component-instance name=&quot;default/workflow.submit&quot;
+ *                          logger=&quot;lenya.usecases.workflow&quot;
+ *                          class=&quot;org.apache.lenya.cms.workflow.usecases.InvokeWorkflow&quot;&gt;
+ *     &lt;event id=&quot;submit&quot;/&gt;
+ *   &lt;/component-instance&gt;
  * </pre>
  * </code>
  * 
  * @version $Id$
  */
-public class InvokeWorkflow extends DocumentUsecase implements Configurable {
-
-    private String event;
-
-    /**
-     * @return The workflow event to use.
-     */
-    protected String getEvent() {
-        return event;
-    }
-
-    /**
-     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
-     */
-    protected void doCheckPreconditions() throws Exception {
-        super.doCheckPreconditions();
-
-        if (hasErrors()) {
-            return;
-        }
-
-        if (!WorkflowUtil.canInvoke(this.manager,
-                getSession(),
-                getLogger(),
-                getSourceDocument(),
-                getEvent())) {
-            addErrorMessage("error-workflow-document", new String[] { getEvent(),
-                    getSourceDocument().toString() });
-        }
-    }
+public class InvokeWorkflow extends CheckWorkflow {
 
     /**
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
@@ -82,22 +49,8 @@
      */
     protected void doExecute() throws Exception {
         super.doExecute();
-        WorkflowUtil.invoke(this.manager,
-                getSession(),
-                getLogger(),
-                getSourceDocument(),
+        WorkflowUtil.invoke(this.manager, getSession(), getLogger(), getSourceDocument(),
                 getEvent());
-    }
-
-    protected static final String ELEMENT_EVENT = "event";
-    protected static final String ATTRIBUTE_ID = "id";
-
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
-     */
-    public void configure(Configuration config) throws ConfigurationException {
-        super.configure(config);
-        this.event = config.getChild(ELEMENT_EVENT).getAttribute(ATTRIBUTE_ID);
     }
 
 }

Modified: lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf?view=diff&rev=442524&r1=442523&r2=442524
==============================================================================
--- lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf (original)
+++ lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf Tue Sep 12 01:39:34 2006
@@ -22,8 +22,9 @@
   <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'edit.bxe']">
     
     <component-instance name="edit.bxe" logger="lenya.publication" 
-    class="org.apache.lenya.cms.usecase.DummyUsecase">
+    class="org.apache.lenya.cms.workflow.usecases.CheckWorkflow">
       <view uri="cocoon://modules/bxe/bxe.open" menu="false"/>
+      <event id="edit"/>
     </component-instance>
     
   </xconf>

Modified: lenya/trunk/src/modules/bxe/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/bxe/sitemap.xmap?view=diff&rev=442524&r1=442523&r2=442524
==============================================================================
--- lenya/trunk/src/modules/bxe/sitemap.xmap (original)
+++ lenya/trunk/src/modules/bxe/sitemap.xmap Tue Sep 12 01:39:34 2006
@@ -169,7 +169,7 @@
               1. get the document contents (by issuing a GET to this URL),
               2. save the changed contents (by issuing a PUT to this URL)
             -->
-            <map:parameter name="BX_xmlfile" value="{request:contextPath}/{../1}/webdav/{../3}.xml"/>
+            <map:parameter name="BX_xmlfile" value="{request:contextPath}/{../1}/webdav/{../3}.xml?lenya.event=edit"/>
             <map:parameter name="defaultlanguage" value="{page-envelope:default-language}"/>
             
             <!-- Instead of an xsl we use the xhtml file to provide the basic layout

Modified: lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java?view=diff&rev=442524&r1=442523&r2=442524
==============================================================================
--- lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java (original)
+++ lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java Tue Sep 12 01:39:34 2006
@@ -29,6 +29,7 @@
 import org.apache.lenya.cms.metadata.MetaData;
 import org.apache.lenya.cms.metadata.MetaDataException;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentFactory;
 import org.apache.lenya.cms.publication.DocumentManager;
@@ -43,7 +44,7 @@
 import org.apache.lenya.cms.site.usecases.CreateDocument;
 import org.apache.lenya.cms.usecase.UsecaseException;
 import org.apache.lenya.cms.usecase.xml.UsecaseErrorHandler;
-import org.apache.lenya.workflow.WorkflowManager;
+import org.apache.lenya.cms.workflow.WorkflowUtil;
 import org.apache.lenya.xml.Schema;
 import org.apache.lenya.xml.ValidationUtil;
 
@@ -52,6 +53,7 @@
  * @version $Id: $
  */
 public class Put extends CreateDocument {
+    
     // registeredExtensions contain all known extension matching to a certain resource-type.
     private HashMap registeredExtensions = new HashMap();
     // default is xhtml and xml but you can override it with the config
@@ -60,7 +62,8 @@
     protected static final String ATTRIBUTE_TYPE = "resource-type";
     protected static final String ELEMENT_ROOT = "extensions";
     protected static final String ELEMENT_EXTENSION = "extension";
-
+    protected static final String EVENT = "lenya.event";
+    
     private boolean fallback = false;
 
     public void configure(Configuration config) throws ConfigurationException {
@@ -80,12 +83,23 @@
         }
     }
 
+    protected void doCheckExecutionConditions() throws Exception {
+        super.doCheckExecutionConditions();
+
+        Document doc = getSourceDocument();
+        String event = getParameterAsString(EVENT);
+        if (event != null
+                && !WorkflowUtil.canInvoke(this.manager, getSession(), getLogger(), doc, event)) {
+            String title = DublinCoreHelper.getTitle(doc);
+            addErrorMessage("error-workflow-document", new String[] { event, title });
+        }
+    }
+
     /**
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
      */
     protected void doExecute() throws Exception {
         SourceResolver resolver = null;
-        WorkflowManager wfManager = null;
 
         try {
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
@@ -144,13 +158,15 @@
                 }
             }
 
+            String event = getParameterAsString(EVENT);
+            if (event != null) {
+                WorkflowUtil.invoke(this.manager, getSession(), getLogger(), doc, event);
+            }
+
         } finally {
             if (resolver != null) {
                 this.manager.release(resolver);
             }
-            if (wfManager != null) {
-                this.manager.release(wfManager);
-            }
         }
     }
 
@@ -237,8 +253,7 @@
         if (this.publication == null) {
             try {
                 this.publication = PublicationUtil.getPublicationFromUrl(this.manager,
-                        getDocumentFactory(),
-                        getSourceURL());
+                        getDocumentFactory(), getSourceURL());
             } catch (PublicationException e) {
                 throw new RuntimeException(e);
             }



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