You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/04/07 11:31:00 UTC

svn commit: r160396 [2/2] - in lenya/trunk/src: java/org/apache/lenya/ac/impl/ java/org/apache/lenya/cms/cocoon/components/modules/input/ java/org/apache/lenya/cms/cocoon/source/ java/org/apache/lenya/cms/metadata/dublincore/ java/org/apache/lenya/cms/metadata/usecases/ java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/rc/ java/org/apache/lenya/cms/site/ java/org/apache/lenya/cms/site/topicmap/ java/org/apache/lenya/cms/site/tree/ java/org/apache/lenya/cms/usecase/ java/org/apache/lenya/cms/usecase/scheduling/ java/org/apache/lenya/cms/workflow/ java/org/apache/lenya/transaction/ webapp/lenya/pubs/default/ webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/ webapp/lenya/usecases/

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/History.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/History.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/History.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/History.java Thu Apr  7 02:30:55 2005
@@ -19,7 +19,6 @@
 
 package org.apache.lenya.cms.workflow;
 
-import java.io.File;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -27,29 +26,30 @@
 import java.util.GregorianCalendar;
 import java.util.List;
 
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
 import org.apache.lenya.workflow.Situation;
 import org.apache.lenya.workflow.Version;
 import org.apache.lenya.workflow.Workflow;
 import org.apache.lenya.workflow.WorkflowException;
 import org.apache.lenya.workflow.impl.VersionImpl;
-import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 /**
  * <p>
- * The history of a workflow instance contains a list of all versions of the
- * instance. A version contains
+ * The history of a workflow instance contains a list of all versions of the instance. A version
+ * contains
  * </p>
  * <ul>
  * <li>the state,</li>
- * <li>the event that caused the transition (omitted in the first version),
- * </li>
+ * <li>the event that caused the transition (omitted in the first version),</li>
  * <li>all variable assignments.</li>
  * </ul>
  */
