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 2004/09/20 17:51:40 UTC

svn commit: rev 46938 - incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase

Author: andreas
Date: Mon Sep 20 08:51:38 2004
New Revision: 46938

Added:
   incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
Modified:
   incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractOperation.java
   incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java
   incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java
   incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
Log:
adding document usecase, improving setup

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractOperation.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractOperation.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractOperation.java	Mon Sep 20 08:51:38 2004
@@ -47,7 +47,7 @@
         return this.unitOfWork;
     }
 
-    private ServiceManager manager;
+    protected ServiceManager manager;
 
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java	Mon Sep 20 08:51:38 2004
@@ -22,16 +22,24 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.cocoon.workflow.WorkflowHelper;
+import org.apache.lenya.util.ServletHelper;
 import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.WorkflowException;
 
 /**
  * Abstract usecase implementation.
- *
- * @version $Id:$ 
+ * 
+ * @version $Id:$
  */
-public class AbstractUsecase extends AbstractOperation implements Usecase {
+public class AbstractUsecase extends AbstractOperation implements Usecase, Contextualizable {
 
     /**
      * Ctor.
@@ -40,20 +48,21 @@
     }
 
     private Situation situation;
-    private Document sourceDocument;
 
     /**
-     * @see org.apache.lenya.cms.usecase.Usecase#setup(org.apache.lenya.cms.publication.Document,
-     *      org.apache.lenya.workflow.Situation)
+     * Sets the source URL and the workflow situation of the usecase.
+     * @param sourceUrl The URL the usecase was invoked on.
+     * @param situation The workflow situation.
+     * 
      */
-    public void setup(Document sourceDocument, Situation situation) {
-        this.sourceDocument = sourceDocument;
+    public void setup(String sourceUrl, Situation situation) {
+        this.sourceUrl = sourceUrl;
         this.situation = situation;
 
         initParameters();
 
         if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Invoking usecase on document: [" + sourceDocument + "]");
+            getLogger().debug("Invoking usecase on URL: [" + sourceUrl + "]");
         }
     }
 
@@ -71,12 +80,14 @@
         return this.situation;
     }
 
+    private String sourceUrl = null;
+
     /**
-     * Returns the source document.
-     * @return A document.
+     * Returns the source URL.
+     * @return A string.
      */
-    protected Document getSourceDocument() {
-        return sourceDocument;
+    protected String getSourceURL() {
+        return sourceUrl;
     }
 
     /**
@@ -285,29 +296,25 @@
         return value;
     }
 
-    private Document targetDocument = null;
+    private String targetUrl = null;
 
-    /**
-     * Sets the target document.
-     * @param document A document.
-     */
-    protected void setTargetDocument(Document document) {
-        this.targetDocument = document;
+    protected void setTargetURL(String url) {
+        this.targetUrl = url;
     }
 
     /**
-     * If {@link #setTargetDocument(Document)}was not called, the source document (
-     * {@link #getSourceDocument()}) is returned.
-     * @see org.apache.lenya.cms.usecase.Usecase#getTargetDocument(boolean)
+     * If {@link #setTargetURL(String)}was not called, the source document (
+     * {@link #getSourceURL()}) is returned.
+     * @see org.apache.lenya.cms.usecase.Usecase#getTargetURL(boolean)
      */
-    public Document getTargetDocument(boolean success) {
-        Document document;
-        if (this.targetDocument != null) {
-            document = this.targetDocument;
+    public String getTargetURL(boolean success) {
+        String url;
+        if (this.targetUrl != null) {
+            url = this.targetUrl;
         } else {
-            document = getSourceDocument();
+            url = getSourceURL();
         }
-        return document;
+        return url;
     }
 
     /**
@@ -317,4 +324,30 @@
     public void setPart(String name, Part value) {
     }
 
+    private Context context;
+
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
+    public void initialize() throws Exception {
+        super.initialize();
+        Map objectModel = ContextHelper.getObjectModel(this.context);
+        Situation situation;
+        try {
+            situation = WorkflowHelper.buildSituation(objectModel);
+        } catch (WorkflowException e) {
+            throw new RuntimeException(e);
+        }
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        String webappUri = ServletHelper.getWebappURI(request);
+        
+        setup(webappUri, situation);
+    }
 }

Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java	Mon Sep 20 08:51:38 2004
@@ -0,0 +1,98 @@
+/*
+ * Created on 20.09.2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.lenya.cms.usecase;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.workflow.Situation;
+
+/**
+ * @author nobby
+ * 
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class DocumentUsecase extends AbstractUsecase {
+
+    /**
+     * Ctor.
+     */
+    public DocumentUsecase() {
+        super();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.Usecase#setup(java.lang.String,
+     *      org.apache.lenya.workflow.Situation)
+     */
+    public void setup(String sourceUrl, Situation situation) {
+        super.setup(sourceUrl, situation);
+        try {
+            this.sourceDocument = getUnitOfWork().getIdentityMap().getFactory().getFromURL(
+                    sourceUrl);
+        } catch (DocumentBuildException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private Document sourceDocument = null;
+
+    /**
+     * Returns the source document.
+     * @return A document.
+     */
+    protected Document getSourceDocument() {
+        return sourceDocument;
+    }
+
+    private Document targetDocument = null;
+
+    /**
+     * Sets the target document.
+     * @param document A document.
+     */
+    protected void setTargetDocument(Document document) {
+        this.targetDocument = document;
+    }
+
+    protected Document getTargetDocument(boolean success) {
+        Document document;
+        if (this.targetDocument != null) {
+            document = this.targetDocument;
+        } else {
+            document = getSourceDocument();
+        }
+        return document;
+    }
+
+    /**
+     * If {@link #setTargetDocument(Document)}was not called, the URL of the source document (
+     * {@link #getSourceDocument()}) is returned.
+     * @see org.apache.lenya.cms.usecase.Usecase#getTargetURL(boolean)
+     */
+    public String getTargetURL(boolean success) {
+        return getTargetDocument(success).getCanonicalWebappURL();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#getSourceURL()
+     */
+    protected String getSourceURL() {
+        return getSourceDocument().getCanonicalWebappURL();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#setTargetURL(java.lang.String)
+     */
+    protected void setTargetURL(String url) {
+        try {
+            this.sourceDocument = getUnitOfWork().getIdentityMap().getFactory().getFromURL(url);
+        } catch (DocumentBuildException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
\ No newline at end of file

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java	Mon Sep 20 08:51:38 2004
@@ -19,7 +19,6 @@
 import java.util.List;
 
 import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.workflow.Situation;
 
 /**
@@ -56,12 +55,12 @@
     void setPart(String name, Part value);
     
     /**
-     * Passes the source document and the workflow situation to the usecase.
-     * @param sourceDocument The document the workflow was invoked on.
+     * Passes the source URL and the workflow situation to the usecase.
+     * @param sourceUrl The URL the usecase was invoked on.
      * @param situation The workflow situation.
      * 
      */
-    void setup(Document sourceDocument, Situation situation);
+    void setup(String sourceUrl, Situation situation);
     
     /**
      * Checks the conditions before a form is displayed.
@@ -104,10 +103,10 @@
     void execute() throws UsecaseException;
     
     /**
-     * Returns the document which should be shown after the usecase is completed.
+     * Returns the webapp URL which should be redirected to after the usecase is completed.
      * @param success If the usecase was completed successfully.
-     * @return A document.
+     * @return A web application URL.
      */
-    Document getTargetDocument(boolean success);
+    String getTargetURL(boolean success);
     
 }

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java	Mon Sep 20 08:51:38 2004
@@ -16,6 +16,7 @@
  */
 package org.apache.lenya.cms.usecase;
 
+
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
@@ -43,8 +44,7 @@
      * @see org.apache.lenya.cms.usecase.UsecaseResolver#resolve(java.lang.String)
      */
     public Usecase resolve(String name) throws ServiceException {
-        Usecase usecase = (Usecase) this.selector.select(name);
-        return usecase;
+        return (Usecase) this.selector.select(name);
     }
 
     private ServiceManager manager;
@@ -76,5 +76,5 @@
             this.manager.release(selector);
         }
     }
-
+    
 }

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