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/04/09 17:41:15 UTC
svn commit: r160689 - in lenya/trunk/src:
java/org/apache/lenya/cms/publication/usecases/EditDocument.java
webapp/WEB-INF/cocoon-xconf.xsl webapp/lenya/pubs/default/usecase-bxe.xmap
webapp/lenya/usecases/edit-document.js
Author: andreas
Date: Sat Apr 9 08:41:14 2005
New Revision: 160689
URL: http://svn.apache.org/viewcvs?view=rev&rev=160689
Log:
Using usecase handler for BXE usecase. This allows transaction handling.
Added:
lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/EditDocument.java
Modified:
lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
lenya/trunk/src/webapp/lenya/pubs/default/usecase-bxe.xmap
lenya/trunk/src/webapp/lenya/usecases/edit-document.js
Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/EditDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/EditDocument.java?view=auto&rev=160689
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/EditDocument.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/EditDocument.java Sat Apr 9 08:41:14 2005
@@ -0,0 +1,76 @@
+/*
+ * 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.publication.usecases;
+
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.cms.workflow.WorkflowManager;
+import org.apache.lenya.transaction.TransactionException;
+
+/**
+ * Usecase to edit documents.
+ *
+ * @version $Id:$
+ */
+public class EditDocument extends DocumentUsecase {
+
+ /**
+ * The URI to copy the document source from.
+ */
+ public static final String SOURCE_URI = "sourceUri";
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+ SourceResolver resolver = null;
+ WorkflowManager wfManager = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ SourceUtil.copy(resolver, getParameterAsString(SOURCE_URI), getSourceDocument()
+ .getSourceURI());
+
+ wfManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
+ if (wfManager.canInvoke(getSourceDocument(), "edit")) {
+ wfManager.invoke(getSourceDocument(), "edit");
+ }
+
+ } finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
+ if (wfManager != null) {
+ this.manager.release(wfManager);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#lockInvolvedObjects()
+ */
+ public void lockInvolvedObjects() throws UsecaseException {
+ super.lockInvolvedObjects();
+ try {
+ getSourceDocument().lock();
+ } catch (TransactionException e) {
+ throw new UsecaseException(e);
+ }
+ }
+}
\ No newline at end of file
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=160688&r2=160689
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Sat Apr 9 08:41:14 2005
@@ -408,9 +408,14 @@
<view template="tab/scheduler" menu="true"/>
</component-instance>
- <component-instance name="publication.createPublicationFromTemplate" logger="lenya.site"
+ <component-instance name="publication.createPublicationFromTemplate" logger="lenya.publication"
class="org.apache.lenya.cms.publication.usecases.CreatePublicationFromTemplate">
<view template="publication/createPublicationFromTemplate"/>
+ </component-instance>
+
+ <component-instance name="publication.edit" logger="lenya.publication"
+ class="org.apache.lenya.cms.publication.usecases.EditDocument">
+ <parameter name="sourceUri" value="cocoon:/request2document"/>
</component-instance>
</usecases>
Modified: lenya/trunk/src/webapp/lenya/pubs/default/usecase-bxe.xmap
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/usecase-bxe.xmap?view=diff&r1=160688&r2=160689
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/usecase-bxe.xmap (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/usecase-bxe.xmap Sat Apr 9 08:41:14 2005
@@ -289,14 +289,14 @@
</map:act>
<map:call function="editDocument">
+ <map:parameter name="lenya.usecase" value="publication.edit"/>
<map:parameter name="sourceUri" value="cocoon:/request2document"/>
<map:parameter name="noCheckin" value="true"/>
</map:call>
-
</map:when>
<map:otherwise> <!-- GET -->
- <map:generate src="content/authoring/{page-envelope:document-path}"/>
+ <map:generate src="lenya://lenya/pubs/{page-envelope:publication-id}/content/authoring/{page-envelope:document-path}"/>
<map:transform src="../../xslt/bxe/change-object-path.xsl">
<map:parameter name="documentid" value="{page-envelope:document-id}"/>
</map:transform>
Modified: lenya/trunk/src/webapp/lenya/usecases/edit-document.js
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/edit-document.js?view=diff&r1=160688&r2=160689
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/edit-document.js (original)
+++ lenya/trunk/src/webapp/lenya/usecases/edit-document.js Sat Apr 9 08:41:14 2005
@@ -37,46 +37,52 @@
* @param noStatus If true, then no response status will be set.
*/
function editDocument() {
+ var usecaseName = cocoon.parameters["lenya.usecase"];
+
+ var usecaseResolver;
+ var usecase;
+
try {
- var flowHelper = cocoon.getComponent(org.apache.lenya.cms.cocoon.flow.FlowHelper.ROLE);
- var resolver = cocoon.getComponent(SourceResolver.ROLE);
- var dstUri = flowHelper.getPageEnvelope(cocoon).getDocument().getSourceURI();
-
-
- /* do the actual copying */
-
- SourceUtil.copy(resolver, cocoon.parameters["sourceUri"], dstUri, _getParameter("useBuffer", "false") == "true");
-
-
- /* are we supposed to check the document in after saving ? */
-
- if(_getParameter("noCheckin", "false") == "false")
- flowHelper.reservedCheckIn(cocoon, _getParameter("backup", "true") == "true");
-
-
- /* do we need to trigger any worklow on the just saved document? */
+ usecaseResolver = cocoon.getComponent("org.apache.lenya.cms.usecase.UsecaseResolver");
+ usecase = usecaseResolver.resolve(usecaseName);
- if(_getParameter("noWorkflow", "false") == "false")
- flowHelper.triggerWorkflow(cocoon, _getParameter("workflowEvent", "edit"));
+ var flowHelper = cocoon.getComponent("org.apache.lenya.cms.cocoon.flow.FlowHelper");
+ var request = flowHelper.getRequest(cocoon);
+ var sourceUrl = Packages.org.apache.lenya.util.ServletHelper.getWebappURI(request);
+ usecase.setSourceURL(sourceUrl);
+ usecase.setName(usecaseName);
+ usecase.checkPreconditions();
+ usecase.lockInvolvedObjects();
+
+ usecase.execute();
+ if (usecase.getErrorMessages().isEmpty()) {
+ // TODO: handle error messages
+ }
if(_getParameter("noStatus", "false") == "false")
cocoon.sendStatus(_getParameter("status", 204));
else
cocoon.redirectTo(_getParameter("redirectUrl", "FIXME"));
-
+
} catch (exception) {
/* FIXME: This is unclean because the flow will not return a value
if there is an exception */
-
cocoon.log.error("Can not edit document.", exception);
- } finally {
- if(resolver != null)
- cocoon.releaseComponent(resolver);
- if(flowHelper != null)
- cocoon.releaseComponent(flowHelper);
+
+ }
+ finally {
+ /* done with usecase component, tell usecaseResolver to release it */
+ if (usecaseResolver != null) {
+ if (usecase != null) {
+ usecaseResolver.release(usecase);
+ usecase = undefined;
+ }
+ cocoon.releaseComponent(usecaseResolver);
+ }
}
+
}
function _getParameter(name, defaultValue) {
@@ -85,3 +91,4 @@
else
return defaultValue;
}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org