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 14:52:17 UTC
svn commit: rev 46932 - in incubator/lenya/trunk/src/java/org/apache/lenya: . cms/cocoon/acting cms/cocoon/components/modules/input cms/cocoon/source cms/cocoon/transformation cms/publication cms/site cms/site/tree cms/usecase
Author: andreas
Date: Mon Sep 20 05:52:15 2004
New Revision: 46932
Added:
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/OperationModule.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/
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/Operation.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UnitOfWork.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UnitOfWorkImpl.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseException.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolver.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
Modified:
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/lenya.roles
Log:
adding usecase classes
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java Mon Sep 20 05:52:15 2004
@@ -140,7 +140,6 @@
}
filename = filename.substring(publicationPath.length());
- getLogger().debug("Filename: " + filename);
username = null;
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java Mon Sep 20 05:52:15 2004
@@ -22,19 +22,16 @@
import java.util.Map;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.PageEnvelopeFactory;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
/**
* Abstract superclass for classes which need access to the page envelope.
*/
-public abstract class AbstractPageEnvelopeModule extends AbstractInputModule {
+public abstract class AbstractPageEnvelopeModule extends OperationModule {
/**
* Get the the page envelope for the given objectModel.
@@ -55,8 +52,7 @@
}
try {
- Publication pub = PublicationFactory.getPublication(objectModel);
- DocumentIdentityMap map = new DocumentIdentityMap(pub);
+ DocumentIdentityMap map = getUnitOfWork().getIdentityMap();
envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(map, objectModel);
} catch (Exception e) {
throw new ConfigurationException("Resolving page envelope failed: ", e);
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java Mon Sep 20 05:52:15 2004
@@ -23,9 +23,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.lenya.cms.publication.util.DocumentHelper;
/**
@@ -40,9 +37,7 @@
*
* @version: $Id$
*/
-public class DocumentURLModule extends AbstractPageEnvelopeModule implements Serviceable {
-
- private ServiceManager manager;
+public class DocumentURLModule extends AbstractPageEnvelopeModule {
/**
* @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
@@ -91,13 +86,6 @@
throws ConfigurationException {
Object[] objects = { getAttribute(name, modeConf, objectModel) };
return objects;
- }
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
}
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java Mon Sep 20 05:52:15 2004
@@ -26,9 +26,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceUtil;
@@ -43,11 +40,9 @@
* <code>lenya/pubs/(publication-id)/lenya/xslt/style.xsl</code> exists, and if not, it uses
* <code>lenya/xslt/style.xsl</code>.
*
- * @version $Id:$
+ * @version $Id$
*/
-public class FallbackModule extends AbstractPageEnvelopeModule implements Serviceable {
-
- private ServiceManager manager;
+public class FallbackModule extends AbstractPageEnvelopeModule {
private String[] baseUris;
@@ -222,17 +217,4 @@
return objects;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
- /**
- * @return Returns the service manager.
- */
- public ServiceManager getServiceManager() {
- return manager;
- }
}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/OperationModule.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/OperationModule.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,68 @@
+/*
+ * 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.cocoon.components.modules.input;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.lenya.cms.usecase.Operation;
+import org.apache.lenya.cms.usecase.UnitOfWork;
+
+/**
+ * @author nobby
+ *
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class OperationModule extends AbstractInputModule implements Operation, Serviceable, Initializable {
+
+ /**
+ * Ctor.
+ */
+ public OperationModule() {
+ super();
+ }
+
+ private UnitOfWork unitOfWork;
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Operation#getUnitOfWork()
+ */
+ public UnitOfWork getUnitOfWork() {
+ return this.unitOfWork;
+ }
+
+ protected ServiceManager manager;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ this.unitOfWork = (UnitOfWork) this.manager.lookup(UnitOfWork.ROLE);
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if (this.manager != null) {
+ if (this.unitOfWork != null) {
+ this.manager.release(this.unitOfWork);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java Mon Sep 20 05:52:15 2004
@@ -29,8 +29,6 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.commons.lang.StringUtils;
@@ -44,9 +42,7 @@
*
* @see org.apache.lenya.cms.publication.PageEnvelope
*/
-public class PageEnvelopeModule extends AbstractPageEnvelopeModule implements Serviceable {
-
- private ServiceManager manager;
+public class PageEnvelopeModule extends AbstractPageEnvelopeModule {
protected static final String URI_PARAMETER_DOCTYPE = "doctype";
@@ -187,13 +183,6 @@
return objects;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
/**
* uri will be filtered by certain rules
* i.e. session information encoded within the uri will be removed.
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java Mon Sep 20 05:52:15 2004
@@ -20,9 +20,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publication.templating.ExistingSourceResolver;
@@ -31,8 +28,7 @@
/**
* @version $Id:$
*/
-public class PublicationTemplateFallbackModule extends AbstractPageEnvelopeModule implements
- Serviceable {
+public class PublicationTemplateFallbackModule extends AbstractPageEnvelopeModule {
/**
* Ctor.
@@ -86,15 +82,6 @@
String publicationUri = "context://" + Publication.PUBLICATION_PREFIX_URI + "/"
+ publication.getId() + "/lenya";
return publicationUri;
- }
-
- private ServiceManager manager;
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
}
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java Mon Sep 20 05:52:15 2004
@@ -25,31 +25,27 @@
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.Constants;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.environment.Context;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceFactory;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceUtil;
import org.apache.excalibur.source.URIAbsolutizer;
-import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publication.templating.ExistingSourceResolver;
import org.apache.lenya.cms.publication.templating.PublicationTemplateManager;
+import org.apache.lenya.cms.usecase.AbstractOperation;
/**
* Source factory following the fallback principle.
*
* @version $Id:$
*/
-public class FallbackSourceFactory extends AbstractLogEnabled implements SourceFactory,
+public class FallbackSourceFactory extends AbstractOperation implements SourceFactory,
Serviceable, Contextualizable, URIAbsolutizer {
/**
@@ -94,8 +90,7 @@
try {
templateManager = (PublicationTemplateManager) this.manager
.lookup(PublicationTemplateManager.ROLE);
- Map objectModel = ContextHelper.getObjectModel(this.context);
- Publication pub = PublicationFactory.getPublication(objectModel);
+ Publication pub = getUnitOfWork().getIdentityMap().getPublication();
templateManager.setup(pub);
ExistingSourceResolver resolver = new ExistingSourceResolver();
@@ -149,6 +144,7 @@
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
+ super.service(manager);
this.manager = manager;
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java Mon Sep 20 05:52:15 2004
@@ -19,7 +19,6 @@
package org.apache.lenya.cms.cocoon.transformation;
-import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -125,111 +124,111 @@
public void startElement(String uri, String localName, String raw, Attributes attr)
throws SAXException {
- if (uri != null && uri.equals(namespace) && cIncludeNamespace != null
- && localName.equals(CHILDREN_ELEMENT)) {
-
- if (getLogger().isInfoEnabled()) {
- getLogger().info("Inserting index");
- }
+ try {
+ if (uri != null && uri.equals(namespace) && cIncludeNamespace != null
+ && localName.equals(CHILDREN_ELEMENT)) {
- String cIncludePrefix = "";
- if (!this.cIncludeNamespace.equals("")) {
- cIncludePrefix = "ci:";
- }
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("Inserting index");
+ }
- String documentId = document.getId();
- String language = document.getLanguage();
- String defaultLanguage = publication.getDefaultLanguage();
- SiteTreeNode[] children = siteTree.getNode(documentId).getChildren();
-
- super.startElement(uri, localName, raw, attr);
-
- for (int i = 0; i < children.length; i++) {
- String childId = documentId + "/" + children[i].getId();
-
- //get child document with the same language than the parent document
- Document doc;
- try {
- doc = this.identityMap.getFactory().get(area, childId, language);
- } catch (DocumentBuildException e) {
- throw new SAXException(e);
+ String cIncludePrefix = "";
+ if (!this.cIncludeNamespace.equals("")) {
+ cIncludePrefix = "ci:";
}
- String url = doc.getCanonicalWebappURL();
- File file = doc.getFile();
- if (!file.exists()) {
- //get first the child document in the default language and then in any other
- // existent language
- getLogger().debug(
- "There is no child file " + file.getAbsolutePath()
- + " in the same language as the parent document [" + language
- + "]");
+ String documentId = document.getId();
+ String language = document.getLanguage();
+ String defaultLanguage = publication.getDefaultLanguage();
+ SiteTreeNode[] children = siteTree.getNode(documentId).getChildren();
- //available language
- String[] availableLanguages = null;
+ super.startElement(uri, localName, raw, attr);
+
+ for (int i = 0; i < children.length; i++) {
+ String childId = documentId + "/" + children[i].getId();
+
+ //get child document with the same language than the parent document
+ Document doc;
try {
- availableLanguages = doc.getLanguages();
- } catch (DocumentException e) {
+ doc = this.identityMap.getFactory().get(area, childId, language);
+ } catch (DocumentBuildException e) {
throw new SAXException(e);
}
+ String url = doc.getCanonicalWebappURL();
- List languages = new ArrayList();
- for (int l = 0; l < availableLanguages.length; l++) {
- if (availableLanguages[l].equals(language)) {
- getLogger().debug(
- "Do nothing because language was already tested: ["
- + availableLanguages[l] + "]");
- } else if (availableLanguages[l].equals(defaultLanguage)) {
- languages.add(0, availableLanguages[l]);
- } else {
- languages.add(availableLanguages[l]);
- }
- }
+ if (!doc.exists()) {
+ //get first the child document in the default language and then in any
+ // other
+ // existent language
+ getLogger().debug(
+ "There is no child document [" + doc
+ + "] in the same language as the parent document ["
+ + language + "]");
- int j = 0;
- while (!file.exists() && j < languages.size()) {
- String newlanguage = (String) languages.get(j);
+ //available language
+ String[] availableLanguages = null;
try {
- doc = this.identityMap.getFactory().get(area, childId, newlanguage);
- } catch (DocumentBuildException e) {
+ availableLanguages = doc.getLanguages();
+ } catch (DocumentException e) {
throw new SAXException(e);
}
- url = doc.getCanonicalWebappURL();
- file = doc.getFile();
- j++;
+ List languages = new ArrayList();
+ for (int l = 0; l < availableLanguages.length; l++) {
+ if (availableLanguages[l].equals(language)) {
+ getLogger().debug(
+ "Do nothing because language was already tested: ["
+ + availableLanguages[l] + "]");
+ } else if (availableLanguages[l].equals(defaultLanguage)) {
+ languages.add(0, availableLanguages[l]);
+ } else {
+ languages.add(availableLanguages[l]);
+ }
+ }
+
+ int j = 0;
+ while (!doc.exists() && j < languages.size()) {
+ String newlanguage = (String) languages.get(j);
+ try {
+ doc = this.identityMap.getFactory().get(area, childId, newlanguage);
+ } catch (DocumentBuildException e) {
+ throw new SAXException(e);
+ }
+ url = doc.getCanonicalWebappURL();
+
+ j++;
+ }
}
- }
- if (file.exists()) {
- //create the tags for the child
- String path;
- try {
- path = file.getCanonicalPath();
- } catch (IOException e) {
- throw new SAXException(e);
+ if (doc.exists()) {
+ //create the tags for the child
+ String sourceUri = doc.getSourceURI();
+
+ AttributesImpl attribute = new AttributesImpl();
+ attribute.addAttribute("", "href", "href", "", url);
+ super.startElement(NAMESPACE, "child", PREFIX + "child", attribute);
+
+ AttributesImpl attributes = new AttributesImpl();
+ attributes.addAttribute("", "src", "src", "", sourceUri);
+ attributes.addAttribute("", "element", "element", "", "included");
+
+ super.startElement(this.cIncludeNamespace, "include", cIncludePrefix
+ + "include", attributes);
+ super.endElement(this.cIncludeNamespace, "include", cIncludePrefix
+ + "include");
+ super.endElement(NAMESPACE, "child", PREFIX + "child");
+ } else {
+ //do nothing for this child
+ getLogger().warn(
+ "There are no existing file for the child with id " + childId);
}
- AttributesImpl attribute = new AttributesImpl();
- attribute.addAttribute("", "href", "href", "", url);
- super.startElement(NAMESPACE, "child", PREFIX + "child", attribute);
-
- AttributesImpl attributes = new AttributesImpl();
- attributes.addAttribute("", "src", "src", "", path);
- attributes.addAttribute("", "element", "element", "", "included");
-
- super.startElement(this.cIncludeNamespace, "include", cIncludePrefix
- + "include", attributes);
- super.endElement(this.cIncludeNamespace, "include", cIncludePrefix + "include");
- super.endElement(NAMESPACE, "child", PREFIX + "child");
- } else {
- //do nothing for this child
- getLogger().warn("There are no existing file for the child with id " + childId);
}
-
+ } else {
+ super.startElement(uri, localName, raw, attr);
}
- } else {
- super.startElement(uri, localName, raw, attr);
+ } catch (DocumentException e) {
+ throw new RuntimeException(e);
}
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractPublication.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractPublication.java Mon Sep 20 05:52:15 2004
@@ -311,6 +311,12 @@
}
/**
+ * @see org.apache.lenya.cms.publication.Publication#addDocument(org.apache.lenya.cms.publication.Document)
+ */
+ public void addDocument(Document document) throws PublicationException {
+ getSiteManager(document.getIdentityMap()).add(document);
+ }
+ /**
* Template method to copy a document. Override {@link #copyDocumentSource(Document, Document)}
* to implement access to a custom repository.
* @see org.apache.lenya.cms.publication.Publication#copyDocument(org.apache.lenya.cms.publication.Document,
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Mon Sep 20 05:52:15 2004
@@ -20,13 +20,13 @@
package org.apache.lenya.cms.publication;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.metadata.dublincore.DublinCoreProxy;
-import org.apache.lenya.cms.site.Label;
import org.apache.lenya.cms.site.SiteException;
import org.apache.lenya.cms.site.SiteManager;
@@ -213,8 +213,7 @@
try {
SiteManager siteManager = getPublication().getSiteManager(getIdentityMap());
if (siteManager != null) {
- Label label = siteManager.getLabel(this);
- labelString = label.getLabel();
+ labelString = siteManager.getLabel(this);
}
} catch (SiteException e) {
throw new DocumentException(e);
@@ -390,6 +389,17 @@
*/
public String getCanonicalDocumentURL() {
return getDocumentURL();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.Document#getSourceURI()
+ */
+ public String getSourceURI() {
+ try {
+ return "file:/" + getFile().getCanonicalPath();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Mon Sep 20 05:52:15 2004
@@ -162,8 +162,8 @@
/**
* Returns the file for this document.
* @return A file object.
- File getFile();
*/
+ File getFile();
/**
* Returns the extension in the URL.
@@ -197,5 +197,11 @@
* @return A document identity map.
*/
DocumentIdentityMap getIdentityMap();
+
+ /**
+ * Returns the URI to resolve the document's source.
+ * @return A string.
+ */
+ String getSourceURI();
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Mon Sep 20 05:52:15 2004
@@ -170,6 +170,13 @@
*/
void copyDocumentSetToArea(DocumentSet documentSet, String destinationArea)
throws PublicationException;
+
+ /**
+ * Adds a document.
+ * @param document The document.
+ * @throws PublicationException if the document is already contained.
+ */
+ void addDocument(Document document) throws PublicationException;
/**
* Deletes a document.
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java Mon Sep 20 05:52:15 2004
@@ -64,6 +64,13 @@
* @throws SiteException if an error occurs.
*/
Document[] getRequiringResources(Document resource) throws SiteException;
+
+ /**
+ * Adds a document to the site structure.
+ * @param document The document to add.
+ * @throws SiteException if the document is already contained.
+ */
+ void add(Document document) throws SiteException;
/**
* Checks if the site structure contains a certain resource in a certain area.
@@ -103,7 +110,15 @@
* @return A label.
* @throws SiteException if an error occurs.
*/
- Label getLabel(Document document) throws SiteException;
+ String getLabel(Document document) throws SiteException;
+
+ /**
+ * Sets the label of a certain document.
+ * @param document The document.
+ * @param label The label.
+ * @throws SiteException if an error occurs.
+ */
+ void setLabel(Document document, String label) throws SiteException;
/**
* Returns all documents in a certain area.
@@ -118,4 +133,5 @@
* @param map A resource identity map.
*/
void setIdentityMap(DocumentIdentityMap map);
+
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java Mon Sep 20 05:52:15 2004
@@ -257,7 +257,29 @@
/**
* @see org.apache.lenya.cms.site.SiteManager#getLabel(org.apache.lenya.cms.publication.Document)
*/
- public Label getLabel(Document document) throws SiteException {
+ public String getLabel(Document document) throws SiteException {
+ Label label = getLabelObject(document);
+ return label.getLabel();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#setLabel(org.apache.lenya.cms.publication.Document,
+ * java.lang.String)
+ */
+ public void setLabel(Document document, String label) throws SiteException {
+ Label labelObject = getLabelObject(document);
+ labelObject.setLabel(label);
+ SiteTree tree = getTree(document.getArea());
+ tree.save();
+ }
+
+ /**
+ * Returns the label object of a document.
+ * @param document The document.
+ * @return A label.
+ * @throws SiteException if an error occurs.
+ */
+ protected Label getLabelObject(Document document) throws SiteException {
Label label = null;
SiteTree siteTree = getTree(document.getArea());
if (siteTree != null) {
@@ -267,6 +289,11 @@
}
label = node.getLabel(document.getLanguage());
}
+
+ if (label == null) {
+ throw new SiteException("The label of document [" + document + "] is null!");
+ }
+
return label;
}
@@ -286,6 +313,22 @@
} catch (DocumentBuildException e) {
throw new SiteException(e);
}
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#add(org.apache.lenya.cms.publication.Document)
+ */
+ public void add(Document document) throws SiteException {
+
+ if (contains(document)) {
+ throw new SiteException("The document [" + document + "] is already contained!");
+ }
+ SiteTree tree = getTree(document.getArea());
+
+ Label label = new Label("", document.getLanguage());
+ Label[] labels = { label };
+ tree.addNode(document.getId(), labels, null, null, false);
+ tree.save();
}
}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractOperation.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractOperation.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,64 @@
+/*
+ * 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.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+/**
+ */
+public class AbstractOperation extends AbstractLogEnabled implements Operation, Serviceable,
+ Initializable, Disposable {
+
+ /**
+ * Ctor.
+ */
+ public AbstractOperation() {
+ super();
+ }
+
+ private UnitOfWork unitOfWork;
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Operation#getUnitOfWork()
+ */
+ public UnitOfWork getUnitOfWork() {
+ return this.unitOfWork;
+ }
+
+ private ServiceManager manager;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ this.unitOfWork = (UnitOfWork) this.manager.lookup(UnitOfWork.ROLE);
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if (this.manager != null) {
+ if (this.unitOfWork != null) {
+ this.manager.release(this.unitOfWork);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,308 @@
+/*
+ * Created on 22.07.2004
+ */
+package org.apache.lenya.cms.usecase;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.lenya.cms.publication.Document;
+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 AbstractUsecase extends AbstractOperation implements Usecase {
+
+ /**
+ * Ctor.
+ */
+ public AbstractUsecase() {
+ }
+
+ 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)
+ */
+ public void setup(Document sourceDocument, Situation situation) {
+ this.sourceDocument = sourceDocument;
+ this.situation = situation;
+
+ initParameters();
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Invoking usecase on document: [" + sourceDocument + "]");
+ }
+ }
+
+ /**
+ * Override to initialize parameters.
+ */
+ protected void initParameters() {
+ }
+
+ /**
+ * Returns the workflow situation.
+ * @return A situation.
+ */
+ protected Situation getSituation() {
+ return this.situation;
+ }
+
+ /**
+ * Returns the source document.
+ * @return A document.
+ */
+ protected Document getSourceDocument() {
+ return sourceDocument;
+ }
+
+ /**
+ * Checks if the operation can be executed and returns the error messages. Error messages
+ * prevent the operation from being executed.
+ * @return A boolean value.
+ */
+ public List getErrorMessages() {
+ return Collections.unmodifiableList(errorMessages);
+ }
+
+ /**
+ * Returns the information messages to show on the confirmation screen.
+ * @return An array of strings. Info messages do not prevent the operation from being executed.
+ */
+ public List getInfoMessages() {
+ return Collections.unmodifiableList(infoMessages);
+ }
+
+ private List errorMessages = new ArrayList();
+ private List infoMessages = new ArrayList();
+
+ /**
+ * Adds an error message.
+ * @param message The message.
+ */
+ protected void addErrorMessage(String message) {
+ errorMessages.add(message);
+ }
+
+ /**
+ * Adds an error message.
+ * @param messages The messages.
+ */
+ protected void addErrorMessages(String[] messages) {
+ for (int i = 0; i < messages.length; i++) {
+ addErrorMessage(messages[i]);
+ }
+ }
+
+ /**
+ * Adds an info message.
+ * @param message The message.
+ */
+ protected void addInfoMessage(String message) {
+ infoMessages.add(message);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#checkExecutionConditions()
+ */
+ public final void checkExecutionConditions() throws UsecaseException {
+ try {
+ clearErrorMessages();
+ clearInfoMessages();
+ doCheckExecutionConditions();
+ dumpErrorMessages();
+ } catch (Exception e) {
+ getLogger().error(e.getMessage(), e);
+ addErrorMessage(e.getMessage() + " - Please consult the logfiles.");
+ if (getLogger().isDebugEnabled()) {
+ throw new UsecaseException(e);
+ }
+ }
+ }
+
+ /**
+ * Checks the execution conditions.
+ * @throws Exception if an error occurs.
+ */
+ protected void doCheckExecutionConditions() throws Exception {
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#checkPreconditions()
+ */
+ public final void checkPreconditions() throws UsecaseException {
+ try {
+ clearErrorMessages();
+ clearInfoMessages();
+ doCheckPreconditions();
+ dumpErrorMessages();
+ } catch (Exception e) {
+ getLogger().error(e.getMessage(), e);
+ addErrorMessage(e.getMessage() + " - Please consult the logfiles.");
+ if (getLogger().isDebugEnabled()) {
+ throw new UsecaseException(e);
+ }
+ }
+ }
+
+ /**
+ * Checks the preconditions.
+ * @throws Exception if an error occurs.
+ */
+ protected void doCheckPreconditions() throws Exception {
+ }
+
+ /**
+ * Clears the error messages.
+ */
+ protected void clearErrorMessages() {
+ errorMessages.clear();
+ }
+
+ /**
+ * Clears the info messages.
+ */
+ protected void clearInfoMessages() {
+ infoMessages.clear();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#execute()
+ */
+ public final void execute() throws UsecaseException {
+ try {
+ clearErrorMessages();
+ clearInfoMessages();
+ doExecute();
+ dumpErrorMessages();
+ } catch (Exception e) {
+ getLogger().error(e.getMessage(), e);
+ addErrorMessage(e.getMessage() + " - Please consult the logfiles.");
+ if (getLogger().isDebugEnabled()) {
+ throw new UsecaseException(e);
+ }
+ }
+ }
+
+ /**
+ * Dumps the error messages to the log and the command line.
+ */
+ protected void dumpErrorMessages() {
+ List errorMessages = getErrorMessages();
+ for (int i = 0; i < errorMessages.size(); i++) {
+ if (getLogger().isDebugEnabled()) {
+ System.out.println("+++ ERROR +++ " + errorMessages.get(i));
+ }
+ getLogger().error((String) errorMessages.get(i));
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#checkPostconditions()
+ */
+ public void checkPostconditions() throws UsecaseException {
+ try {
+ clearErrorMessages();
+ clearInfoMessages();
+ doCheckPostconditions();
+ dumpErrorMessages();
+ } catch (Exception e) {
+ getLogger().error(e.getMessage(), e);
+ addErrorMessage(e.getMessage() + " - Please consult the logfiles.");
+ if (getLogger().isDebugEnabled()) {
+ throw new UsecaseException(e);
+ }
+ }
+ }
+
+ /**
+ * Checks the post conditions.
+ * @throws Exception if an error occured.
+ */
+ protected void doCheckPostconditions() throws Exception {
+ }
+
+ /**
+ * Executes the operation.
+ * @throws Exception when something went wrong.
+ */
+ protected void doExecute() throws Exception {
+ }
+
+ private Map parameters = new HashMap();
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.String)
+ */
+ public void setParameter(String name, String value) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Setting parameter [" + name + "] = [" + value + "]");
+ }
+ this.parameters.put(name, value);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#getParameter(java.lang.String)
+ */
+ public String getParameter(String name) {
+ return (String) parameters.get(name);
+ }
+
+ /**
+ * Returns one of the strings "true" or "false" depending on whether the corresponding checkbox
+ * was checked.
+ * @param name The parameter name.
+ * @return A string.
+ */
+ public String getBooleanCheckboxParameter(String name) {
+ String value = "false";
+ if (getParameter(name) != null && getParameter(name).equals("on")) {
+ value = "true";
+ }
+ return value;
+ }
+
+ private Document targetDocument = null;
+
+ /**
+ * Sets the target document.
+ * @param document A document.
+ */
+ protected void setTargetDocument(Document document) {
+ this.targetDocument = document;
+ }
+
+ /**
+ * If {@link #setTargetDocument(Document)}was not called, the source document (
+ * {@link #getSourceDocument()}) is returned.
+ * @see org.apache.lenya.cms.usecase.Usecase#getTargetDocument(boolean)
+ */
+ public Document getTargetDocument(boolean success) {
+ Document document;
+ if (this.targetDocument != null) {
+ document = this.targetDocument;
+ } else {
+ document = getSourceDocument();
+ }
+ return document;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#setPart(java.lang.String,
+ * org.apache.cocoon.servlet.multipart.Part)
+ */
+ public void setPart(String name, Part value) {
+ }
+
+}
\ No newline at end of file
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Operation.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Operation.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+/**
+ */
+public interface Operation {
+
+ /**
+ * The Avalon role.
+ */
+ String ROLE = Operation.class.getName();
+
+ /**
+ * Returns the unit of work object.
+ * @return A unit of work.
+ */
+ UnitOfWork getUnitOfWork();
+
+}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UnitOfWork.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UnitOfWork.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,29 @@
+/*
+ * 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.DocumentIdentityMap;
+
+/**
+ * This is a "Unit of Work" object (see "Unit of Work" pattern by Martin Fowler).
+ *
+ * @version $Id:$
+ */
+public interface UnitOfWork {
+
+ /**
+ * The Avalon role.
+ */
+ String ROLE = UnitOfWork.class.getName();
+
+ /**
+ * Returns the document identity map.
+ * @return An identity map.
+ */
+ DocumentIdentityMap getIdentityMap();
+
+}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UnitOfWorkImpl.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UnitOfWorkImpl.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,70 @@
+/*
+ <License>
+ </License>
+ */
+package org.apache.lenya.cms.usecase;
+
+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.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.PublicationFactory;
+
+/**
+ * Abstract base class for operations on documents.
+ *
+ * @author <a href="andreas@apache.org">Andreas Hartmann </a>
+ * @version $Id: UnitOfWork.java,v 1.2 2004/06/28 20:25:32 andreas Exp $
+ */
+public class UnitOfWorkImpl extends AbstractLogEnabled implements UnitOfWork, Contextualizable {
+
+ /**
+ * Ctor.
+ */
+ public UnitOfWorkImpl() {
+ }
+
+ private DocumentIdentityMap identityMap;
+
+ /**
+ * Returns the document identity map.
+ * @return A document identity map.
+ */
+ public DocumentIdentityMap getIdentityMap() {
+
+ if (this.identityMap == null) {
+ Map objectModel = ContextHelper.getObjectModel(this.context);
+ Publication publication;
+ try {
+ publication = PublicationFactory.getPublication(objectModel);
+ } catch (PublicationException e) {
+ throw new RuntimeException(e);
+ }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Initializing unit of work for publication [" + publication.getId() + "]");
+ }
+
+ this.identityMap = new DocumentIdentityMap(publication);
+ }
+
+ return identityMap;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+ */
+ public void contextualize(Context context)
+ throws ContextException {
+ this.context = context;
+ }
+
+ /** The environment context */
+ private Context context;
+
+}
\ No newline at end of file
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/Usecase.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,104 @@
+/*
+ * Created on 22.07.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 java.util.List;
+
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.lenya.cms.publication.Document;
+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 interface Usecase {
+
+ /**
+ * The <code>Usecase</code> role.
+ */
+ String ROLE = Usecase.class.getName();
+
+ /**
+ * Sets a parameter from the form.
+ * @param name The parameter name.
+ * @param value The parameter value.
+ */
+ void setParameter(String name, String value);
+
+ /**
+ * Returns the current value of a parameter.
+ * @param name The parameter name.
+ * @return A string.
+ */
+ String getParameter(String name);
+
+ /**
+ * Sets a parameter from the form. This method is called for parts in multipart requests.
+ * @param name The parameter name.
+ * @param value The parameter value.
+ */
+ 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.
+ * @param situation The workflow situation.
+ *
+ */
+ void setup(Document sourceDocument, Situation situation);
+
+ /**
+ * Checks the conditions before a form is displayed.
+ * @throws UsecaseException if an error occurs that causes an unstable system.
+ */
+ void checkPreconditions() throws UsecaseException;
+
+ /**
+ * Checks the conditions after the usecase was executed.
+ * @throws UsecaseException if an error occurs that causes an unstable system.
+ */
+ void checkPostconditions() throws UsecaseException;
+
+ /**
+ * Checks the conditions right before the operation is executed.
+ * @throws UsecaseException if an error occurs that causes an unstable system.
+ */
+ void checkExecutionConditions() throws UsecaseException;
+
+ /**
+ * Returns the error messages from the previous operation. Error messages
+ * prevent the operation from being executed.
+ * @return A list of strings.
+ */
+ List getErrorMessages();
+
+ /**
+ * Returns the info messages from the previous operation. Info messages
+ * do not prevent the operation from being executed.
+ * @return A list of strings.
+ */
+ List getInfoMessages();
+
+ /**
+ * Executes the usecase. During this method error and info messages are
+ * filled in. If getErrorMessages() returns an empty array, the operation
+ * succeeded. Otherwise, the operation failed.
+ * @throws UsecaseException if an error occured that causes an unstable system.
+ */
+ void execute() throws UsecaseException;
+
+ /**
+ * Returns the document which should be shown after the usecase is completed.
+ * @param success If the usecase was completed successfully.
+ * @return A document.
+ */
+ Document getTargetDocument(boolean success);
+
+}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseException.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseException.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,48 @@
+/*
+ * Created on 22.07.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;
+
+/**
+ * @author nobby
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class UsecaseException extends Exception {
+
+ /**
+ *
+ */
+ public UsecaseException() {
+ super();
+ }
+
+ /**
+ * @param arg0
+ */
+ public UsecaseException(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public UsecaseException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public UsecaseException(Throwable arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolver.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolver.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,39 @@
+/*
+ * Created on 22.07.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.avalon.framework.service.ServiceException;
+
+/**
+ * @author nobby
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public interface UsecaseResolver {
+
+ /**
+ * The Avalon role.
+ */
+ String ROLE = UsecaseResolver.class.getName();
+
+ /**
+ * Resolves a usecase object.
+ * @param name The name of the usecase.
+ * @return A usecase object.
+ * @throws ServiceException if the object could not be created.
+ */
+ Usecase resolve(String name) throws ServiceException;
+
+ /**
+ * Releases a usecase object.
+ * @param usecase The usecase object.
+ * @throws ServiceException if an error occurs.
+ */
+ void release(Usecase usecase) throws ServiceException;
+
+}
Added: incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
==============================================================================
--- (empty file)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java Mon Sep 20 05:52:15 2004
@@ -0,0 +1,71 @@
+/*
+ * Created on 22.07.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.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
+
+/**
+ * @author nobby
+ *
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class UsecaseResolverImpl extends AbstractLogEnabled implements UsecaseResolver,
+ Serviceable, Disposable {
+
+ /**
+ * Ctor.
+ */
+ public UsecaseResolverImpl() {
+ }
+
+ private ServiceSelector selector;
+
+ /**
+ * @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;
+ }
+
+ private ServiceManager manager;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ this.selector = (ServiceSelector) manager.lookup(Usecase.ROLE + "Selector");
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.UsecaseResolver#release(org.apache.lenya.cms.usecase.Usecase)
+ */
+ public void release(Usecase usecase) throws ServiceException {
+ if (usecase == null) {
+ throw new IllegalArgumentException("The usecase to release must not be null.");
+ }
+ this.selector.release(usecase);
+
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if (this.selector != null) {
+ this.manager.release(selector);
+ }
+ }
+
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/lenya.roles
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/lenya.roles Mon Sep 20 05:52:15 2004
@@ -78,4 +78,20 @@
shorthand="publication-template-manager"
default-class="org.apache.lenya.cms.publication.templating.PublicationTemplateManagerImpl"/>
+ <role name="org.apache.lenya.cms.usecase.UnitOfWork"
+ shorthand="unit-of-work"
+ default-class="org.apache.lenya.cms.usecase.UnitOfWorkImpl"/>
+
+ <role name="org.apache.lenya.cms.usecase.Operation"
+ shorthand="operation"
+ default-class="org.apache.lenya.cms.usecase.AbstractOperation"/>
+
+ <role name="org.apache.lenya.cms.usecase.UsecaseSelector"
+ shorthand="usecases"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
+
+ <role name="org.apache.lenya.cms.usecase.UsecaseResolver"
+ shorthand="usecase-resolver"
+ default-class="org.apache.lenya.cms.usecase.UsecaseResolverImpl"/>
+
</role-list>
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org