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/02/25 11:52:56 UTC

svn commit: r155315 - in lenya/trunk/src: java/org/apache/lenya/ java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/publication/file/ java/org/apache/lenya/cms/publication/task/ java/org/apache/lenya/cms/site/usecases/ java/org/apache/lenya/cms/workflow/usecases/ webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/

Author: andreas
Date: Fri Feb 25 02:52:51 2005
New Revision: 155315

URL: http://svn.apache.org/viewcvs?view=rev&rev=155315
Log:
introduced DocumentManager

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractDocumentManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/file/FileDocumentManager.java
Removed:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/file/FilePublication.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUtility.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/task/CopyDocumentToArea.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java
    lenya/trunk/src/java/org/apache/lenya/lenya.roles
    lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
    lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractDocumentManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractDocumentManager.java?view=auto&rev=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractDocumentManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/AbstractDocumentManager.java Fri Feb 25 02:52:51 2005
@@ -0,0 +1,495 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.publication;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.lenya.cms.publication.util.DocumentSet;
+import org.apache.lenya.cms.publication.util.DocumentVisitor;
+import org.apache.lenya.cms.publication.util.OrderedDocumentSet;
+import org.apache.lenya.cms.publication.util.UniqueDocumentId;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.workflow.WorkflowResolver;
+import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
+
+/**
+ * Abstract DocumentManager implementation.
+ * 
+ * @version $Id:$
+ */
+public abstract class AbstractDocumentManager extends AbstractLogEnabled implements
+        DocumentManager, Serviceable, Contextualizable {
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#addDocument(org.apache.lenya.cms.publication.Document)
+     */
+    public void addDocument(Document document) throws PublicationException {
+
+        Publication publication = document.getPublication();
+        SiteManager siteManager = publication.getSiteManager(document.getIdentityMap());
+        if (siteManager.contains(document)) {
+            throw new PublicationException("The document [" + document
+                    + "] is already contained in this publication!");
+        }
+
+        siteManager.add(document);
+
+        DocumentTypeResolver doctypeResolver = null;
+        WorkflowResolver workflowResolver = null;
+        try {
+            doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+            workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+
+            DocumentType doctype = doctypeResolver.resolve(document);
+
+            if (doctype.hasWorkflow()) {
+                Situation situation = workflowResolver.getSituation();
+                workflowResolver.getWorkflowInstance(document).getHistory().initialize(situation);
+            }
+
+        } catch (ServiceException e) {
+            throw new PublicationException(e);
+        } catch (WorkflowException e) {
+            throw new PublicationException(e);
+        } finally {
+            if (doctypeResolver != null) {
+                this.manager.release(doctypeResolver);
+            }
+        }
+    }
+
+    /**
+     * Template method to copy a document. Override
+     * {@link #copyDocumentSource(Document, Document)}to implement access to a
+     * custom repository.
+     * @see org.apache.lenya.cms.publication.DocumentManager#copyDocument(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void copyDocument(Document sourceDocument, Document destinationDocument)
+            throws PublicationException {
+
+        Publication publication = sourceDocument.getPublication();
+        copyDocumentSource(sourceDocument, destinationDocument);
+        publication.getSiteManager(sourceDocument.getIdentityMap()).copy(sourceDocument,
+                destinationDocument);
+
+        ResourcesManager resourcesManager = sourceDocument.getResourcesManager();
+        WorkflowResolver workflowResolver = null;
+        try {
+            resourcesManager.copyResourcesTo(destinationDocument);
+            
+            workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+            copyWorkflow(workflowResolver, sourceDocument, destinationDocument);
+        } catch (Exception e) {
+            throw new PublicationException(e);
+        }
+        finally {
+            if (workflowResolver != null) {
+                this.manager.release(workflowResolver);
+            }
+        }
+    }
+
+    /**
+     * Moves the workflow history of a document.
+     * @param resolver The workflow resolver.
+     * @param sourceDocument The source document.
+     * @param destinationDocument The destination document.
+     * @throws WorkflowException if an error occurs.
+     */
+    protected void moveWorkflow(WorkflowResolver resolver, Document sourceDocument,
+            Document destinationDocument) throws WorkflowException {
+        copyWorkflow(resolver, sourceDocument, destinationDocument);
+        deleteWorkflow(resolver, sourceDocument);
+    }
+
+    /**
+     * Deletes the workflow history of a document.
+     * @param resolver The workflow resolver.
+     * @param sourceDocument The source document.
+     * @throws WorkflowException if an error occurs.
+     */
+    protected void deleteWorkflow(WorkflowResolver resolver, Document sourceDocument)
+            throws WorkflowException {
+        if (resolver.hasWorkflow(sourceDocument)) {
+            WorkflowInstance sourceInstance = resolver.getWorkflowInstance(sourceDocument);
+            sourceInstance.getHistory().delete();
+        }
+    }
+
+    /**
+     * Copies the workflow history of a document.
+     * @param resolver The workflow resolver.
+     * @param sourceDocument The source document.
+     * @param destinationDocument The destination document.
+     * @throws WorkflowException if an error occurs.
+     */
+    protected void copyWorkflow(WorkflowResolver resolver, Document sourceDocument,
+            Document destinationDocument) throws WorkflowException {
+        if (resolver.hasWorkflow(sourceDocument)) {
+            WorkflowInstance sourceInstance = resolver.getWorkflowInstance(sourceDocument);
+
+            WorkflowInstance destinationInstance = resolver
+                    .getWorkflowInstance(destinationDocument);
+            destinationInstance.getHistory().replaceWith(sourceInstance.getHistory());
+        }
+    }
+
+    /**
+     * Copies a document source.
+     * @param sourceDocument The source document.
+     * @param destinationDocument The destination document.
+     * @throws PublicationException when something went wrong.
+     */
+    protected abstract void copyDocumentSource(Document sourceDocument, Document destinationDocument)
+            throws PublicationException;
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#deleteDocument(org.apache.lenya.cms.publication.Document)
+     */
+    public void deleteDocument(Document document) throws PublicationException {
+        if (!document.exists()) {
+            throw new PublicationException("Document [" + document + "] does not exist!");
+        }
+        Publication publication = document.getPublication();
+        publication.getSiteManager(document.getIdentityMap()).delete(document);
+        deleteDocumentSource(document);
+
+        ResourcesManager resourcesManager = document.getResourcesManager();
+        resourcesManager.deleteResources();
+
+        WorkflowResolver workflowResolver = null;
+        try {
+            workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+            deleteWorkflow(workflowResolver, document);
+        } catch (Exception e) {
+            throw new PublicationException(e);
+        } finally {
+            if (workflowResolver != null) {
+                this.manager.release(workflowResolver);
+            }
+        }
+    }
+
+    /**
+     * Deletes the source of a document.
+     * @param document The document to delete.
+     * @throws PublicationException when something went wrong.
+     */
+    protected abstract void deleteDocumentSource(Document document) throws PublicationException;
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#moveDocument(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void moveDocument(Document sourceDocument, Document destinationDocument)
+            throws PublicationException {
+        copyDocument(sourceDocument, destinationDocument);
+        deleteDocument(sourceDocument);
+
+        ResourcesManager resourcesManager = sourceDocument.getResourcesManager();
+        WorkflowResolver workflowResolver = null;
+        try {
+            resourcesManager.copyResourcesTo(destinationDocument);
+            resourcesManager.deleteResources();
+
+            workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+            moveWorkflow(workflowResolver, sourceDocument, destinationDocument);
+        } catch (Exception e) {
+            throw new PublicationException(e);
+        } finally {
+            if (workflowResolver != null) {
+                this.manager.release(workflowResolver);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#copyDocumentToArea(org.apache.lenya.cms.publication.Document,
+     *      java.lang.String)
+     */
+    public void copyDocumentToArea(Document sourceDocument, String destinationArea)
+            throws PublicationException {
+        Publication publication = sourceDocument.getPublication();
+        Document destinationDocument = publication.getAreaVersion(sourceDocument, destinationArea);
+        copyDocument(sourceDocument, destinationDocument);
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#copyDocumentSetToArea(org.apache.lenya.cms.publication.util.DocumentSet,
+     *      java.lang.String)
+     */
+    public void copyDocumentSetToArea(DocumentSet documentSet, String destinationArea)
+            throws PublicationException {
+        Document[] documents = documentSet.getDocuments();
+        for (int i = 0; i < documents.length; i++) {
+            copyDocumentToArea(documents[i], destinationArea);
+        }
+    }
+
+    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;
+    }
+
+    private Context context;
+
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    /**
+     * @return The Avalon context.
+     */
+    protected Context getContext() {
+        return this.context;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#canCreate(org.apache.lenya.cms.publication.DocumentIdentityMap,
+     *      java.lang.String, org.apache.lenya.cms.publication.Document,
+     *      java.lang.String, java.lang.String)
+     */
+    public String[] canCreate(DocumentIdentityMap identityMap, String area, Document parent,
+            String nodeId, String language) throws DocumentBuildException, DocumentException {
+
+        List errorMessages = new ArrayList();
+
+        String newDocumentId;
+        if (parent != null) {
+            newDocumentId = parent.getId() + "/" + nodeId;
+        } else {
+            newDocumentId = "/" + nodeId;
+        }
+
+        if (nodeId.equals("")) {
+            errorMessages.add("The document ID is required.");
+        } else if (nodeId.indexOf("/") > -1) {
+            errorMessages.add("The document ID may not contain a slash ('/').");
+        } else if (identityMap.getFactory().isValidDocumentId(newDocumentId)) {
+            Document newDocument = identityMap.getFactory().get(area, newDocumentId, language);
+
+            if (newDocument.exists()) {
+                errorMessages.add("A document with this ID already exists.");
+            }
+        } else {
+            errorMessages.add("This document ID is not valid.");
+        }
+
+        return (String[]) errorMessages.toArray(new String[errorMessages.size()]);
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#getAvailableDocument(org.apache.lenya.cms.publication.Document)
+     */
+    public Document getAvailableDocument(Document document) throws DocumentBuildException {
+        UniqueDocumentId uniqueDocumentId = new UniqueDocumentId();
+        String availableDocumentId = uniqueDocumentId.computeUniqueDocumentId(document
+                .getPublication(), document.getArea(), document.getId());
+        DocumentFactory factory = document.getIdentityMap().getFactory();
+        Document availableDocument = factory.get(document.getArea(), availableDocumentId, document
+                .getLanguage());
+        return availableDocument;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#moveAll(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void moveAll(Document source, Document target) throws PublicationException {
+        DocumentIdentityMap identityMap = source.getIdentityMap();
+        SiteManager manager = identityMap.getPublication().getSiteManager(identityMap);
+        Document[] descendantsArray = manager.getRequiringResources(source);
+        OrderedDocumentSet descendants = new OrderedDocumentSet(descendantsArray);
+        descendants.add(source);
+
+        DocumentVisitor visitor = new MoveVisitor(this, source, target);
+        descendants.visitAscending(visitor);
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#moveAllLanguageVersions(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void moveAllLanguageVersions(Document source, Document target)
+            throws PublicationException {
+        DocumentIdentityMap identityMap = source.getIdentityMap();
+        String[] languages = source.getLanguages();
+        for (int i = 0; i < languages.length; i++) {
+
+            Document sourceVersion = identityMap.getFactory().getLanguageVersion(source,
+                    languages[i]);
+            Document targetVersion = identityMap.getFactory().get(target.getArea(),
+                    target.getId(),
+                    languages[i]);
+            moveDocument(sourceVersion, targetVersion);
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#copyAll(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void copyAll(Document source, Document target) throws PublicationException {
+        DocumentIdentityMap identityMap = source.getIdentityMap();
+        SiteManager manager = identityMap.getPublication().getSiteManager(identityMap);
+        Document[] descendantsArray = manager.getRequiringResources(source);
+        OrderedDocumentSet descendants = new OrderedDocumentSet(descendantsArray);
+        descendants.add(source);
+
+        DocumentVisitor visitor = new CopyVisitor(this, source, target);
+        descendants.visitAscending(visitor);
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#copyAllLanguageVersions(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void copyAllLanguageVersions(Document source, Document target)
+            throws PublicationException {
+        DocumentIdentityMap identityMap = source.getIdentityMap();
+        String[] languages = source.getLanguages();
+        for (int i = 0; i < languages.length; i++) {
+
+            Document sourceVersion = identityMap.getFactory().getLanguageVersion(source,
+                    languages[i]);
+            Document targetVersion = identityMap.getFactory().get(target.getArea(),
+                    target.getId(),
+                    languages[i]);
+            copyDocument(sourceVersion, targetVersion);
+        }
+    }
+
+    /**
+     * Abstract base class for document visitors which operate on a source and
+     * target document.
+     */
+    public abstract class Visitor implements DocumentVisitor {
+
+        private Document rootSource;
+        private Document rootTarget;
+        private DocumentManager manager;
+
+        /**
+         * Ctor.
+         * @param manager The document manager.
+         * @param source The root source.
+         * @param target The root target.
+         */
+        public Visitor(DocumentManager manager, Document source, Document target) {
+            this.manager = manager;
+            this.rootSource = source;
+            this.rootTarget = target;
+        }
+
+        protected Document getRootSource() {
+            return rootSource;
+        }
+
+        protected Document getRootTarget() {
+            return rootTarget;
+        }
+
+        protected DocumentManager getDocumentManager() {
+            return this.manager;
+        }
+
+        /**
+         * Returns the target corresponding to a source relatively to the root
+         * target document.
+         * @param source The source.
+         * @return A document.
+         * @throws DocumentBuildException if the target could not be built.
+         */
+        protected Document getTarget(Document source) throws DocumentBuildException {
+            String rootSourceId = getRootSource().getId();
+            String rootTargetId = getRootTarget().getId();
+            String childId = source.getId().substring(rootSourceId.length());
+            String targetId = rootTargetId + childId;
+            DocumentFactory factory = getRootTarget().getIdentityMap().getFactory();
+            return factory.get(getRootTarget().getArea(), targetId, source.getLanguage());
+        }
+    }
+
+    /**
+     * DocumentVisitor to move documents.
+     */
+    public class MoveVisitor extends Visitor {
+
+        /**
+         * Ctor.
+         * @param manager The document manager.
+         * @param source The root source.
+         * @param target The root target.
+         */
+        public MoveVisitor(DocumentManager manager, Document source, Document target) {
+            super(manager, source, target);
+        }
+
+        /**
+         * @see org.apache.lenya.cms.publication.util.DocumentVisitor#visitDocument(org.apache.lenya.cms.publication.Document)
+         */
+        public void visitDocument(Document source) throws PublicationException {
+            Document target = getTarget(source);
+            getDocumentManager().moveAllLanguageVersions(source, target);
+        }
+
+    }
+
+    /**
+     * DocumentVisitor to copy documents.
+     */
+    public class CopyVisitor extends Visitor {
+
+        /**
+         * Ctor.
+         * @param manager The document manager.
+         * @param source The root source.
+         * @param target The root target.
+         */
+        public CopyVisitor(DocumentManager manager, Document source, Document target) {
+            super(manager, source, target);
+        }
+
+        /**
+         * @see org.apache.lenya.cms.publication.util.DocumentVisitor#visitDocument(org.apache.lenya.cms.publication.Document)
+         */
+        public void visitDocument(Document source) throws PublicationException {
+            Document target = getTarget(source);
+            getDocumentManager().copyAllLanguageVersions(source, target);
+        }
+
+    }
+
+}
\ No newline at end of file

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?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Fri Feb 25 02:52:51 2005
@@ -219,7 +219,7 @@
      * @param _area A string.
      */
     protected void setArea(String _area) {
-        if (!AbstractPublication.isValidArea(_area)) {
+        if (!PublicationImpl.isValidArea(_area)) {
             throw new IllegalArgumentException("The area [" + _area + "] is not valid!");
         }
         this.area = _area;

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java Fri Feb 25 02:52:51 2005
@@ -152,7 +152,7 @@
             if (slashIndex > -1) {
                 String area = publicationURI.substring(0, slashIndex);
                 String documentUri = publicationURI.substring(slashIndex);
-                if (AbstractPublication.isValidArea(area) && !area.equals(Publication.ADMIN_AREA)
+                if (PublicationImpl.isValidArea(area) && !area.equals(Publication.ADMIN_AREA)
                         && documentUri.startsWith("/") && documentUri.length() > 1) {
                     isDocument = true;
                 }

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java?view=auto&rev=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java Fri Feb 25 02:52:51 2005
@@ -0,0 +1,149 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.publication;
+
+import org.apache.lenya.cms.publication.util.DocumentSet;
+
+/**
+ * Helper to manage documents. It takes care of workflow, attachments etc.
+ * 
+ * @version $Id:$
+ */
+public interface DocumentManager {
+    
+    /**
+     * The Avalon component role.
+     */
+    String ROLE = DocumentManager.class.getName();
+
+    /**
+     * Copies a document from one location to another location.
+     * @param sourceDocument The document to copy.
+     * @param destinationDocument The destination document.
+     * @throws PublicationException if a document which destinationDocument
+     *             depends on does not exist.
+     */
+    void copyDocument(Document sourceDocument, Document destinationDocument)
+            throws PublicationException;
+
+    /**
+     * Copies a document to another area.
+     * @param sourceDocument The document to copy.
+     * @param destinationArea The destination area.
+     * @throws PublicationException if a document which the destination document
+     *             depends on does not exist.
+     */
+    void copyDocumentToArea(Document sourceDocument, String destinationArea)
+            throws PublicationException;
+
+    /**
+     * Copies a document set to another area.
+     * @param documentSet The document set to copy.
+     * @param destinationArea The destination area.
+     * @throws PublicationException if a document which one of the destination
+     *             documents depends on does not exist.
+     */
+    void copyDocumentSetToArea(DocumentSet documentSet, String destinationArea)
+            throws PublicationException;
+
+    /**
+     * Adds a document to the publication.
+     * @param document The document.
+     * @throws PublicationException if the document is already contained.
+     */
+    void addDocument(Document document) throws PublicationException;
+
+    /**
+     * Deletes a document.
+     * @param document The document to delete.
+     * @throws PublicationException when something went wrong.
+     */
+    void deleteDocument(Document document) throws PublicationException;
+
+    /**
+     * Moves a document from one location to another.
+     * @param sourceDocument The source document.
+     * @param destinationDocument The destination document.
+     * @throws PublicationException if a document which the destination document
+     *             depends on does not exist.
+     */
+    void moveDocument(Document sourceDocument, Document destinationDocument)
+            throws PublicationException;
+
+    /**
+     * Checks if a document can be created. This is the case if the document ID
+     * is valid and the document does not yet exist.
+     * @param identityMap The identity map to use.
+     * @param area The area.
+     * @param parent The parent of the document or <code>null</code> if the
+     *            document has no parent.
+     * @param nodeId The node ID.
+     * @param language The language.
+     * @return An array of error messages. The array is empty if the document
+     *         can be created.
+     * @throws DocumentBuildException if an error occurs.
+     * @throws DocumentException if an error occurs.
+     */
+    String[] canCreate(DocumentIdentityMap identityMap, String area, Document parent,
+            String nodeId, String language) throws DocumentBuildException, DocumentException;
+
+    /**
+     * Checks if the document does already exist. If it does, returns a
+     * non-existing document with a similar document ID. If it does not, the
+     * original document is returned.
+     * @param document The document.
+     * @return A document.
+     * @throws DocumentBuildException if the new document could not be built.
+     */
+    public Document getAvailableDocument(Document document) throws DocumentBuildException;
+
+    /**
+     * Moves a document to another location, incl. all requiring documents. If a
+     * sitetree is used, this means that the whole subtree is moved.
+     * @param source The source document.
+     * @param target The target document.
+     * @throws PublicationException if an error occurs.
+     */
+    public void moveAll(Document source, Document target) throws PublicationException;
+
+    /**
+     * Moves all language versions of a document to another location.
+     * @param source The source.
+     * @param target The target.
+     * @throws PublicationException if the documents could not be moved.
+     */
+    public void moveAllLanguageVersions(Document source, Document target)
+            throws PublicationException;
+
+    /**
+     * Copies a document to another location, incl. all requiring documents. If
+     * a sitetree is used, this means that the whole subtree is copied.
+     * @param source The source document.
+     * @param target The target document.
+     * @throws PublicationException if an error occurs.
+     */
+    public void copyAll(Document source, Document target) throws PublicationException;
+
+    /**
+     * Copies all language versions of a document to another location.
+     * @param source The source.
+     * @param target The target.
+     * @throws PublicationException if the documents could not be copied.
+     */
+    public void copyAllLanguageVersions(Document source, Document target)
+            throws PublicationException;
+}
\ No newline at end of file

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?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Fri Feb 25 02:52:51 2005
@@ -21,7 +21,6 @@
 
 import java.io.File;
 
-import org.apache.lenya.cms.publication.util.DocumentSet;
 import org.apache.lenya.cms.site.SiteException;
 import org.apache.lenya.cms.site.SiteManager;
 
@@ -211,59 +210,6 @@
      */
     DocumentBuilder getDocumentBuilder();
     
-    /**
-     * Copies a document from one location to another location.
-     * @param sourceDocument The document to copy.
-     * @param destinationDocument The destination document.
-     * @throws PublicationException if a document which destinationDocument depends on
-     * does not exist.
-     */
-    void copyDocument(Document sourceDocument, Document destinationDocument)
-        throws PublicationException;
-
-    /**
-     * Copies a document to another area.
-     * @param sourceDocument The document to copy.
-     * @param destinationArea The destination area.
-     * @throws PublicationException if a document which the
-     * destination document depends on does not exist.
-     */
-    void copyDocumentToArea(Document sourceDocument, String destinationArea)
-        throws PublicationException;
-
-    /**
-     * Copies a document set to another area.
-     * @param documentSet The document set to copy.
-     * @param destinationArea The destination area.
-     * @throws PublicationException if a document which one of the
-     * destination documents depends on does not exist.
-     */
-    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.
-     * @param document The document to delete.
-     * @throws PublicationException when something went wrong.
-     */
-    void deleteDocument(Document document) throws PublicationException;
-    
-    /**
-     * Moves a document from one location to another.
-     * @param sourceDocument The source document.
-     * @param destinationDocument The destination document.
-     * @throws PublicationException if a document which the
-     * destination document depends on does not exist.
-     */
-    void moveDocument(Document sourceDocument, Document destinationDocument) throws PublicationException;
-
     /**
      * Creates a version of the document object in another area.
      * @param document The document to clone.

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java Fri Feb 25 02:52:51 2005
@@ -33,7 +33,6 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.source.SourceUtil;
-import org.apache.lenya.cms.publication.file.FilePublication;
 import org.apache.lenya.util.ServletHelper;
 
 /**
@@ -102,7 +101,7 @@
             publication = (Publication) keyToPublication.get(key);
         } else {
             if (PublicationFactory.existsPublication(id, servletContextPath)) {
-                publication = new FilePublication(id, servletContextPath);
+                publication = new PublicationImpl(id, servletContextPath);
                 ContainerUtil.enableLogging(publication, getLogger());
                 keyToPublication.put(key, publication);
             }

Added: 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?view=auto&rev=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java Fri Feb 25 02:52:51 2005
@@ -0,0 +1,368 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+/* $Id: AbstractPublication.java 155024 2005-02-23 15:27:31Z andreas $  */
+
+package org.apache.lenya.cms.publication;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.tree.TreeSiteManager;
+import org.xml.sax.SAXException;
+
+/**
+ * A publication.
+ */
+public class PublicationImpl extends AbstractLogEnabled implements Publication {
+
+    private static final String[] areas = { AUTHORING_AREA, STAGING_AREA, LIVE_AREA, ADMIN_AREA,
+            ARCHIVE_AREA, TRASH_AREA, INFO_AREA_PREFIX + AUTHORING_AREA,
+            INFO_AREA_PREFIX + STAGING_AREA, INFO_AREA_PREFIX + LIVE_AREA,
+            INFO_AREA_PREFIX + ARCHIVE_AREA, INFO_AREA_PREFIX + TRASH_AREA };
+
+    private String id;
+    private File servletContext;
+    private DocumentIdToPathMapper mapper = null;
+    private ArrayList languages = new ArrayList();
+    private String defaultLanguage = null;
+    private String breadcrumbprefix = null;
+
+    private static final String ELEMENT_PROXY = "proxy";
+    private static final String ATTRIBUTE_AREA = "area";
+    private static final String ATTRIBUTE_URL = "url";
+    private static final String ATTRIBUTE_SSL = "ssl";
+
+    /**
+     * Creates a new instance of Publication
+     * @param _id the publication id
+     * @param servletContextPath the servlet context of this publication
+     * @throws PublicationException if there was a problem reading the config
+     *             file
+     */
+    protected PublicationImpl(String _id, String servletContextPath)
+            throws PublicationException {
+        assert _id != null;
+        this.id = _id;
+
+        assert servletContextPath != null;
+
+        File _servletContext = new File(servletContextPath);
+        assert _servletContext.exists();
+        this.servletContext = _servletContext;
+
+        File configFile = new File(getDirectory(), CONFIGURATION_FILE);
+        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+
+        Configuration config;
+
+        String pathMapperClassName = null;
+        String documentBuilderClassName = null;
+
+        try {
+            config = builder.buildFromFile(configFile);
+
+            try {
+                pathMapperClassName = config.getChild(ELEMENT_PATH_MAPPER).getValue();
+                Class pathMapperClass = Class.forName(pathMapperClassName);
+                this.mapper = (DocumentIdToPathMapper) pathMapperClass.newInstance();
+            } catch (final ClassNotFoundException e) {
+                throw new PublicationException("Cannot instantiate documentToPathMapper: ["
+                        + pathMapperClassName + "]", e);
+            }
+
+            try {
+                Configuration documentBuilderConfiguration = config
+                        .getChild(ELEMENT_DOCUMENT_BUILDER, false);
+                if (documentBuilderConfiguration != null) {
+                    documentBuilderClassName = documentBuilderConfiguration.getValue();
+                    Class documentBuilderClass = Class.forName(documentBuilderClassName);
+                    this.documentBuilder = (DocumentBuilder) documentBuilderClass.newInstance();
+                }
+            } catch (final ClassNotFoundException e) {
+                throw new PublicationException("Cannot instantiate document builder: ["
+                        + pathMapperClassName + "]", e);
+            }
+
+            Configuration[] _languages = config.getChild(LANGUAGES).getChildren();
+            for (int i = 0; i < _languages.length; i++) {
+                Configuration languageConfig = _languages[i];
+                String language = languageConfig.getValue();
+                this.languages.add(language);
+                if (languageConfig.getAttribute(DEFAULT_LANGUAGE_ATTR, null) != null) {
+                    this.defaultLanguage = language;
+                }
+            }
+
+            String _siteManagerClass = TreeSiteManager.class.getName();
+            Configuration siteStructureConfiguration = config.getChild(ELEMENT_SITE_STRUCTURE,
+                    false);
+            if (siteStructureConfiguration != null) {
+                _siteManagerClass = siteStructureConfiguration.getAttribute(ATTRIBUTE_TYPE);
+            }
+            Class klass = Class.forName(_siteManagerClass);
+            this.siteManagerClass = klass;
+
+            Configuration[] proxyConfigs = config.getChildren(ELEMENT_PROXY);
+            for (int i = 0; i < proxyConfigs.length; i++) {
+                String url = proxyConfigs[i].getAttribute(ATTRIBUTE_URL);
+                String ssl = proxyConfigs[i].getAttribute(ATTRIBUTE_SSL);
+                String area = proxyConfigs[i].getAttribute(ATTRIBUTE_AREA);
+
+                Proxy proxy = new Proxy();
+                proxy.setUrl(url);
+
+                Object key = getProxyKey(area, Boolean.valueOf(ssl).booleanValue());
+                this.areaSsl2proxy.put(key, proxy);
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Adding proxy: [" + proxy + "] for area=[" + area + "] SSL=["
+                            + ssl + "]");
+                }
+            }
+        } catch (final ConfigurationException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        } catch (final SAXException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        } catch (final IOException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        } catch (final InstantiationException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        } catch (final IllegalAccessException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        } catch (final PublicationException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        } catch (final ClassNotFoundException e) {
+            throw new PublicationException("Problem with config file: "
+                    + configFile.getAbsolutePath(), e);
+        }
+
+        this.breadcrumbprefix = config.getChild(BREADCRUMB_PREFIX).getValue("");
+
+    }
+
+    /**
+     * Returns the publication ID.
+     * @return A string value.
+     */
+    public String getId() {
+        return this.id;
+    }
+
+    /**
+     * Returns the servlet context this publication belongs to (usually, the
+     * <code>webapps/lenya</code> directory).
+     * @return A <code>File</code> object.
+     */
+    public File getServletContext() {
+        return this.servletContext;
+    }
+
+    /**
+     * Returns the publication directory.
+     * @return A <code>File</code> object.
+     */
+    public File getDirectory() {
+        return new File(getServletContext(), PUBLICATION_PREFIX + File.separator + getId());
+    }
+
+    /**
+     * Return the directory of a specific area.
+     * @param area a <code>File</code> representing the root of the area
+     *            content directory.
+     * @return the directory of the given content area.
+     */
+    public File getContentDirectory(String area) {
+        return new File(getDirectory(), CONTENT_PATH + File.separator + area);
+    }
+
+    /**
+     * Set the path mapper
+     * @param _mapper The path mapper
+     */
+    public void setPathMapper(DefaultDocumentIdToPathMapper _mapper) {
+        assert _mapper != null;
+        this.mapper = _mapper;
+    }
+
+    /**
+     * Returns the path mapper.
+     * @return a <code>DocumentIdToPathMapper</code>
+     */
+    public DocumentIdToPathMapper getPathMapper() {
+        return this.mapper;
+    }
+
+    /**
+     * Returns if a given string is a valid area name.
+     * @param area The area string to test.
+     * @return A boolean value.
+     */
+    public static boolean isValidArea(String area) {
+        return area != null && Arrays.asList(areas).contains(area);
+    }
+
+    /**
+     * Get the default language
+     * @return the default language
+     */
+    public String getDefaultLanguage() {
+        return this.defaultLanguage;
+    }
+
+    /**
+     * Set the default language
+     * @param language the default language
+     */
+    public void setDefaultLanguage(String language) {
+        this.defaultLanguage = language;
+    }
+
+    /**
+     * Get all available languages for this publication
+     * @return an <code>Array</code> of languages
+     */
+    public String[] getLanguages() {
+        return (String[]) this.languages.toArray(new String[this.languages.size()]);
+    }
+
+    /**
+     * Get the breadcrumb prefix. It can be used as a prefix if a publication is
+     * part of a larger site
+     * @return the breadcrumb prefix
+     */
+    public String getBreadcrumbPrefix() {
+        return this.breadcrumbprefix;
+    }
+
+    private DocumentBuilder documentBuilder;
+
+    /**
+     * Returns the document builder of this instance.
+     * @return A document builder.
+     */
+    public DocumentBuilder getDocumentBuilder() {
+
+        if (this.documentBuilder == null) {
+            throw new IllegalStateException(
+                    "The document builder was not defined in publication.xconf!");
+        }
+        ContainerUtil.enableLogging(this.documentBuilder, getLogger());
+        return this.documentBuilder;
+    }
+
+    /**
+     * Creates a version of the document object in another area.
+     * @param document The document to clone.
+     * @param area The destination area.
+     * @return A document.
+     * @throws PublicationException when an error occurs.
+     */
+    public Document getAreaVersion(Document document, String area) throws PublicationException {
+        DocumentBuilder builder = getDocumentBuilder();
+        String url = builder
+                .buildCanonicalUrl(this, area, document.getId(), document.getLanguage());
+        Document destinationDocument = builder.buildDocument(document.getIdentityMap(), url);
+        return destinationDocument;
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object object) {
+        boolean equals = false;
+
+        if (getClass().isInstance(object)) {
+            Publication publication = (Publication) object;
+            equals = getId().equals(publication.getId())
+                    && getServletContext().equals(publication.getServletContext());
+        }
+
+        return equals;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        String key = getServletContext() + ":" + getId();
+        return key.hashCode();
+    }
+
+    private Map areaSsl2proxy = new HashMap();
+
+    /**
+     * Generates a hash key for a area-SSL combination.
+     * @param area The area.
+     * @param isSslProtected If the proxy is assigned for SSL-protected pages.
+     * @return An object.
+     */
+    protected Object getProxyKey(String area, boolean isSslProtected) {
+        return area + ":" + isSslProtected;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.Publication#getProxy(org.apache.lenya.cms.publication.Document,
+     *      boolean)
+     */
+    public Proxy getProxy(Document document, boolean isSslProtected) {
+
+        Object key = getProxyKey(document.getArea(), isSslProtected);
+        Proxy proxy = (Proxy) this.areaSsl2proxy.get(key);
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger()
+                    .debug("Resolving proxy for [" + document + "] SSL=[" + isSslProtected + "]");
+            getLogger().debug("Resolved proxy: [" + proxy + "]");
+        }
+
+        return proxy;
+    }
+
+    private Class siteManagerClass;
+
+    /**
+     * @see org.apache.lenya.cms.publication.Publication#getSiteManager(org.apache.lenya.cms.publication.DocumentIdentityMap)
+     */
+    public SiteManager getSiteManager(DocumentIdentityMap map) throws SiteException {
+        SiteManager manager;
+        try {
+            manager = (SiteManager) this.siteManagerClass.newInstance();
+            ContainerUtil.enableLogging(manager, getLogger());
+        } catch (Exception e) {
+            throw new SiteException(e);
+        }
+        manager.setIdentityMap(map);
+        return manager;
+    }
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/file/FileDocumentManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/file/FileDocumentManager.java?view=auto&rev=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/file/FileDocumentManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/file/FileDocumentManager.java Fri Feb 25 02:52:51 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.publication.file;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.avalon.excalibur.io.FileUtil;
+import org.apache.lenya.cms.publication.AbstractDocumentManager;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.PublicationException;
+
+/**
+ * Filesystem-based document manager.
+ *
+ * @version $Id:$ 
+ */
+public class FileDocumentManager extends AbstractDocumentManager {
+
+    /**
+     * @see org.apache.lenya.cms.publication.AbstractDocumentManager#copyDocumentSource(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document)
+     */
+    public void copyDocumentSource(Document sourceDocument, Document destinationDocument)
+            throws PublicationException {
+        File file = sourceDocument.getFile();
+        File destinationDirectory = destinationDocument.getFile().getParentFile();
+        try {
+            if (!destinationDirectory.isDirectory()) {
+                destinationDirectory.mkdirs();
+            }
+            FileUtil.copyFileToDirectory(file, destinationDirectory);
+            destinationDocument.getDublinCore().replaceBy(sourceDocument.getDublinCore());
+        } catch (IOException e) {
+            throw new PublicationException(e);
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.AbstractDocumentManager#deleteDocumentSource(org.apache.lenya.cms.publication.Document)
+     */
+    protected void deleteDocumentSource(Document document) throws PublicationException {
+        File file = document.getFile();
+        boolean deleted = file.delete();
+        if (!deleted) {
+            throw new PublicationException("Source file [" + file + "] of document [" + document
+                    + "] could not be deleted!");
+        }
+    }
+
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/task/CopyDocumentToArea.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/task/CopyDocumentToArea.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/task/CopyDocumentToArea.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/task/CopyDocumentToArea.java Fri Feb 25 02:52:51 2005
@@ -41,7 +41,7 @@
         String area;
         try {
             area = getParameters().getParameter(PARAMETER_DESTINATION_AREA);
-            getPublication().copyDocumentToArea(document, area);
+//            getPublication().copyDocumentToArea(document, area);
         } catch (Exception e) {
             throw new ExecutionException(e);
         }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java Fri Feb 25 02:52:51 2005
@@ -51,13 +51,15 @@
     protected void initParameters() {
         super.initParameters();
         Document document = getSourceDocument();
-        setParameter(DOCUMENT_ID, document.getId());
-        try {
-            SiteManager _manager = document.getPublication().getSiteManager(document
-                    .getIdentityMap());
-            setParameter(LABEL, _manager.getLabel(document));
-        } catch (SiteException e) {
-            throw new RuntimeException(e);
+        if (document != null) {
+            setParameter(DOCUMENT_ID, document.getId());
+            try {
+                SiteManager _manager = document.getPublication().getSiteManager(document
+                        .getIdentityMap());
+                setParameter(LABEL, _manager.getLabel(document));
+            } catch (SiteException e) {
+                throw new RuntimeException(e);
+            }
         }
     }
 

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java Fri Feb 25 02:52:51 2005
@@ -40,7 +40,9 @@
     protected void initParameters() {
         super.initParameters();
         Document document = getSourceDocument();
-        setParameter(NODE_ID, document.getName());
+        if (document != null) {
+            setParameter(NODE_ID, document.getName());
+        }
     }
 
     /**
@@ -74,12 +76,13 @@
 
         String nodeId = getParameterAsString(NODE_ID);
         Document parent = identityMap.getFactory().getParent(getSourceDocument());
-        SiteUtility util = new SiteUtility();
-        addErrorMessages(util.canCreate(identityMap,
+        String[] messages = getDocumentManager().canCreate(identityMap,
                 getSourceDocument().getArea(),
                 parent,
                 nodeId,
-                getSourceDocument().getLanguage()));
+                getSourceDocument().getLanguage());
+
+        addErrorMessages(messages);
     }
 
     /**
@@ -117,7 +120,6 @@
         Document newDocument = null;
 
         DocumentIdentityMap identityMap = document.getIdentityMap();
-        Publication publication = identityMap.getPublication();
         String newDocumentId = getNewDocumentId();
 
         String[] availableLanguages = document.getLanguages();
@@ -131,7 +133,7 @@
                     newDocumentId,
                     availableLanguages[i]);
 
-            publication.moveDocument(languageVersion, newLanguageVersion);
+            getDocumentManager().moveDocument(languageVersion, newLanguageVersion);
 
             if (availableLanguages[i].equals(document.getLanguage())) {
                 newDocument = newLanguageVersion;

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java Fri Feb 25 02:52:51 2005
@@ -33,15 +33,14 @@
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.URLInformation;
 import org.apache.lenya.cms.site.SiteManager;
-import org.apache.lenya.cms.usecase.WorkflowUsecase;
-import org.apache.lenya.workflow.WorkflowInstance;
+import org.apache.lenya.cms.usecase.AbstractUsecase;
 
 /**
  * Abstract superclass for usecases to create a resource.
  * 
  * @version $Id: Create.java 123982 2005-01-03 15:01:19Z andreas $
  */
-public abstract class Create extends WorkflowUsecase {
+public abstract class Create extends AbstractUsecase {
 
     protected static final String LANGUAGE = "language";
     protected static final String LANGUAGES = "languages";
@@ -60,7 +59,7 @@
     protected void doCheckPreconditions() throws Exception {
         super.doCheckPreconditions();
         
-        if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) {
+        if (!getArea().equals(Publication.AUTHORING_AREA)) {
             addErrorMessage("This usecase can only be invoked in the authoring area!");
         }
     }
@@ -84,14 +83,11 @@
 
         Document document = createDocument();
         Publication publication = document.getPublication();
+        getDocumentManager().addDocument(document);
 
         SiteManager _manager = publication.getSiteManager(document.getIdentityMap());
-        _manager.add(document);
         _manager.setLabel(document, getParameterAsString(DublinCore.ELEMENT_TITLE));
 
-        WorkflowInstance instance = getWorkflowInstance(document);
-        instance.getHistory().initialize(getSituation());
-
         setMetaData(document);
         setTargetURL(document.getCanonicalWebappURL());
     }
@@ -141,7 +137,12 @@
         Session session = request.getSession(false);
         Identity identity = (Identity) session.getAttribute(Identity.class.getName());
         User user = identity.getUser();
-        setParameter(DublinCore.ELEMENT_CREATOR, user.getId());
+        if (user != null) {
+            setParameter(DublinCore.ELEMENT_CREATOR, user.getId());
+        }
+        else {
+            setParameter(DublinCore.ELEMENT_CREATOR, "");
+        }
 
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
         setParameter(DublinCore.ELEMENT_DATE, format.format(new GregorianCalendar().getTime()));

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java Fri Feb 25 02:52:51 2005
@@ -62,12 +62,12 @@
         String nodeId = getParameterAsString(DOCUMENT_ID);
         Document parent = getSourceDocument();
         String language = getParameterAsString(LANGUAGE);
-        SiteUtility util = new SiteUtility();
-        addErrorMessages(util.canCreate(getUnitOfWork().getIdentityMap(),
+        String[] messages = getDocumentManager().canCreate(getUnitOfWork().getIdentityMap(),
                 getArea(),
                 parent,
                 nodeId,
-                language));
+                language);
+        addErrorMessages(messages);
     }
 
     /**

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java Fri Feb 25 02:52:51 2005
@@ -89,21 +89,23 @@
         super.initParameters();
 
         Document source = getSourceDocument();
-        DocumentTypeResolver resolver = null;
+        if (source != null) {
+            DocumentTypeResolver resolver = null;
 
-        try {
-            resolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
-            DocumentType type = resolver.resolve(source);
-            this.documentTypeName = type.getName();
+            try {
+                resolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+                DocumentType type = resolver.resolve(source);
+                this.documentTypeName = type.getName();
 
-            List nonExistingLanguages = getNonExistingLanguages();
-            setParameter(LANGUAGES, nonExistingLanguages.toArray(new String[nonExistingLanguages
-                    .size()]));
+                List nonExistingLanguages = getNonExistingLanguages();
+                setParameter(LANGUAGES, nonExistingLanguages.toArray(new String[nonExistingLanguages
+                        .size()]));
 
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        } finally {
-            this.manager.release(resolver);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            } finally {
+                this.manager.release(resolver);
+            }
         }
     }
 

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java Fri Feb 25 02:52:51 2005
@@ -69,7 +69,9 @@
      */
     protected void initParameters() {
         super.initParameters();
-        setParameter("documentId", getSourceDocument().getId());
-        setParameter("language", getSourceDocument().getLanguage());
+        if (getSourceDocument() != null) {
+            setParameter("documentId", getSourceDocument().getId());
+            setParameter("language", getSourceDocument().getLanguage());
+        }
     }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java Fri Feb 25 02:52:51 2005
@@ -78,14 +78,13 @@
         String potentialDocumentId = getSourceDocument().getId() + "/" + nodeId;
         
         Document potentialDocument = identityMap.getFactory().get(targetArea, potentialDocumentId, language);
-        SiteUtility util = new SiteUtility();
-        Document availableDocument = util.getAvailableDocument(potentialDocument);
+        Document availableDocument = getDocumentManager().getAvailableDocument(potentialDocument);
         
         if (clipboard.getMethod() == Clipboard.METHOD_COPY) {
-            util.copyAll(clippedDocument, availableDocument);
+            getDocumentManager().copyAll(clippedDocument, availableDocument);
         }
         else if (clipboard.getMethod() == Clipboard.METHOD_CUT) {
-            util.moveAll(clippedDocument, availableDocument);
+            getDocumentManager().moveAll(clippedDocument, availableDocument);
         }
         else {
             throw new RuntimeException("This clipboard method is not supported!");

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?view=diff&r1=155314&r2=155315
==============================================================================
--- 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 Fri Feb 25 02:52:51 2005
@@ -44,8 +44,12 @@
      */
     protected void doCheckPreconditions() throws Exception {
         super.doCheckPreconditions();
-        String eventName = getParameterAsString(EVENT);
         
+        if (!getErrorMessages().isEmpty()) {
+            return;
+        }
+        
+        String eventName = getParameterAsString(EVENT);
         WorkflowInstance instance = getWorkflowInstance(getSourceDocument());
         if (!instance.canInvoke(getSituation(), eventName)) {
             addErrorMessage("The event [" + eventName + "] is not executable on document ["

Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Fri Feb 25 02:52:51 2005
@@ -110,4 +110,8 @@
   	    shorthand="link-rewriter"
   	    default-class="org.apache.lenya.cms.site.usecases.LinkRewriterImpl"/>
         
+  <role name="org.apache.lenya.cms.publication.DocumentManager"
+  	    shorthand="link-rewriter"
+  	    default-class="org.apache.lenya.cms.publication.file.FileDocumentManager"/>
+        
 </role-list>

Modified: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java?view=diff&r1=155314&r2=155315
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java Fri Feb 25 02:52:51 2005
@@ -84,7 +84,7 @@
         try {
             Document liveDocument = publication.getAreaVersion(authoringDocument,
                     Publication.LIVE_AREA);
-            publication.deleteDocument(liveDocument);
+            getDocumentManager().deleteDocument(liveDocument);
 
             triggerWorkflow(getEvent(), authoringDocument);
             success = true;

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=155314&r2=155315
==============================================================================
--- 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 Fri Feb 25 02:52:51 2005
@@ -107,11 +107,10 @@
      */
     protected void publish(Document authoringDocument) {
 
-        Publication publication = authoringDocument.getPublication();
         boolean success = false;
 
         try {
-            publication.copyDocumentToArea(authoringDocument, Publication.LIVE_AREA);
+            getDocumentManager().copyDocumentToArea(authoringDocument, Publication.LIVE_AREA);
             triggerWorkflow(getEvent(), authoringDocument);
             success = true;
         } catch (Exception e) {



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