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/06/02 14:15:34 UTC

svn commit: r179575 - in /lenya/trunk/src/java/org/apache/lenya/cms: editors/forms/ metadata/ publication/ workflow/ workflow/usecases/

Author: andreas
Date: Thu Jun  2 05:15:33 2005
New Revision: 179575

URL: http://svn.apache.org/viewcvs?rev=179575&view=rev
Log:
(1) added fallback for doctypes, this means doctypes can be served by the core (1st step towards resource type packages) (2) store workflow state and variable values in meta data. currently the history is stored there as well, this is subject to changes.

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java   (with props)
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java
    lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilderImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java Thu Jun  2 05:15:33 2005
@@ -43,7 +43,7 @@
 import org.apache.excalibur.source.ModifiableSource;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.DocumentType;
 import org.apache.lenya.cms.usecase.DocumentUsecase;
 import org.apache.lenya.cms.usecase.UsecaseException;
 import org.apache.lenya.transaction.Transactionable;
@@ -106,11 +106,6 @@
     public void advance() throws UsecaseException {
         super.advance();
 
-        String form = getParameterAsString("form");
-        String pubUrl = "context://" 
-            + Publication.PUBLICATION_PREFIX + "/"
-            + getSourceDocument().getPublication().getId();
-        String schemaUri = pubUrl + "/config/doctypes/schemas/" + form + ".rng";
         String unnumberTagsXslUri = "context://lenya/usecases/edit/forms/unnumberTags.xsl";
         String numberTagsXslUri = "context://lenya/usecases/edit/forms/numberTags.xsl";
 
@@ -124,7 +119,11 @@
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
 
             xmlSource = (ModifiableSource) resolver.resolveURI(getSourceDocument().getSourceURI());
+            
+            DocumentType resourceType = getSourceDocument().getResourceType();
+            String schemaUri = resourceType.getSchemaDefinitionSourceURI();
             schemaSource = resolver.resolveURI(schemaUri);
+            
             unnumberTagsXslSource = resolver.resolveURI(unnumberTagsXslUri);
             numberTagsXslSource = resolver.resolveURI(numberTagsXslUri);
 

Modified: lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java Thu Jun  2 05:15:33 2005
@@ -30,8 +30,6 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.publication.DocumentType;
-import org.apache.lenya.cms.publication.DocumentTypeResolver;
-import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.usecase.DocumentUsecase;
 import org.apache.lenya.cms.usecase.UsecaseException;
 import org.apache.lenya.transaction.Transactionable;
@@ -75,22 +73,8 @@
 
         // Save file temporarily
 
-        DocumentType doctype;
-        DocumentTypeResolver doctypeResolver = null;
-        try {
-            doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
-            doctype = doctypeResolver.resolve(getSourceDocument());
-        } finally {
-            if (doctypeResolver != null) {
-                this.manager.release(doctypeResolver);
-            }
-        }
-
-        String pubId = getSourceDocument().getPublication().getId();
-        String schemaUri = "context://" 
-            + Publication.PUBLICATION_PREFIX_URI + "/" 
-            + pubId + "/config/doctypes/schemas/"
-            + doctype.getName() + ".rng";
+        DocumentType resourceType = getSourceDocument().getResourceType();
+        String schemaUri = resourceType.getSchemaDefinitionSourceURI();
         Source schemaSource = null;
         ModifiableSource xmlSource = null;
         SourceResolver resolver = null;

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java Thu Jun  2 05:15:33 2005
@@ -48,9 +48,16 @@
      */
     public static final String ELEMENT_CONTENT_TYPE = "contentType";
 
+    /**
+     * A workflow version.
+     * @see org.apache.lenya.cms.workflow.DocumentWorkflowable
+     */
+    public static final String ELEMENT_WORKFLOW_VERSION = "workflowVersion";
+
     static final String[] ELEMENTS = {
        ELEMENT_RESOURCE_TYPE,
-       ELEMENT_CONTENT_TYPE
+       ELEMENT_CONTENT_TYPE,
+       ELEMENT_WORKFLOW_VERSION
     };
 
     /**

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java Thu Jun  2 05:15:33 2005
@@ -55,6 +55,14 @@
      * @throws DocumentException when something went wrong.
      */
     void setValue(String key, String value) throws DocumentException;
+    
+    /**
+     * Addds a value for a certain key. The existing values will not be removed.
+     * @param key The key.
+     * @param value The value to add.
+     * @throws DocumentException when something went wrong.
+     */
+    void addValue(String key, String value) throws DocumentException;
 
     /**
      * Replace the contents of the current meta data by the contents of other.

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java Thu Jun  2 05:15:33 2005
@@ -451,12 +451,9 @@
     }
 
     /**
-     * Adds a value for a certain key.
-     * @param key The key.
-     * @param value The value.
-     * @throws DocumentException if an error occurs.
+     * @see org.apache.lenya.cms.metadata.MetaData#addValue(java.lang.String, java.lang.String)
      */
-    private void addValue(String key, String value) throws DocumentException {
+    public void addValue(String key, String value) throws DocumentException {
         String[] existingValues = getElementOrTerm(key);
         List list = new ArrayList(Arrays.asList(existingValues));
         list.add(value);

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Thu Jun  2 05:15:33 2005
@@ -36,6 +36,7 @@
 import org.apache.lenya.cms.repository.Node;
 import org.apache.lenya.cms.site.SiteManager;
 import org.apache.lenya.cms.workflow.CMSHistory;
+import org.apache.lenya.cms.workflow.DocumentWorkflowable;
 import org.apache.lenya.cms.workflow.History;
 import org.apache.lenya.workflow.Situation;
 import org.apache.lenya.workflow.Version;
@@ -409,17 +410,47 @@
         return this.history;
     }
 
+    protected DocumentWorkflowable workflowable;
+    
+    protected DocumentWorkflowable getWorkflowable() {
+        if (this.workflowable == null) {
+            this.workflowable = new DocumentWorkflowable(this, this.manager, getLogger());
+        }
+        return this.workflowable;
+    }
+
     /**
      * @see org.apache.lenya.workflow.Workflowable#getVersions()
      */
     public Version[] getVersions() {
-        return getHistory().getVersions();
+        return getWorkflowable().getVersions();
     }
 
     /**
      * @see org.apache.lenya.workflow.Workflowable#getLatestVersion()
      */
     public Version getLatestVersion() {
+        return getWorkflowable().getLatestVersion();
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Workflowable#newVersion(org.apache.lenya.workflow.Workflow,
+     *      org.apache.lenya.workflow.Version, org.apache.lenya.workflow.Situation)
+     */
+    public void newVersion(Workflow workflow, Version version, Situation situation) {
+        getWorkflowable().newVersion(workflow, version, situation);
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Workflowable#getVersions()
+    public Version[] getVersions() {
+        return getHistory().getVersions();
+    }
+     */
+
+    /**
+     * @see org.apache.lenya.workflow.Workflowable#getLatestVersion()
+    public Version getLatestVersion() {
         Version[] versions = getVersions();
         Version lastVersion = null;
         if (versions.length > 0) {
@@ -427,14 +458,15 @@
         }
         return lastVersion;
     }
+     */
 
     /**
      * @see org.apache.lenya.workflow.Workflowable#newVersion(org.apache.lenya.workflow.Workflow,
      *      org.apache.lenya.workflow.Version, org.apache.lenya.workflow.Situation)
-     */
     public void newVersion(Workflow workflow, Version version, Situation situation) {
         getHistory().newVersion(workflow, version, situation);
     }
+     */
 
     /**
      * @see org.apache.lenya.cms.publication.Document#delete()

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java Thu Jun  2 05:15:33 2005
@@ -92,8 +92,19 @@
 	 * for this resource type
 	 */
 	public String getSchemaDefinition() {
+        if (this.schemaDefinition == null) {
+            throw new IllegalStateException("No schema assigned to resource type [" + getName() + "]");
+        }
 		return schemaDefinition;
 	}
+    
+    /**
+     * @return The source URI of the RelaxNG schema.
+     */
+    public String getSchemaDefinitionSourceURI() {
+        return "fallback://lenya/resources/schemas/" + getSchemaDefinition();
+    }
+    
 	/**
 	 * @param schemaDefinition The path to the RelaxNG schema
 	 * definition file
@@ -120,38 +131,6 @@
     protected void setCreator(NodeCreatorInterface _creator) {
         assert _creator != null;
         this.creator = _creator;
-    }
-
-    private String workflowFile = null;
-
-    /**
-     * Returns if this document type has a workflow definition.
-     * @return A boolean value.
-     */
-    public boolean hasWorkflow() {
-        return this.workflowFile != null;
-    }
-
-	/**
-	 * Get the file name of the workflow file.
-	 * @return a <code>String</code>
-	 * @throws DocumentTypeBuildException if the document type has no workflow
-	 */
-    public String getWorkflowFileName() throws DocumentTypeBuildException {
-        if (!hasWorkflow()) {
-            throw new DocumentTypeBuildException("The document type '" + getName() +
-                "' has no workflow!");
-        }
-        return this.workflowFile;
-    }
-
-	/**
-	 * Set the file name of the workflow file.
-	 * @param string the new file name
-	 */
-    public void setWorkflowFileName(String string) {
-        assert string != null;
-        this.workflowFile = string;
     }
 
     private String[] linkAttributeXPaths = { };

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilderImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilderImpl.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilderImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilderImpl.java Thu Jun  2 05:15:33 2005
@@ -17,7 +17,6 @@
 
 package org.apache.lenya.cms.publication;
 
-import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -31,8 +30,11 @@
 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.lenya.cms.authoring.DefaultBranchCreator;
 import org.apache.lenya.cms.authoring.NodeCreatorInterface;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 /**
@@ -58,21 +60,10 @@
     }
 
     /**
-     * The default document types configuration directory, relative to the publication directory.
-     */
-    private static final String DOCTYPE_DIRECTORY = "config/doctypes".replace('/',
-            File.separatorChar);
-
-    /**
-     * The location of sample contents for this resource type. Note that this need not be a file.
-     */
-    private static final String DOCTYPE_SAMPLES = "config/doctypes/samples/";
-
-    /**
      * <code>CONFIG_FILE</code> The default document types configuration file, relative to the
      * publication directory.
      */
-    public static final String CONFIG_FILE = "doctypes.xconf";
+    public static final String CONFIG_FILE = "doctype.xconf";
     /**
      * <code>DOCTYPES_ELEMENT</code> The doctypes element
      */
@@ -98,10 +89,6 @@
      */
     public static final String SRC_ATTRIBUTE = "src";
     /**
-     * <code>WORKFLOW_ELEMENT</code> The workflow element
-     */
-    public static final String WORKFLOW_ELEMENT = "workflow";
-    /**
      * <code>ELEMENT_REWRITE_ATTRIBUTE</code> The link-attribute element.
      */
     public static final String ELEMENT_REWRITE_ATTRIBUTE = "link-attribute";
@@ -131,113 +118,97 @@
 
         // see if configuration has changed since last load.
         // if it has, do not use cache.
-        boolean useCache = isEntryUptodate(confLastModifiedCache,
-                publication.getId(),
-                getDocTypeConfigFile(publication).lastModified());
 
         // this will refer to the returned instance
         DocumentType type = null;
 
-        if (useCache) {
-            // try to get an instance from cache
-            type = docTypeCache.get(publication.getId(), name);
-        }
+        String configUri = "fallback://lenya/doctypes/" + name + "/doctype.xconf";
 
-        if (getLogger().isDebugEnabled())
-            getLogger().debug("buildDocumentType() called with name [" + name
-                    + "], publication.getId [" + publication.getId() + "], lookInCache ["
-                    + useCache + "], is in cache [" + (type != null) + "]");
+        Source configSource = null;
+        SourceResolver resolver = null;
+        try {
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            configSource = resolver.resolveURI(configUri);
+
+            boolean useCache = isEntryUptodate(confLastModifiedCache,
+                    publication.getId(),
+                    configSource.getLastModified());
+
+            if (useCache) {
+                // try to get an instance from cache
+                type = docTypeCache.get(publication.getId(), name);
+            }
 
-        if (type == null) {
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("buildDocumentType() called with name [" + name
+                        + "], publication.getId [" + publication.getId() + "], lookInCache ["
+                        + useCache + "], is in cache [" + (type != null) + "]");
 
-            // create a new instance of DocumentType
-            type = new DocumentType(name, getLogger());
+            if (type == null) {
 
-            try {
-                // retrieve configuration for this publication
-                Configuration configuration = getDocTypeConfiguration(publication);
+                // create a new instance of DocumentType
+                type = new DocumentType(name, getLogger());
 
-                // now get configuration for this resource type
-                Configuration[] doctypeConfigurations = configuration.getChildren(DOCTYPE_ELEMENT);
+                try {
+                    // retrieve configuration for this publication
+                    Configuration doctypeConf = getDocTypeConfiguration(configSource, publication);
 
-                Configuration doctypeConf = null;
+                    Configuration schemaConf = doctypeConf.getChild(SCHEMA_ELEMENT, false);
 
-                for (int i = 0; i < doctypeConfigurations.length; i++) {
-                    if (doctypeConfigurations[i].getAttribute(TYPE_ATTRIBUTE).equals(name)) {
-                        doctypeConf = doctypeConfigurations[i];
-                        break;
+                    if (schemaConf != null) {
+                        String schemaFileName = schemaConf.getAttribute(SRC_ATTRIBUTE);
+                        type.setSchemaDefinition(schemaFileName);
                     }
-                }
-
-                if (doctypeConf == null) {
-                    throw new DocumentTypeBuildException("No definition found for doctype '" + name
-                            + "'");
-                }
 
-                Configuration schemaConf = doctypeConf.getChild(SCHEMA_ELEMENT, false);
+                    NodeCreatorInterface creator;
+                    Configuration creatorConf = doctypeConf.getChild(CREATOR_ELEMENT, false);
 
-                if (schemaConf != null) {
-                    String schemaFileName = schemaConf.getAttribute(SRC_ATTRIBUTE);
-                    type.setSchemaDefinition(schemaFileName);
-                }
-
-                NodeCreatorInterface creator;
-                Configuration creatorConf = doctypeConf.getChild(CREATOR_ELEMENT, false);
+                    if (creatorConf != null) {
+                        String creatorClassName = creatorConf.getAttribute(SRC_ATTRIBUTE);
+                        Class creatorClass = Class.forName(creatorClassName);
+                        creator = (NodeCreatorInterface) creatorClass.newInstance();
+                        creator.init(creatorConf, manager, getLogger());
+                    } else {
+                        creator = new DefaultBranchCreator();
+                    }
 
-                if (creatorConf != null) {
-                    String creatorClassName = creatorConf.getAttribute(SRC_ATTRIBUTE);
-                    Class creatorClass = Class.forName(creatorClassName);
-                    creator = (NodeCreatorInterface) creatorClass.newInstance();
-                    creator.init(creatorConf, manager, getLogger());
-                } else {
-                    creator = new DefaultBranchCreator();
-                }
+                    type.setCreator(creator);
 
-                type.setCreator(creator);
+                    // determine the sample content location.
+                    if (creatorConf != null) {
+                        Configuration sampleConf = creatorConf.getChild(SAMPLE_NAME, false);
+                        if (sampleConf != null) {
+                            String sampleLocation = sampleConf.getValue();
+                            type.setSampleContentLocation("fallback://lenya/doctypes/" + name
+                                    + "/samples/" + sampleLocation);
+                        }
+                    }
 
-                // determine the sample content location.
-                if (creatorConf != null) {
-                    Configuration sampleConf = creatorConf.getChild(SAMPLE_NAME, false);
-                    if (sampleConf != null) {
-                        String sampleLocation = sampleConf.getValue();
-                        String pubBase = publication.getSourceURI();
-                        type.setSampleContentLocation("fallback://" + DOCTYPE_SAMPLES + sampleLocation);
+                    Configuration[] rewriteAttributeConfigs = doctypeConf
+                            .getChildren(ELEMENT_REWRITE_ATTRIBUTE);
+                    List xPaths = new ArrayList();
+                    for (int i = 0; i < rewriteAttributeConfigs.length; i++) {
+                        String xPath = rewriteAttributeConfigs[i].getAttribute(ATTRIBUTE_XPATH);
+                        xPaths.add(xPath);
                     }
-                }
+                    String[] xPathArray = (String[]) xPaths.toArray(new String[xPaths.size()]);
+                    type.setLinkAttributeXPaths(xPathArray);
 
-                Configuration workflowConf = doctypeConf.getChild(WORKFLOW_ELEMENT, false);
+                    docTypeCache.add(publication.getId(), name, type);
 
-                if (workflowConf != null) {
-                    String workflowFileName = workflowConf.getAttribute(SRC_ATTRIBUTE);
-                    type.setWorkflowFileName(workflowFileName);
+                } catch (final Exception e) {
+                    throw new DocumentTypeBuildException(e);
                 }
+            }
 
-                Configuration[] rewriteAttributeConfigs = doctypeConf
-                        .getChildren(ELEMENT_REWRITE_ATTRIBUTE);
-                List xPaths = new ArrayList();
-                for (int i = 0; i < rewriteAttributeConfigs.length; i++) {
-                    String xPath = rewriteAttributeConfigs[i].getAttribute(ATTRIBUTE_XPATH);
-                    xPaths.add(xPath);
+        } catch (Exception e) {
+            throw new DocumentTypeBuildException(e);
+        } finally {
+            if (resolver != null) {
+                if (configSource != null) {
+                    resolver.release(configSource);
                 }
-                String[] xPathArray = (String[]) xPaths.toArray(new String[xPaths.size()]);
-                type.setLinkAttributeXPaths(xPathArray);
-
-                docTypeCache.add(publication.getId(), name, type);
-
-            } catch (final ConfigurationException e) {
-                throw new DocumentTypeBuildException(e);
-            } catch (final SAXException e) {
-                throw new DocumentTypeBuildException(e);
-            } catch (final IOException e) {
-                throw new DocumentTypeBuildException(e);
-            } catch (final DocumentTypeBuildException e) {
-                throw new DocumentTypeBuildException(e);
-            } catch (final ClassNotFoundException e) {
-                throw new DocumentTypeBuildException(e);
-            } catch (final InstantiationException e) {
-                throw new DocumentTypeBuildException(e);
-            } catch (final IllegalAccessException e) {
-                throw new DocumentTypeBuildException(e);
+                this.manager.release(resolver);
             }
         }
 
@@ -250,7 +221,7 @@
     private Hashtable confCache = new Hashtable();
     private Hashtable confLastModifiedCache = new Hashtable();
 
-    private Configuration getDocTypeConfiguration(Publication _publication)
+    private Configuration getDocTypeConfiguration(Source source, Publication _publication)
             throws DocumentTypeBuildException, SAXException, IOException, ConfigurationException {
 
         Object conf = confCache.get(_publication.getId());
@@ -259,14 +230,13 @@
             getLogger().debug("getDocTypeConfiguration() for publication [" + _publication.getId()
                     + "], conf in cache ? " + (conf != null));
 
-        File configFile = getDocTypeConfigFile(_publication);
-        if (!configFile.exists())
-            throw new DocumentTypeBuildException("configuration file for publication ["
-                    + _publication.getId() + "] does not exist");
+        if (!source.exists())
+            throw new DocumentTypeBuildException("configuration file [" + source.getURI()
+                    + "] for publication [" + _publication.getId() + "] does not exist");
 
         if (conf == null
-                || !isEntryUptodate(confLastModifiedCache, _publication.getId(), configFile
-                        .lastModified())) {
+                || !isEntryUptodate(confLastModifiedCache, _publication.getId(), source
+                        .getLastModified())) {
 
             // load / reload the configuration from file
             if (getLogger().isDebugEnabled())
@@ -274,11 +244,11 @@
                         .debug("getDocTypeConfiguration() reloading configuration for publication ["
                                 + _publication.getId() + "]");
 
-            conf = new DefaultConfigurationBuilder().buildFromFile(configFile);
-
+            conf = new DefaultConfigurationBuilder()
+                    .build(new InputSource(source.getInputStream()));
             // put in cache
             confCache.put(_publication.getId(), conf);
-            confLastModifiedCache.put(_publication.getId(), new Long(configFile.lastModified()));
+            confLastModifiedCache.put(_publication.getId(), new Long(source.getLastModified()));
         }
 
         return (Configuration) conf;
@@ -305,23 +275,6 @@
         }
 
         return isUptodate;
-    }
-
-    /**
-     * @param _publication The publication.
-     * @return The doctype configuration file.
-     * @throws DocumentTypeBuildException if the configuration file does not exist.
-     */
-    private File getDocTypeConfigFile(Publication _publication) throws DocumentTypeBuildException {
-
-        File configDirectory = new File(_publication.getDirectory(), DOCTYPE_DIRECTORY);
-        File ret = new File(configDirectory, CONFIG_FILE);
-        if (!ret.exists())
-            throw new DocumentTypeBuildException(
-                    "Resource types configuration file for publication " + _publication.getId()
-                            + " does not exist; should be located at [" + ret.getPath() + "]");
-
-        return ret;
     }
 
     protected ServiceManager manager;

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Thu Jun  2 05:15:33 2005
@@ -190,4 +190,16 @@
      */
     String getContentURI(String area);
 
-}
+    /**
+     * @param resourceType The resource type or <code>null</code> if no workflow is registered for
+     *            this resource type.
+     * @return The workflow schema to use for this resource type.
+     */
+    String getWorkflowSchema(DocumentType resourceType);
+    
+    /**
+     * @return The resource types that are supported by this publication.
+     */
+    String[] getResourceTypeNames();
+
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java Thu Jun  2 05:15:33 2005
@@ -70,6 +70,8 @@
     private static final String LANGUAGES = "languages";
     private static final String DEFAULT_LANGUAGE_ATTR = "default";
     private static final String BREADCRUMB_PREFIX = "breadcrumb-prefix";
+    private static final String ELEMENT_RESOURCE_TYPE = "resource-type";
+    private static final String ATTRIBUTE_WORKFLOW = "workflow";
 
     /**
      * Creates a new instance of Publication
@@ -184,6 +186,17 @@
                         .getAttribute(PublicationImpl.ATTRIBUTE_NAME);
             }
 
+            Configuration[] resourceTypeConfigs = config.getChildren(ELEMENT_RESOURCE_TYPE);
+            for (int i = 0; i< resourceTypeConfigs.length; i++) {
+                String name = resourceTypeConfigs[i].getAttribute(ATTRIBUTE_NAME);
+                this.resourceTypes.add(name);
+                
+                String workflow = resourceTypeConfigs[i].getAttribute(ATTRIBUTE_WORKFLOW, null);
+                if (workflow != null) {
+                    this.resourceType2workflow.put(name, workflow);
+                }
+            }
+            
         } catch (final Exception e) {
             throw new RuntimeException("Problem with config file: " + configFile.getAbsolutePath(),
                     e);
@@ -413,6 +426,25 @@
      */
     public String getContentURI(String area) {
         return getSourceURI() + "/" + CONTENT_PATH + "/" + area;
+    }
+    
+    private Map resourceType2workflow = new HashMap();
+
+    /**
+     * @see org.apache.lenya.cms.publication.Publication#getWorkflowSchema(org.apache.lenya.cms.publication.DocumentType)
+     */
+    public String getWorkflowSchema(DocumentType resourceType) {
+        String workflow = (String) this.resourceType2workflow.get(resourceType.getName());
+        return workflow;
+    }
+    
+    private List resourceTypes = new ArrayList();
+
+    /**
+     * @see org.apache.lenya.cms.publication.Publication#getResourceTypeNames()
+     */
+    public String[] getResourceTypeNames() {
+        return (String[]) resourceTypes.toArray(new String[resourceTypes.size()]);
     }
 
 }

Added: lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java?rev=179575&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java Thu Jun  2 05:15:33 2005
@@ -0,0 +1,187 @@
+/*
+ * Created on 27.05.2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.lenya.cms.workflow;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.Version;
+import org.apache.lenya.workflow.Workflow;
+import org.apache.lenya.workflow.Workflowable;
+
+/**
+ * @author nobby
+ * 
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class DocumentWorkflowable extends AbstractLogEnabled implements Workflowable {
+
+    /**
+     * Ctor.
+     * @param document The document.
+     * @param manager The service manager.
+     * @param logger The logger.
+     */
+    public DocumentWorkflowable(Document document, ServiceManager manager, Logger logger) {
+        this.document = document;
+        this.manager = manager;
+        ContainerUtil.enableLogging(this, logger);
+    }
+
+    private Document document;
+    private ServiceManager manager;
+
+    protected String getWorkflowName() {
+        String workflowName = null;
+        try {
+            DocumentType doctype = document.getResourceType();
+            if (doctype != null) {
+                workflowName = document.getPublication().getWorkflowSchema(doctype);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return workflowName;
+    }
+
+    private Version[] versions = null;
+
+    /**
+     * @see org.apache.lenya.workflow.Workflowable#getVersions()
+     */
+    public Version[] getVersions() {
+        if (this.versions == null) {
+            try {
+                LenyaMetaData meta = this.document.getMetaDataManager().getLenyaMetaData();
+
+                String[] versionStrings = meta.getValues(LenyaMetaData.ELEMENT_WORKFLOW_VERSION);
+                this.versions = new Version[versionStrings.length];
+                for (int i = 0; i < versionStrings.length; i++) {
+                    String string = versionStrings[i];
+                    int spaceIndex = string.indexOf(" ");
+                    String numberString = string.substring(0, spaceIndex);
+                    int number = Integer.parseInt(numberString);
+                    String versionString = string.substring(spaceIndex + 1);
+                    Version version = decodeVersion(versionString);
+                    this.versions[number] = version;
+                }
+
+            } catch (DocumentException e) {
+                throw new RuntimeException();
+            }
+        }
+        return this.versions;
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Workflowable#getLatestVersion()
+     */
+    public Version getLatestVersion() {
+        Version version = null;
+        Version[] versions = getVersions();
+        if (versions.length > 0) {
+            version = versions[versions.length - 1];
+        }
+        return version;
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Workflowable#newVersion(org.apache.lenya.workflow.Workflow,
+     *      org.apache.lenya.workflow.Version, org.apache.lenya.workflow.Situation)
+     */
+    public void newVersion(Workflow workflow, Version version, Situation situation) {
+        Version[] newVersions = new Version[getVersions().length + 1];
+        for (int i = 0; i < getVersions().length; i++) {
+            newVersions[i] = getVersions()[i];
+        }
+
+        int number = newVersions.length - 1;
+        newVersions[number] = version;
+
+        String string = number + " " + encodeVersion(version, (CMSSituation) situation);
+        try {
+            LenyaMetaData meta = this.document.getMetaDataManager().getLenyaMetaData();
+            meta.addValue(LenyaMetaData.ELEMENT_WORKFLOW_VERSION, string);
+            meta.save();
+        } catch (DocumentException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected String encodeVersion(Version version, CMSSituation situation) {
+
+        String string = "event:" + version.getEvent();
+        string += " state:" + version.getState();
+
+        string += " user:" + situation.getUserId();
+        string += " machine:" + situation.getMachineIp();
+
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
+        string += " date:" + format.format(new Date());
+
+        WorkflowResolver resolver = null;
+        try {
+            resolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+            Workflow workflow = resolver.getWorkflowSchema(this.document);
+            String names[] = workflow.getVariableNames();
+            for (int i = 0; i < names.length; i++) {
+                String value = Boolean.toString(version.getValue(names[i]));
+                string += " var:" + names[i] + "=" + value;
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (resolver != null) {
+                this.manager.release(resolver);
+            }
+        }
+        return string;
+    }
+
+    protected Version decodeVersion(String string) {
+
+        String event = null;
+        String state = null;
+        Map variables = new HashMap();
+
+        String[] parts = string.split(" ");
+        for (int i = 0; i < parts.length; i++) {
+            String[] steps = parts[i].split(":");
+            if (steps[0].equals("event")) {
+                event = steps[1];
+            }
+            if (steps[0].equals("state")) {
+                state = steps[1];
+            }
+            if (steps[0].equals("var")) {
+                String[] nameValue = steps[1].split("=");
+                variables.put(nameValue[0], nameValue[1]);
+            }
+        }
+        Version version = new CMSVersion(event, state);
+        for (Iterator i = variables.keySet().iterator(); i.hasNext();) {
+            String name = (String) i.next();
+            String value = (String) variables.get(name);
+            version.setValue(name, Boolean.valueOf(value).booleanValue());
+        }
+        return version;
+    }
+
+}
\ No newline at end of file

Propchange: lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java Thu Jun  2 05:15:33 2005
@@ -23,9 +23,6 @@
 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.components.ContextHelper;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
@@ -51,7 +48,7 @@
  * @version $Id$
  */
 public class WorkflowResolverImpl extends AbstractLogEnabled implements WorkflowResolver,
-        Contextualizable, Serviceable {
+        Contextualizable {
 
     /**
      * @see org.apache.lenya.cms.workflow.WorkflowResolver#getWorkflowSchema(org.apache.lenya.cms.publication.Document)
@@ -61,14 +58,14 @@
 
         try {
             DocumentType doctype = document.getResourceType();
-            if (doctype.hasWorkflow()) {
-                String workflowFileName = doctype.getWorkflowFileName();
+            String workflowSchema = document.getPublication().getWorkflowSchema(doctype);
+            if (workflowSchema != null) {
                 Publication publication = document.getPublication();
 
                 File workflowDirectory = new File(publication.getDirectory(), WORKFLOW_DIRECTORY);
-                File workflowFile = new File(workflowDirectory, workflowFileName);
+                File workflowFile = new File(workflowDirectory, workflowSchema);
                 WorkflowBuilder builder = new WorkflowBuilder(getLogger());
-                workflow = builder.buildWorkflow(workflowFileName, workflowFile);
+                workflow = builder.buildWorkflow(workflowSchema, workflowFile);
             }
         } catch (final Exception e) {
             throw new WorkflowException(e);
@@ -136,7 +133,7 @@
         try {
             if (document.exists()) {
                 DocumentType doctype = document.getResourceType();
-                hasWorkflow = doctype.hasWorkflow();
+                hasWorkflow = (document.getPublication().getWorkflowSchema(doctype) != null);
             }
         } catch (final Exception e) {
             throw new RuntimeException(e);
@@ -146,14 +143,5 @@
 
     protected static final String WORKFLOW_DIRECTORY = "config/workflow".replace('/',
             File.separatorChar);
-
-    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: lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java?rev=179575&r1=179574&r2=179575&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java Thu Jun  2 05:15:33 2005
@@ -29,11 +29,13 @@
  * <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>
@@ -65,7 +67,8 @@
         try {
             workflowManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
             if (!workflowManager.canInvoke(getSourceDocument(), getEvent())) {
-                addErrorMessage("error-workflow-document", new String[]{getEvent(), getSourceDocument().getId()});
+                addErrorMessage("error-workflow-document", new String[] { getEvent(),
+                        getSourceDocument().getId() });
             }
         } finally {
             if (workflowManager != null) {
@@ -108,4 +111,4 @@
         this.event = config.getChild(ELEMENT_EVENT).getAttribute(ATTRIBUTE_ID);
     }
 
-}
+}
\ No newline at end of file



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