-public abstract class History {
+public abstract class History extends AbstractLogEnabled {
 
     /**
      * <code>WORKFLOW_ATTRIBUTE</code> The workflow attribute
@@ -108,47 +108,57 @@
      * <code>IP_ATTRIBUTE</code> The IP attribute
      */
     public static final String IP_ATTRIBUTE = "ip-address";
-
-    private File historyFile;
-    private List versions;
+    protected ServiceManager manager;
+    private String sourceUri;
 
     /**
      * Creates a new history object for a workflow instance.
-     * @param historyFile The history file.
+     * @param sourceUri The URI of the source to store the history.
+     * @param manager The service manager.
      * @throws WorkflowException if an error occurs.
      */
-    public History(File historyFile) throws WorkflowException {
-        this.historyFile = historyFile;
+    public History(String sourceUri, ServiceManager manager)
+            throws WorkflowException {
+        this.manager = manager;
+
+        if (sourceUri == null) {
+            throw new WorkflowException("The source URI must not be null!");
+        }
+        this.sourceUri = sourceUri;
+
     }
 
     /**
      * @return An array of version wrappers.
      */
-    protected VersionWrapper[] getVersionWrappers() {
+    protected List getVersionWrappers() {
 
-        if (this.versions == null) {
-            this.versions = new ArrayList();
-            if (getHistoryFile().exists()) {
+        List versions = new ArrayList();
+        try {
+            Document document = SourceUtil.readDOM(this.sourceUri, this.manager);
+            if (document != null) {
                 NamespaceHelper helper = getNamespaceHelper();
                 Element documentElement = helper.getDocument().getDocumentElement();
                 Element[] versionElements = helper.getChildren(documentElement, VERSION_ELEMENT);
                 for (int i = 0; i < versionElements.length; i++) {
                     VersionWrapper version = restoreVersion(helper, versionElements[i]);
-                    this.versions.add(version);
+                    versions.add(version);
                 }
             }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
-        return (VersionWrapper[]) this.versions.toArray(new VersionWrapper[this.versions.size()]);
+        return versions;
     }
 
     /**
      * @return An array of versions.
      */
     public Version[] getVersions() {
-        VersionWrapper[] wrappers = getVersionWrappers();
-        Version[] versions = new Version[wrappers.length];
+        List wrappers = getVersionWrappers();
+        Version[] versions = new Version[wrappers.size()];
         for (int i = 0; i < versions.length; i++) {
-            versions[i] = wrappers[i].getVersion();
+            versions[i] = ((VersionWrapper) wrappers.get(i)).getVersion();
         }
         return versions;
     }
@@ -160,8 +170,8 @@
     protected NamespaceHelper getNamespaceHelper() {
         NamespaceHelper helper;
         try {
-            if (getHistoryFile().exists()) {
-                Document document = DocumentHelper.readDocument(getHistoryFile());
+            Document document = SourceUtil.readDOM(this.sourceUri, this.manager);
+            if (document != null) {
                 helper = new NamespaceHelper(Workflow.NAMESPACE, Workflow.DEFAULT_PREFIX, document);
             } else {
                 helper = new NamespaceHelper(Workflow.NAMESPACE, Workflow.DEFAULT_PREFIX,
@@ -200,51 +210,37 @@
         return workflowId;
     }
 
-    /**
-     * Factory method to obtain the history file.
-     * @return A file.
-     */
-    protected File getHistoryFile() {
-        return this.historyFile;
-    }
-
     protected VersionWrapper createVersionWrapper() {
         return new VersionWrapper();
     }
 
     /**
-     * Saves the history.
+     * Adds a new version to the history.
+     * @param workflow The workflow.
+     * @param version The version.
+     * @param situation The situation.
      */
-    public void save() {
+    public void newVersion(Workflow workflow, Version version, Situation situation) {
+        List versions = getVersionWrappers();
+        VersionWrapper wrapper = createVersionWrapper();
+        wrapper.initialize(workflow, version, situation);
+        versions.add(wrapper);
         try {
             NamespaceHelper helper = new NamespaceHelper(Workflow.NAMESPACE,
                     Workflow.DEFAULT_PREFIX, HISTORY_ELEMENT);
 
             Element documentElement = helper.getDocument().getDocumentElement();
-            VersionWrapper[] versions = getVersionWrappers();
-            for (int i = 0; i < versions.length; i++) {
-                Element versionElement = versions[i].getVersionElement(helper);
+            for (int i = 0; i < versions.size(); i++) {
+                Element versionElement = ((VersionWrapper) versions.get(i)).getVersionElement(helper);
                 documentElement.appendChild(versionElement);
             }
-            DocumentHelper.writeDocument(helper.getDocument(), getHistoryFile());
+            SourceUtil.writeDOM(helper.getDocument(), this.sourceUri, this.manager);
         } catch (final Exception e) {
             throw new RuntimeException(e);
         }
     }
 
     /**
-     * Adds a new version to the history.
-     * @param workflow The workflow.
-     * @param version The version.
-     * @param situation The situation.
-     */
-    public void newVersion(Workflow workflow, Version version, Situation situation) {
-        VersionWrapper wrapper = createVersionWrapper();
-        wrapper.initialize(workflow, version, situation);
-        this.versions.add(wrapper);
-    }
-
-    /**
      * Restores a version from an XML element.
      * @param helper The namespace helper.
      * @param element An XML element.
@@ -262,21 +258,18 @@
     }
 
     /**
-     * Deletes the history.
-     * @throws WorkflowException when something went wrong.
+     * @throws WorkflowException if an error occurs.
      */
     public void delete() throws WorkflowException {
-        if (getHistoryFile().exists()) {
-            boolean deleted = getHistoryFile().delete();
-            if (!deleted) {
-                throw new WorkflowException("The workflow history could not be deleted!");
-            }
+        try {
+            SourceUtil.delete(this.sourceUri, this.manager);
+        } catch (Exception e) {
+            throw new WorkflowException(e);
         }
     }
 
     /**
-     * Use subclasses of this class to store additional information for a
-     * version.
+     * Use subclasses of this class to store additional information for a version.
      */
     public class VersionWrapper {
 
@@ -372,6 +365,13 @@
             return versionElement;
         }
 
+    }
+
+    /**
+     * @return The source URI.
+     */
+    public String getSourceURI() {
+        return this.sourceUri;
     }
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowManagerImpl.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowManagerImpl.java Thu Apr  7 02:30:55 2005
@@ -60,8 +60,6 @@
                             + "] in the situation [" + situation + "]");
                 }
                 engine.invoke(document, workflow, situation, event);
-
-                ((DefaultDocument) document).getHistory().save();
             }
         } catch (ServiceException e) {
             throw new WorkflowException(e);
@@ -176,11 +174,11 @@
 
                 sourceResolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
 
-                String sourceUri = ((DefaultDocument) source).getHistorySourceURI();
+                String sourceUri = ((DefaultDocument) source).getHistory().getSourceURI();
                 sourceHistory = sourceResolver.resolveURI(sourceUri);
 
                 if (sourceHistory.exists()) {
-                    String targetUri = ((DefaultDocument) target).getHistorySourceURI();
+                    String targetUri = ((DefaultDocument) target).getHistory().getSourceURI();
                     targetHistory = sourceResolver.resolveURI(targetUri);
                     SourceUtil.copy(sourceHistory, (ModifiableSource) targetHistory, true);
                 }
@@ -224,7 +222,7 @@
             resolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
             if (resolver.hasWorkflow(sourceDocument)) {
                 sourceResolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
-                String uri = ((DefaultDocument) sourceDocument).getHistorySourceURI();
+                String uri = ((DefaultDocument) sourceDocument).getHistory().getSourceURI();
                 historySource = sourceResolver.resolveURI(uri);
                 if (historySource.exists()) {
                     ((ModifiableSource) historySource).delete();

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?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java Thu Apr  7 02:30:55 2005
@@ -150,7 +150,7 @@
         boolean hasWorkflow = false;
         try {
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
-            String uri = ((DefaultDocument) document).getHistorySourceURI();
+            String uri = ((DefaultDocument) document).getHistory().getSourceURI();
             source = resolver.resolveURI(uri);
             if (source.exists()) {
                 hasWorkflow = true;

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/AbstractOperation.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/transaction/AbstractOperation.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/AbstractOperation.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/AbstractOperation.java Thu Apr  7 02:30:55 2005
@@ -19,10 +19,15 @@
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.container.ContainerUtil;
+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.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.Session;
 
 /**
  * Abstract operation implementation.
@@ -30,7 +35,7 @@
  * @version $Id: AbstractOperation.java 158088 2005-03-18 16:17:38Z jwkaltz $
  */
 public class AbstractOperation extends AbstractLogEnabled implements Operation, Serviceable,
-        Initializable, Disposable {
+        Initializable, Disposable, Contextualizable {
 
     /**
      * Ctor.
@@ -42,31 +47,33 @@
     private UnitOfWork unitOfWork;
 
     /**
-     * Retrieves a unit-of-work, which gives the operation access to business
-     * objects affected by the operation.
-     *
+     * Retrieves a unit-of-work, which gives the operation access to business objects affected by
+     * the operation.
+     * 
      * @return a UnitOfWork, the interface to access the objects
-     * @throws ServiceException if the unit-of-work component can not be initialized by the component framework
-     *
+     * @throws ServiceException if the unit-of-work component can not be initialized by the
+     *             component framework
+     * 
      * @see org.apache.lenya.transaction.Operation#getUnitOfWork()
      */
     public UnitOfWork getUnitOfWork() throws ServiceException {
         if (this.unitOfWork == null) {
-           if (getLogger().isDebugEnabled())
-               getLogger().debug("AbstractOperation.getUnitOfWork() does not yet have instance, looking up role [" + UnitOfWork.ROLE + "]");
-
-           this.unitOfWork = new UnitOfWorkImpl();
-           ContainerUtil.enableLogging(this.unitOfWork, getLogger());
+            setUnitOfWork(new UnitOfWorkImpl());
         }
 
         return this.unitOfWork;
     }
-    
+
     /**
      * @param unit The unit of work.
      */
     public void setUnitOfWork(UnitOfWork unit) {
         this.unitOfWork = unit;
+        ContainerUtil.enableLogging(this.unitOfWork, getLogger());
+        Session session = ContextHelper.getRequest(this.context).getSession(false);
+        if (session != null) {
+            session.setAttribute(UnitOfWork.class.getName(), unit);
+        }
     }
 
     protected ServiceManager manager;
@@ -82,7 +89,11 @@
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        // do nothing
+        // reset the unit of work
+        /*
+         * Session session = ContextHelper.getRequest(this.context).getSession(false); if (session !=
+         * null) { session.setAttribute(UnitOfWork.class.getName(), null); }
+         */
     }
 
     /**
@@ -96,4 +107,13 @@
         }
     }
 
-}
+    protected Context context;
+
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/IdentityMapImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/transaction/IdentityMapImpl.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/IdentityMapImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/IdentityMapImpl.java Thu Apr  7 02:30:55 2005
@@ -46,7 +46,6 @@
         if (transactionable == null) {
             try {
                 transactionable = getFactory(type).build(this, key);
-                transactionable.lock();
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/Transactionable.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/transaction/Transactionable.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/Transactionable.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/Transactionable.java Thu Apr  7 02:30:55 2005
@@ -88,9 +88,10 @@
     String getTransactionableType();
     
     /**
-     * @return The latest version.
+     * Checks if the transactionable has been changed since it has been locked.
+     * @return A boolean value.
      * @throws TransactionException if an error occurs.
      */
-    int getVersion() throws TransactionException;
+    boolean hasChanged() throws TransactionException;
     
 }

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java Thu Apr  7 02:30:55 2005
@@ -107,7 +107,7 @@
 
         for (Iterator i = involvedObjects.iterator(); i.hasNext();) {
             Transactionable t = (Transactionable) i.next();
-            if (t.getVersion() > t.getLock().getVersion()) {
+            if (t.hasChanged()) {
                 throw new LockException("Cannot commit transaction: The object [" + t
                         + "] was modified after it has been locked.");
             }

Modified: lenya/trunk/src/webapp/lenya/pubs/default/doctypes.xmap
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/doctypes.xmap?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/doctypes.xmap (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/doctypes.xmap Thu Apr  7 02:30:55 2005
@@ -40,7 +40,7 @@
       <!-- parametrized doctype matcher -->
       <!-- pattern="{rendertype}/{area}/{doctype}/{document-path}" -->
       <map:match pattern="*/*/*/**.xml">
-        <map:generate src="lenya:/{4}.xml"/>
+        <map:generate src="content/{2}/{4}.xml"/>
         <map:transform src="fallback://xslt/{3}2xhtml.xsl">
           <map:parameter name="rendertype" value="{1}"/>
           <map:parameter name="nodeid" value="{page-envelope:document-name}"/>

Modified: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java Thu Apr  7 02:30:55 2005
@@ -26,7 +26,6 @@
 
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
 import org.apache.lenya.cms.publication.DocumentIdentityMap;
 import org.apache.lenya.cms.publication.DocumentManager;
 import org.apache.lenya.cms.publication.Publication;
@@ -35,6 +34,7 @@
 import org.apache.lenya.cms.publication.util.DocumentSet;
 import org.apache.lenya.cms.site.SiteManager;
 import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
 import org.apache.lenya.cms.usecase.scheduling.UsecaseScheduler;
 import org.apache.lenya.cms.workflow.WorkflowManager;
 import org.apache.lenya.workflow.WorkflowException;
@@ -61,14 +61,41 @@
         Date now = new GregorianCalendar().getTime();
         DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
         setParameter(SCHEDULE_TIME, format.format(now));
-        
-        // resolve involved documents to lock them
-        Document doc = getSourceDocument();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.Usecase#lockInvolvedObjects()
+     */
+    public void lockInvolvedObjects() throws UsecaseException {
+        super.lockInvolvedObjects();
+
+        ServiceSelector selector = null;
+        SiteManager siteManager = null;
         try {
-            Document liveVersion = doc.getIdentityMap().getAreaVersion(doc, Publication.LIVE_AREA);
-            getInvolvedDocuments(liveVersion);
-        } catch (DocumentBuildException e) {
+            Document doc = getSourceDocument();
+            DocumentSet set = getInvolvedDocuments(doc);
+            Document[] documents = set.getDocuments();
+            for (int i = 0; i < documents.length; i++) {
+                Document liveVersion = documents[i].getIdentityMap().getAreaVersion(documents[i],
+                        Publication.LIVE_AREA);
+                liveVersion.lock();
+            }
+
+            selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
+            siteManager = (SiteManager) selector.select(doc.getPublication().getSiteManagerHint());
+            siteManager.getSiteStructure(doc.getIdentityMap(),
+                    doc.getPublication(),
+                    Publication.LIVE_AREA).lock();
+
+        } catch (Exception e) {
             throw new RuntimeException(e);
+        } finally {
+            if (selector != null) {
+                if (siteManager != null) {
+                    selector.release(siteManager);
+                }
+                this.manager.release(selector);
+            }
         }
     }
 
@@ -237,7 +264,7 @@
 
     /**
      * @param document The document.
-     * @return A set containing the document itself and all requiring documents.
+     * @return All documents that are involved in this transaction.
      */
     protected DocumentSet getInvolvedDocuments(Document document) {
         DocumentSet set;

Modified: lenya/trunk/src/webapp/lenya/usecases/usecases.js
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/usecases.js?view=diff&r1=160395&r2=160396
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/usecases.js (original)
+++ lenya/trunk/src/webapp/lenya/usecases/usecases.js Thu Apr  7 02:30:55 2005
@@ -75,6 +75,7 @@
 
         passRequestParameters(flowHelper, usecase);
         usecase.checkPreconditions();
+        usecase.lockInvolvedObjects();
         proxy = new Packages.org.apache.lenya.cms.usecase.UsecaseProxy(usecase);
     }
     finally {



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