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/01/10 11:35:58 UTC

svn commit: r124784 - /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

Author: andreas
Date: Mon Jan 10 02:35:56 2005
New Revision: 124784

URL: http://svn.apache.org/viewcvs?view=rev&rev=124784
Log:
added CreateDocument usecase
Added:
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
Modified:
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java

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&rev=124784&p1=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java&r1=124783&p2=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java&r2=124784
==============================================================================
--- 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	Mon Jan 10 02:35:56 2005
@@ -16,9 +16,7 @@
  */
 package org.apache.lenya.cms.site.usecases;
 
-import java.io.File;
 import java.text.SimpleDateFormat;
-import java.util.Collections;
 import java.util.GregorianCalendar;
 import java.util.Map;
 
@@ -28,7 +26,6 @@
 import org.apache.cocoon.environment.Session;
 import org.apache.lenya.ac.Identity;
 import org.apache.lenya.ac.User;
-import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentException;
@@ -40,22 +37,16 @@
 import org.apache.lenya.cms.workflow.WorkflowFactory;
 
 /**
- * Usecase to create a resource.
+ * Abstract superclass for usecases to create a resource.
  * 
  * @version $Id: Create.java 123982 2005-01-03 15:01:19Z andreas $
  */
-public class Create extends DocumentUsecase {
+public abstract class Create extends DocumentUsecase {
 
     protected static final String LANGUAGE = "language";
-
     protected static final String LANGUAGES = "languages";
-
-    protected static final String PARENT_ID = "parentId";
-
     protected static final String DOCUMENT_ID = "documentId";
 
-    protected static final String DOCUMENT_TYPE = "doctype";
-
     /**
      * Ctor.
      */
@@ -96,46 +87,16 @@
     protected void doExecute() throws Exception {
         super.doExecute();
 
-        Document parent = getSourceDocument();
-
-        String documentId = parent.getId() + "/" + getParameterAsString(DOCUMENT_ID);
-        String navigationTitle = getParameterAsString(DublinCore.ELEMENT_TITLE);
-        String documentTypeName = getParameterAsString(DOCUMENT_TYPE);
-        String language = getParameterAsString(LANGUAGE);
-
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Creating document");
-            getLogger().debug("    Parent document:   [" + parent.getId() + "]");
-            getLogger().debug("    Child document:    [" + documentId + "]");
-            getLogger().debug("    Language:          [" + language + "]");
-            getLogger().debug("    Document Type:     [" + documentTypeName + "]");
-            getLogger().debug("    Navigation Title:  [" + navigationTitle + "]");
-        }
-
-        Publication publication = parent.getPublication();
-        String area = parent.getArea();
-        Document document = parent.getIdentityMap().getFactory().get(area, documentId, language);
+        Document document = createDocument();
+        Publication publication = document.getPublication();
+        String documentTypeName = getDocumentTypeName();
 
         DocumentType documentType = DocumentTypeBuilder.buildDocumentType(documentTypeName,
                 publication);
 
-        String parentId = parent.getId().substring(1);
-        String childId = document.getName();
-
-        File doctypesDirectory = new File(publication.getDirectory(),
-                DocumentTypeBuilder.DOCTYPE_DIRECTORY);
-
-        documentType.getCreator().create(new File(doctypesDirectory, "samples"),
-                new File(publication.getContentDirectory(area), parentId),
-                childId,
-                ParentChildCreatorInterface.BRANCH_NODE,
-                navigationTitle,
-                language,
-                Collections.EMPTY_MAP);
-
         SiteManager manager = publication.getSiteManager(document.getIdentityMap());
         manager.add(document);
-        manager.setLabel(document, navigationTitle);
+        manager.setLabel(document, getParameterAsString(DublinCore.ELEMENT_TITLE));
 
         WorkflowFactory.initHistory(document, documentType.getWorkflowFileName(), getSituation());
 
@@ -144,6 +105,18 @@
     }
 
     /**
+     * Creates a document.
+     * @return A document.
+     * @throws Exception if an error occurs.
+     */
+    protected abstract Document createDocument() throws Exception;
+
+    /**
+     * @return The type of the created document.
+     */
+    protected abstract String getDocumentTypeName();
+
+    /**
      * Sets the meta data of the created document.
      * @param document The document.
      * @throws DocumentException if an error occurs.
@@ -171,9 +144,6 @@
     protected void initParameters() {
         super.initParameters();
 
-        Document parent = getSourceDocument();
-        setParameter(PARENT_ID, parent.getId());
-
         Map objectModel = ContextHelper.getObjectModel(getContext());
         Request request = ObjectModelHelper.getRequest(objectModel);
         Session session = request.getSession(false);
@@ -184,7 +154,5 @@
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
         setParameter(DublinCore.ELEMENT_DATE, format.format(new GregorianCalendar().getTime()));
 
-        String[] languages = parent.getPublication().getLanguages();
-        setParameter(LANGUAGES, languages);
     }
 }

Added: 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=auto&rev=124784
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java	Mon Jan 10 02:35:56 2005
@@ -0,0 +1,102 @@
+/*
+ * 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.site.usecases;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.cms.publication.DocumentTypeBuilder;
+import org.apache.lenya.cms.publication.Publication;
+
+/**
+ * Usecase to create a document.
+ *
+ * @version $Id:$
+ */
+public class CreateDocument extends Create {
+
+    protected static final String PARENT_ID = "parentId";
+    protected static final String DOCUMENT_TYPE = "doctype";
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+     */
+    protected void initParameters() {
+        super.initParameters();
+
+        Document parent = getSourceDocument();
+        setParameter(PARENT_ID, parent.getId());
+
+        String[] languages = parent.getPublication().getLanguages();
+        setParameter(LANGUAGES, languages);
+    }
+    
+    /**
+     * @see org.apache.lenya.cms.site.usecases.Create#createDocument()
+     */
+    protected Document createDocument() throws Exception {
+        Document parent = getSourceDocument();
+
+        String documentId = parent.getId() + "/" + getParameterAsString(DOCUMENT_ID);
+        String navigationTitle = getParameterAsString(DublinCore.ELEMENT_TITLE);
+        String documentTypeName = getDocumentTypeName();
+        String language = getParameterAsString(LANGUAGE);
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Creating document");
+            getLogger().debug("    Parent document:   [" + parent.getId() + "]");
+            getLogger().debug("    Child document:    [" + documentId + "]");
+            getLogger().debug("    Language:          [" + language + "]");
+            getLogger().debug("    Document Type:     [" + documentTypeName + "]");
+            getLogger().debug("    Navigation Title:  [" + navigationTitle + "]");
+        }
+
+        Publication publication = parent.getPublication();
+        String area = parent.getArea();
+        Document document = parent.getIdentityMap().getFactory().get(area, documentId, language);
+
+        DocumentType documentType = DocumentTypeBuilder.buildDocumentType(documentTypeName,
+                publication);
+
+        String parentId = parent.getId().substring(1);
+        String childId = document.getName();
+
+        File doctypesDirectory = new File(publication.getDirectory(),
+                DocumentTypeBuilder.DOCTYPE_DIRECTORY);
+
+        documentType.getCreator().create(new File(doctypesDirectory, "samples"),
+                new File(publication.getContentDirectory(area), parentId),
+                childId,
+                ParentChildCreatorInterface.BRANCH_NODE,
+                navigationTitle,
+                language,
+                Collections.EMPTY_MAP);
+        
+        return document;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
+     */
+    protected String getDocumentTypeName() {
+        return getParameterAsString(DOCUMENT_TYPE);
+    }
+}

Added: 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=auto&rev=124784
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java	Mon Jan 10 02:35:56 2005
@@ -0,0 +1,127 @@
+/*
+ * 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.site.usecases;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.cms.publication.DocumentTypeBuilder;
+import org.apache.lenya.cms.publication.DocumentTypeResolver;
+import org.apache.lenya.cms.publication.Publication;
+
+/**
+ * Usecase to create a new language version of a resource.
+ * 
+ * @version $Id:$
+ */
+public class CreateLanguage extends Create {
+
+    private String documentType;
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+     */
+    protected void initParameters() {
+        super.initParameters();
+
+        Document source = getSourceDocument();
+        DocumentTypeResolver resolver = null;
+
+        try {
+
+            resolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+            DocumentType type = resolver.resolve(source);
+            this.documentType = type.getName();
+
+            List nonExistingLanguages = new ArrayList();
+            String[] languages = source.getPublication().getLanguages();
+            DocumentFactory factory = source.getIdentityMap().getFactory();
+            for (int i = 0; i < languages.length; i++) {
+                Document version = factory.get(source.getArea(), source.getId(), languages[i]);
+                if (!version.exists()) {
+                    nonExistingLanguages.add(languages[i]);
+                }
+            }
+            setParameter(LANGUAGES, nonExistingLanguages.toArray(new String[nonExistingLanguages
+                    .size()]));
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            this.manager.release(resolver);
+        }
+
+    }
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.Create#createDocument()
+     */
+    protected Document createDocument() throws Exception {
+
+        Document source = getSourceDocument();
+        String navigationTitle = getParameterAsString(DublinCore.ELEMENT_TITLE);
+        String documentTypeName = getDocumentTypeName();
+        String language = getParameterAsString(LANGUAGE);
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Creating document language version");
+            getLogger().debug("    Child document:    [" + source.getId() + "]");
+            getLogger().debug("    Language:          [" + language + "]");
+            getLogger().debug("    Document Type:     [" + documentTypeName + "]");
+            getLogger().debug("    Navigation Title:  [" + navigationTitle + "]");
+        }
+
+        Publication publication = source.getPublication();
+        String area = source.getArea();
+        DocumentFactory factory = source.getIdentityMap().getFactory();
+        Document document = factory.get(area, source.getId(), language);
+
+        DocumentType documentType = DocumentTypeBuilder.buildDocumentType(documentTypeName,
+                publication);
+
+        String parentId = factory.getParent(document).getId().substring(1);
+        String childId = document.getName();
+
+        File doctypesDirectory = new File(publication.getDirectory(),
+                DocumentTypeBuilder.DOCTYPE_DIRECTORY);
+
+        documentType.getCreator().create(new File(doctypesDirectory, "samples"),
+                new File(publication.getContentDirectory(area), parentId),
+                childId,
+                ParentChildCreatorInterface.BRANCH_NODE,
+                navigationTitle,
+                language,
+                Collections.EMPTY_MAP);
+
+        return document;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
+     */
+    protected String getDocumentTypeName() {
+        return this.documentType;
+    }
+
+}
\ No newline at end of file

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