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 2007/01/30 16:15:10 UTC

svn commit: r501415 - in /lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors: EditDocument.java SaveDocument.java

Author: andreas
Date: Tue Jan 30 07:15:09 2007
New Revision: 501415

URL: http://svn.apache.org/viewvc?view=rev&rev=501415
Log:
Refactored EditDocument and SaveDocument usecases, added some javadocs

Modified:
    lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java
    lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/SaveDocument.java

Modified: lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java?view=diff&rev=501415&r1=501414&r2=501415
==============================================================================
--- lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java (original)
+++ lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java Tue Jan 30 07:15:09 2007
@@ -30,12 +30,38 @@
 import org.apache.lenya.xml.ValidationUtil;
 
 /**
- * Usecase to edit documents.
+ * <p>
+ * You can use this usecase to save a document. It reads XML data from a source
+ * and saves as the content of the current document.
+ * </p>
+ * <ul>
+ * <li>If the document's resource type supports validation, the XML document is
+ * validated and not saved if validation errors occur.</li>
+ * <li>All URL-based internal links in the XML source are converted to
+ * UUID-based links before saving.</li>
+ * <li>A workflow event is invoked. The event defaults to "edit", you can
+ * override it using the <em>event</em> parameter.</li>
+ * </ul>
+ * <p>
+ * Parameters:
+ * </p>
+ * <ul>
+ * <li><em>sourceUri</em> - the URI to read the XML data from</li>
+ * <li><em>event</em> - the workflow event to invoke</li>
+ * </ul>
+ * <p>
+ * A typical usage scenario is to save XML data entered in a form. In this case,
+ * the <em>sourceUri</em> parameter refers to a Cocoon pipeline featuring the
+ * stream generator.
+ * </p>
  * 
  * @version $Id$
  */
 public class EditDocument extends DocumentUsecase {
 
+    protected static final String EVENT = "event";
+    protected static final String DEFAULT_EVENT = "edit";
+
     /**
      * The URI to copy the document source from.
      */
@@ -51,19 +77,20 @@
 
         String sourceUri = getParameterAsString(SOURCE_URI);
         org.w3c.dom.Document xmlDoc = SourceUtil.readDOM(sourceUri, this.manager);
-        
+
         ResourceType resourceType = sourceDoc.getResourceType();
         Schema schema = resourceType.getSchema();
         ValidationUtil.validate(this.manager, xmlDoc, schema, new UsecaseErrorHandler(this));
 
         if (!hasErrors()) {
             SourceUtil.writeDOM(xmlDoc, sourceDoc.getSourceURI(), this.manager);
-            
+
             LinkConverter converter = new LinkConverter(this.manager, getLogger());
             converter.convertUrlsToUuids(getSourceDocument());
 
-            WorkflowUtil.invoke(this.manager, getSession(), getLogger(), getSourceDocument(),
-                    "edit");
+            String event = getParameterAsString(EVENT, DEFAULT_EVENT);
+            WorkflowUtil
+                    .invoke(this.manager, getSession(), getLogger(), getSourceDocument(), event);
         }
     }
 

Modified: lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/SaveDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/SaveDocument.java?view=diff&rev=501415&r1=501414&r2=501415
==============================================================================
--- lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/SaveDocument.java (original)
+++ lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/SaveDocument.java Tue Jan 30 07:15:09 2007
@@ -29,21 +29,22 @@
 
 /**
  * <p>
- * This usecase saves the document from the request stream
- * <strong>before</strong> the view is displayed.
- * That's kind of a hack, since it violates the standard usecase principle,
- * but it is very convenient because you can save and re-load the document
- * without a redirect.
+ * This usecase saves the document from the request stream <em>before</em> the
+ * view is displayed using the {@link EditDocument} usecase. That's kind of a
+ * hack, since it violates the standard usecase principle, but it is very
+ * convenient because you can save and re-load the document without a redirect.
  * </p>
  * 
  * @version $Id: EditDocument.java 495324 2007-01-11 18:44:04Z andreas $
  */
 public class SaveDocument extends DocumentUsecase {
 
+    protected static final String USECASE_NAME = "usecaseName";
+
     protected void doCheckPreconditions() throws Exception {
         super.doCheckPreconditions();
 
-        String usecase = getParameterAsString("usecaseName");
+        String usecase = getParameterAsString(USECASE_NAME);
         Assert.notNull("usecase", usecase);
 
         UsecaseInvoker invoker = null;
@@ -51,6 +52,7 @@
             invoker = (UsecaseInvoker) this.manager.lookup(UsecaseInvoker.ROLE);
             Map params = new HashMap();
             params.put(EditDocument.SOURCE_URI, getParameter(EditDocument.SOURCE_URI));
+            params.put(EditDocument.EVENT, getParameter(EditDocument.EVENT));
             invoker.invoke(getSourceURL(), usecase, params);
 
             if (invoker.getResult() != UsecaseInvoker.SUCCESS) {



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