You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by jw...@apache.org on 2005/05/12 11:58:24 UTC
svn commit: r169797 -
/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: jwkaltz
Date: Thu May 12 02:58:22 2005
New Revision: 169797
URL: http://svn.apache.org/viewcvs?rev=169797&view=rev
Log:
factorize document creation code into superclass
Modified:
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 (contents, props changed)
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=169797&r1=169796&r2=169797&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 Thu May 12 02:58:22 2005
@@ -16,7 +16,9 @@
*/
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.HashMap;
import java.util.Map;
@@ -28,12 +30,17 @@
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.LenyaMetaData;
import org.apache.lenya.cms.metadata.MetaData;
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;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.cms.publication.DocumentTypeBuilder;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.publication.PublicationFactory;
@@ -146,7 +153,103 @@
* @return A document.
* @throws Exception if an error occurs.
*/
- protected abstract Document createDocument() throws Exception;
+ protected Document createDocument() throws Exception {
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("createDocument() called");
+
+ Document usecaseDocument = getSourceDocument();
+ String newDocumentId = getNewDocumentId();
+ String navigationTitle = getParameterAsString(DublinCore.ELEMENT_TITLE);
+ String documentTypeName = getDocumentTypeName();
+ String language = getParameterAsString(LANGUAGE);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("createDocument() read parameters:");
+ getLogger().debug(" UsecaseDocument document: [" + usecaseDocument.getId() + "]");
+ getLogger().debug(" Child document: [" + newDocumentId + "]");
+ getLogger().debug(" Language: [" + language + "]");
+ getLogger().debug(" Document Type: [" + documentTypeName + "]");
+ getLogger().debug(" Navigation Title: [" + navigationTitle + "]");
+ }
+
+ Publication publication = usecaseDocument.getPublication();
+ DocumentIdentityMap map = usecaseDocument.getIdentityMap();
+ String area = usecaseDocument.getArea();
+
+ /*
+ * Get an instance of Document.
+ * This will (ultimately) be created by the implementation for
+ * the DocumentBuilder role.
+ */
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("createDocument() creating Document instance");
+ Document document = map.get(publication, area, newDocumentId, language);
+ Transactionable[] nodes = document.getRepositoryNodes();
+ for (int i = 0; i < nodes.length; i++) {
+ nodes[i].lock();
+ }
+
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("createDocument() looking up a DocumentTypeBuilder so that we can call the creator");
+
+ /*
+ * Create an instance of DocumentType, and then
+ * use the creator for this DocumentType to actually
+ * physically create a document of this type.
+ */
+ DocumentTypeBuilder documentTypeBuilder = null;
+ DocumentType documentType = null;
+ try {
+ documentTypeBuilder = (DocumentTypeBuilder) this.manager.lookup(DocumentTypeBuilder.ROLE);
+
+ documentType = documentTypeBuilder.buildDocumentType(documentTypeName, publication);
+
+ String parentId = "";
+ Document parentDocument = getParentDocument(document);
+ if (parentDocument != null)
+ parentId = parentDocument.getId().substring(1);
+
+ String childId = document.getName();
+ ParentChildCreatorInterface creator = documentType.getCreator();
+ creator.create(
+ getInitialContentsURI(parentDocument, documentType),
+ new File(publication.getContentDirectory(area), parentId),
+ childId,
+ ParentChildCreatorInterface.BRANCH_NODE,
+ navigationTitle,
+ language,
+ Collections.EMPTY_MAP);
+ }
+ finally {
+ if (documentTypeBuilder != null) {
+ this.manager.release(documentTypeBuilder);
+ }
+ }
+
+ return document;
+ }
+
+
+ /**
+ * @return the id of the new document being created in the usecase
+ */
+ protected abstract String getNewDocumentId();
+
+ /**
+ * @param newDocument the new document being created in the usecase
+ * @return the new document's parent
+ */
+ protected abstract Document getParentDocument(Document newDocument) throws DocumentBuildException;
+
+ /**
+ * If there is a reference document from which to copy contents,
+ * pass this as parameter. If there is no such document, the document
+ * type will be used instead to read a sample content.
+ *
+ * @param referenceDocument the document to use as reference for the initial contents
+ * @param type the type of resource to be created
+ */
+ protected abstract String getInitialContentsURI(Document referenceDocument, DocumentType type);
/**
* @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=169797&r1=169796&r2=169797&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 Thu May 12 02:58:22 2005
@@ -16,17 +16,11 @@
*/
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.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.DocumentType;
-import org.apache.lenya.cms.publication.DocumentTypeBuilder;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.transaction.Transactionable;
/**
* Usecase to create a document.
@@ -82,82 +76,29 @@
}
/**
- * @see org.apache.lenya.cms.site.usecases.Create#createDocument()
+ * @see Create#getNewDocumentId()
*/
- protected Document createDocument() throws Exception {
-
- if (getLogger().isDebugEnabled())
- getLogger().debug("createDocument() called; first retrieving parent");
-
- 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("createDocument() read parameters:");
- 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();
-
- /*
- * Get an instance of Document.
- * This will (ultimately) be created by the implementation for
- * the DocumentBuilder role.
- */
- if (getLogger().isDebugEnabled())
- getLogger().debug("createDocument() creating Document instance");
- Document document = parent.getIdentityMap().get(publication,
- area,
- documentId,
- language);
- Transactionable[] nodes = document.getRepositoryNodes();
- for (int i = 0; i < nodes.length; i++) {
- nodes[i].lock();
- }
-
- /*
- * Create an instance of DocumentType, and then
- * use the creator for this DocumentType to actually
- * physically create a document of this type.
- */
- if (getLogger().isDebugEnabled())
- getLogger().debug("createDocument() looking up a DocumentTypeBuilder so that we can call the creator");
- DocumentTypeBuilder documentTypeBuilder = null;
- DocumentType documentType = null;
- try {
- documentTypeBuilder = (DocumentTypeBuilder) this.manager.lookup(DocumentTypeBuilder.ROLE);
-
- documentType = documentTypeBuilder.buildDocumentType(documentTypeName, publication);
+ protected String getNewDocumentId() {
+ return getSourceDocument().getId() + "/" + getParameterAsString(DOCUMENT_ID);
+ }
- String parentId = parent.getId().substring(1);
- String childId = document.getName();
- ParentChildCreatorInterface creator = documentType.getCreator();
- creator.create(
- documentType.getSampleContentLocation(),
- new File(publication.getContentDirectory(area), parentId),
- childId,
- ParentChildCreatorInterface.BRANCH_NODE,
- navigationTitle,
- language,
- Collections.EMPTY_MAP);
- }
- finally {
- if (documentTypeBuilder != null) {
- this.manager.release(documentTypeBuilder);
- }
- }
+ /**
+ * In this usecase, the parent document is simply the source
+ * document the usecase was invoked upon.
+ * @see Create#getParentDocument(Document)
+ */
+ protected Document getParentDocument(Document newDocument) throws DocumentBuildException {
+ return getSourceDocument();
+ }
- return document;
+ /**
+ * New document: reference not relevant, use type sample
+ * @see Create#getInitialContentsURI(Document, DocumentType)
+ */
+ protected String getInitialContentsURI(Document referenceDocument, DocumentType type) {
+ return type.getSampleContentLocation();
}
+
/**
* @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
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=169797&r1=169796&r2=169797&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 Thu May 12 02:58:22 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -16,22 +16,16 @@
*/
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.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
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;
-import org.apache.lenya.transaction.Transactionable;
/**
* Usecase to create a new language version of a resource.
@@ -105,65 +99,37 @@
}
/**
- * @see org.apache.lenya.cms.site.usecases.Create#createDocument()
+ * For new language version of a document, id is the same
+ * as that document's
+ * @see Create#getNewDocumentId()
*/
- 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();
- DocumentIdentityMap map = source.getIdentityMap();
- String area = source.getArea();
- Document document = map.get(publication, area, source.getId(), language);
- Transactionable[] nodes = document.getRepositoryNodes();
- for (int i = 0; i < nodes.length; i++) {
- nodes[i].lock();
- }
-
- // create an instance of DocumentType
- DocumentTypeBuilder documentTypeBuilder = null;
- DocumentType documentType = null;
- try {
- documentTypeBuilder = (DocumentTypeBuilder) this.manager.lookup(DocumentTypeBuilder.ROLE);
-
- documentType = documentTypeBuilder.buildDocumentType(documentTypeName, publication);
-
- String parentId = "";
- Document parent = map.getParent(document);
- if (parent != null) {
- parentId = map.getParent(document).getId().substring(1);
- }
-
- String childId = document.getName();
+ protected String getNewDocumentId() {
+ return getSourceDocument().getId();
+ }
- documentType.getCreator().create(
- documentType.getSampleContentLocation(),
- new File(publication.getContentDirectory(area), parentId),
- childId,
- ParentChildCreatorInterface.BRANCH_NODE,
- navigationTitle,
- language,
- Collections.EMPTY_MAP);
- }
- finally {
- if (documentTypeBuilder != null) {
- this.manager.release(documentTypeBuilder);
- }
- }
+ /**
+ * The parent document is retrieved via the new document's
+ * identity map.
+ * @see Create#getParentDocument(Document)
+ */
+ protected Document getParentDocument(Document newDocument) throws DocumentBuildException {
+ DocumentIdentityMap documentMap = newDocument.getIdentityMap();
+ Document parent = documentMap.getParent(newDocument);
+ return parent;
+ }
+ /**
+ * New language version of a document:
+ * use that document's content
+ * @see Create#getInitialContentsURI(Document, DocumentType)
+ */
+ protected String getInitialContentsURI(Document referenceDocument, DocumentType type) {
+ // FIXME: this should be
+ // return referenceDocument.getSourceURI();
+ // but this can only work if DefaultCreator no longer uses
+ // File to read initial contents, and can work with a Lenya URI
- return document;
+ return type.getSampleContentLocation();
}
/**
Propchange: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org