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/05/18 17:20:50 UTC

svn commit: r170762 - in /lenya/trunk/src: java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/site/usecases/ webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/

Author: andreas
Date: Wed May 18 08:20:48 2005
New Revision: 170762

URL: http://svn.apache.org/viewcvs?rev=170762&view=rev
Log:
DocumentManager.add(): replaced initialContentsUri with another method where you can pass a source document

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.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/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java

Modified: 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?rev=170762&r1=170761&r2=170762&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java Wed May 18 08:20:48 2005
@@ -65,10 +65,6 @@
      * @param document The document to add.
      * @param documentType the document type (aka resource type) of the new document
      * @param navigationTitle navigation title
-     * @param initialContentsURI an URI from which initial contents for the new document can be
-     *            read. Optional parameter; may be set to <code>null</code>, in which case the
-     *            default initial sample as configured in <code>doctypes.xconf</code> will be
-     *            used.
      * @param parameters any parameters the caller needs to pass to the creator
      * 
      * @throws DocumentBuildException if the document can not be created
@@ -77,7 +73,23 @@
     void add(Document document,
             DocumentType documentType,
             String navigationTitle,
-            String initialContentsURI,
+            Map parameters) throws DocumentBuildException, PublicationException;
+
+    /**
+     * Creates a new document in the same publication the <code>parentDocument</code> belongs to
+     * with the given parameters:
+     * 
+     * @param document The document to add.
+     * @param sourceDocument The document to initialize the contents and meta data from.
+     * @param navigationTitle navigation title
+     * @param parameters any parameters the caller needs to pass to the creator
+     * 
+     * @throws DocumentBuildException if the document can not be created
+     * @throws PublicationException if the document is already contained.
+     */
+    void add(Document document,
+            Document sourceDocument,
+            String navigationTitle,
             Map parameters) throws DocumentBuildException, PublicationException;
 
     /**

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?rev=170762&r1=170761&r2=170762&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Wed May 18 08:20:48 2005
@@ -33,6 +33,7 @@
 import org.apache.lenya.cms.authoring.NodeCreatorInterface;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
 import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.metadata.MetaDataManager;
 import org.apache.lenya.cms.publication.util.DocumentSet;
 import org.apache.lenya.cms.publication.util.DocumentVisitor;
 import org.apache.lenya.cms.site.SiteManager;
@@ -54,37 +55,62 @@
      * implementation to be used is specified in doctypes.xconf (and thus depends on the publication
      * and the resource type to be used)
      * 
-     * @see DocumentManager#add(Document, DocumentType, String, String, Map)
+     * @see DocumentManager#add(Document, DocumentType, String, Map)
      * @see org.apache.lenya.cms.authoring.NodeCreatorInterface
      * @see org.apache.lenya.cms.publication.DocumentBuilder
      */
     public void add(Document document,
             DocumentType documentType,
             String navigationTitle,
-            String initialContentsURI,
             Map parameters) throws DocumentBuildException, PublicationException {
 
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Create");
-            getLogger().debug("    document:     [" + document + "]");
-            getLogger().debug("    nav title:    [" + navigationTitle + "]");
-            getLogger().debug("    contents URI: [" + initialContentsURI + "]");
-        }
-
-        /*
-         * Get an instance of Document. This will (ultimately) be created by the implementation for
-         * the DocumentBuilder role.
-         */
+        String contentsURI = documentType.getSampleContentLocation();
+        add(document, documentType, navigationTitle, parameters, contentsURI);
+    }
 
-        // Call the creator for the document type to physically create a document of this type
-        try {
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentManager#add(org.apache.lenya.cms.publication.Document,
+     *      org.apache.lenya.cms.publication.Document,
+     *      java.lang.String, java.util.Map)
+     */
+    public void add(Document document,
+            Document sourceDocument,
+            String navigationTitle,
+            Map parameters) throws DocumentBuildException, PublicationException {
+        String contentsURI = sourceDocument.getSourceURI();
+        add(document, sourceDocument.getResourceType(), navigationTitle, parameters, contentsURI);
+        MetaDataManager mgr = document.getMetaDataManager();
+        MetaDataManager srcMgr = sourceDocument.getMetaDataManager();
+        mgr.getLenyaMetaData().replaceBy(srcMgr.getLenyaMetaData());
+        mgr.getDublinCoreMetaData().replaceBy(srcMgr.getDublinCoreMetaData());
+        mgr.getCustomMetaData().replaceBy(srcMgr.getCustomMetaData());
+    }
 
-            if (initialContentsURI == null)
-                initialContentsURI = documentType.getSampleContentLocation();
+    /**
+     * Adds a document.
+     * @param document The document.
+     * @param documentType The document type.
+     * @param navigationTitle The navigation title.
+     * @param parameters The parameters for the creator.
+     * @param initialContentsURI A URI to read the contents from.
+     * @throws DocumentBuildException if an error occurs.
+     * @throws DocumentException if an error occurs.
+     * @throws PublicationException if an error occurs.
+     */
+    protected void add(Document document,
+            DocumentType documentType,
+            String navigationTitle,
+            Map parameters,
+            String initialContentsURI) throws DocumentBuildException, DocumentException,
+            PublicationException {
+        try {
 
-            if (getLogger().isDebugEnabled())
-                getLogger().debug("DocumentManagerImpl::add() using initialContentsURI ["
-                        + initialContentsURI + "]");
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Create");
+                getLogger().debug("    document:     [" + document + "]");
+                getLogger().debug("    nav title:    [" + navigationTitle + "]");
+                getLogger().debug("    contents URI: [" + initialContentsURI + "]");
+            }
 
             // look up creator for documents of this type
             NodeCreatorInterface creator = documentType.getCreator();

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?rev=170762&r1=170761&r2=170762&view=diff
==============================================================================
--- 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 Wed May 18 08:20:48 2005
@@ -29,7 +29,6 @@
 import org.apache.lenya.ac.User;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.DocumentIdentityMap;
 import org.apache.lenya.cms.publication.DocumentManager;
@@ -113,9 +112,6 @@
             documentTypeBuilder = (DocumentTypeBuilder) this.manager
                     .lookup(DocumentTypeBuilder.ROLE);
 
-            DocumentType documentType = documentTypeBuilder
-                    .buildDocumentType(getDocumentTypeName(), getPublication());
-
             documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
 
             DocumentIdentityMap map = (DocumentIdentityMap) getUnitOfWork().getIdentityMap();
@@ -124,11 +120,20 @@
                     getNewDocumentId(),
                     getParameterAsString(LANGUAGE));
 
-            documentManager.add(document,
-                    documentType,
-                    getParameterAsString(DublinCore.ELEMENT_TITLE),
-                    getInitialContentsURI(),
-                    null);
+            Document initialDocument = getInitialDocument();
+            if (initialDocument == null) {
+                DocumentType documentType = documentTypeBuilder
+                        .buildDocumentType(getDocumentTypeName(), getPublication());
+                documentManager.add(document,
+                        documentType,
+                        getParameterAsString(DublinCore.ELEMENT_TITLE),
+                        null);
+            } else {
+                documentManager.add(document,
+                        initialDocument,
+                        getParameterAsString(DublinCore.ELEMENT_TITLE),
+                        null);
+            }
 
             setMetaData(document);
 
@@ -157,19 +162,14 @@
     protected abstract String getNewDocumentId();
 
     /**
-     * Determine the parent document of the document being created by this usecase
-     * @return the parent document
-     * @throws DocumentBuildException if an error occurs.
-     */
-    protected abstract Document getParentDocument() throws DocumentBuildException;
-
-    /**
      * If the document created in the usecase shall have initial contents copied from an existing
-     * document, construct that document's URI in this method.
+     * document, construct that document in this method.
      * 
-     * @return a URI.
+     * @return A document.
      */
-    protected abstract String getInitialContentsURI();
+    protected Document getInitialDocument() {
+        return null;
+    }
 
     /**
      * @return The type of the created document.

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?rev=170762&r1=170761&r2=170762&view=diff
==============================================================================
--- 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 Wed May 18 08:20:48 2005
@@ -17,7 +17,6 @@
 package org.apache.lenya.cms.site.usecases;
 
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
 import org.apache.lenya.cms.publication.DocumentManager;
 import org.apache.lenya.cms.publication.Publication;
 
@@ -87,23 +86,6 @@
      */
     protected String getNewDocumentId() {
         return getSourceDocument().getId() + "/" + getNewDocumentName();
-    }
-
-    /**
-     * In this usecase, the parent document is simply the source document the usecase was invoked
-     * upon.
-     * @see Create#getParentDocument()
-     */
-    protected Document getParentDocument() throws DocumentBuildException {
-        return getSourceDocument();
-    }
-
-    /**
-     * New document: no existing document is referenced
-     * @see Create#getInitialContentsURI()
-     */
-    protected String getInitialContentsURI() {
-        return null;
     }
 
     /**

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?rev=170762&r1=170761&r2=170762&view=diff
==============================================================================
--- 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 Wed May 18 08:20:48 2005
@@ -116,21 +116,11 @@
     }
 
     /**
-     * For new language version, the parent document is the same as for the document the usecase is called on
-     * @see Create#getParentDocument()
-     */
-    protected Document getParentDocument() throws DocumentBuildException {
-        DocumentIdentityMap documentMap = getSourceDocument().getIdentityMap();
-        Document parent = documentMap.getParent(getSourceDocument());
-        return parent;
-    }
-
-    /**
      * New language version of a document: use that document's content
-     * @see Create#getInitialContentsURI()
+     * @see Create#getInitialDocument()
      */
-    protected String getInitialContentsURI() {
-        return getSourceDocument().getSourceURI();
+    protected Document getInitialDocument() {
+        return getSourceDocument();
     }
 
     /**

Modified: lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java?rev=170762&r1=170761&r2=170762&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java Wed May 18 08:20:48 2005
@@ -116,7 +116,6 @@
             documentManager.add(document,
                     documentType,
                     getParameterAsString(DublinCore.ELEMENT_TITLE),
-                    null,
                     allParameters);
         } finally {
             if (documentManager != null) {



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