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 10:45:20 UTC
svn commit: r170727 - 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 01:45:18 2005
New Revision: 170727
URL: http://svn.apache.org/viewcvs?rev=170727&view=rev
Log:
updated DocumentManager.add() signature: don't require parent document, pass info as single strings
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/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=170727&r1=170726&r2=170727&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 01:45:18 2005
@@ -59,34 +59,35 @@
void copyToArea(DocumentSet documentSet, String destinationArea) throws PublicationException;
/**
- * Creates a new document in the same publication the <code>parentDocument</code>
- * belongs to with the given parameters:
- *
- * @param parentDocument The parent document.
- * @param newDocumentNodeName the name of the node representing the new document
+ * Creates a new document in the same publication the <code>parentDocument</code> belongs to
+ * with the given parameters:
+ *
+ * @param map The identity map.
+ * @param publication The publication.
+ * @param area The area.
* @param newDocumentId the id of the new document
- * @param documentTypeName the document type (aka resource type) of the new document
+ * @param documentType the document type (aka resource type) of the new document
* @param language language 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 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
* @return A document.
*
* @throws DocumentBuildException if the document can not be created
* @throws PublicationException if the document is already contained.
*/
- Document add(Document parentDocument,
- String newDocumentNodeName,
- String newDocumentId,
- String documentTypeName,
- String language,
- String navigationTitle,
- String initialContentsURI,
- Map parameters)
- throws DocumentBuildException, PublicationException;
+ Document add(DocumentIdentityMap map,
+ Publication publication,
+ String area,
+ String newDocumentId,
+ String language,
+ DocumentType documentType,
+ String navigationTitle,
+ String initialContentsURI,
+ Map parameters) throws DocumentBuildException, PublicationException;
/**
* Deletes a document.
@@ -138,9 +139,12 @@
* @throws DocumentBuildException if an error occurs.
* @throws DocumentException if an error occurs.
*/
- String[] canCreate(DocumentIdentityMap identityMap, Publication publication, String area,
- Document parent, String nodeId, String language) throws DocumentBuildException,
- DocumentException;
+ String[] canCreate(DocumentIdentityMap identityMap,
+ Publication publication,
+ String area,
+ Document parent,
+ String nodeId,
+ String language) throws DocumentBuildException, DocumentException;
/**
* Moves a document to another location, incl. all requiring documents. If a sitetree is used,
@@ -198,4 +202,4 @@
*/
void delete(DocumentSet documents) throws PublicationException;
-}
+}
\ No newline at end of file
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=170727&r1=170726&r2=170727&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 01:45:18 2005
@@ -56,29 +56,28 @@
* 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,String,String,String,String,String,String,Map)
+ * @see DocumentManager#add(DocumentIdentityMap,
+ * Publication,String,String,String,DocumentType,String,String,Map)
* @see org.apache.lenya.cms.authoring.NodeCreatorInterface
* @see org.apache.lenya.cms.publication.DocumentBuilder
*/
- public Document add(Document parentDocument, String newDocumentNodeName, String newDocumentId,
- String documentTypeName, String language, String navigationTitle,
- String initialContentsURI, Map parameters)
- throws DocumentBuildException, PublicationException {
+ public Document add(DocumentIdentityMap map,
+ Publication publication,
+ String area,
+ String newDocumentId,
+ String language,
+ DocumentType documentType,
+ String navigationTitle,
+ String initialContentsURI,
+ Map parameters) throws DocumentBuildException, PublicationException {
if (getLogger().isDebugEnabled())
- getLogger().debug("DocumentManagerImpl::add() called with:\n"
- + "\t parentDocument.getId() [" + (parentDocument != null ? parentDocument.getId() : "null") + "]\n"
- + "\t newDocumentNodeName [" + newDocumentNodeName + "]\n"
- + "\t newDocumentId [" + newDocumentId + "]\n" + "\t documentTypeName ["
- + documentTypeName + "]\n" + "\t language [" + language + "]\n"
- + "\t navigationTitle [" + navigationTitle + "]\n" + "\t initialContentsURI ["
- + initialContentsURI + "]\n"
+ getLogger().debug("DocumentManagerImpl::add() called with:\n" + "\t newDocumentId ["
+ + newDocumentId + "]\n" + "\t documentTypeName [" + documentType.getName() + "]\n"
+ + "\t language [" + language + "]\n" + "\t navigationTitle [" + navigationTitle
+ + "]\n" + "\t initialContentsURI [" + initialContentsURI + "]\n"
+ "\t non-empty parameters [" + (parameters != null) + "]\n");
- Publication publication = parentDocument.getPublication();
- DocumentIdentityMap map = parentDocument.getIdentityMap();
- String area = parentDocument.getArea();
-
/*
* Get an instance of Document. This will (ultimately) be created by the implementation for
* the DocumentBuilder role.
@@ -88,24 +87,8 @@
Document newDocument = map.get(publication, area, newDocumentId, language);
if (getLogger().isDebugEnabled())
- getLogger()
- .debug("DocumentManagerImpl::add() looking up a DocumentTypeBuilder so that we can call the creator");
-
- // Get an instance of DocumentType
- DocumentTypeBuilder documentTypeBuilder = null;
- DocumentType documentType = null;
- try {
- documentTypeBuilder = (DocumentTypeBuilder) this.manager
- .lookup(DocumentTypeBuilder.ROLE);
-
- documentType = documentTypeBuilder.buildDocumentType(documentTypeName, publication);
- } catch (Exception e) {
- throw new DocumentBuildException("could not build type for new document", e);
- } finally {
- if (documentTypeBuilder != null) {
- this.manager.release(documentTypeBuilder);
- }
- }
+ getLogger().debug("DocumentManagerImpl::add() looking up a DocumentTypeBuilder"
+ + " so that we can call the creator");
// Call the creator for the document type to physically create a document of this type
try {
@@ -124,8 +107,16 @@
// where, relative to content base (and potentially to the parent
// as well), the new document shall be created
String contentBaseURI = publication.getContentURI(area);
- String parentId = (parentDocument != null ? parentDocument.getId() : "/");
- String newDocumentURI = creator.getNewDocumentURI(contentBaseURI, parentId, newDocumentNodeName, language);
+
+ String[] steps = newDocumentId.split("/");
+ String newDocumentNodeName = steps[steps.length - 1];
+ String parentId = newDocumentId.substring(0, newDocumentId.length()
+ - ("/" + newDocumentNodeName).length());
+
+ String newDocumentURI = creator.getNewDocumentURI(contentBaseURI,
+ parentId,
+ newDocumentNodeName,
+ language);
// Important note:
// how the new document's source URI is constructed is
@@ -149,15 +140,11 @@
parameters);
} catch (Exception e) {
throw new DocumentBuildException("call to creator for new document failed", e);
- } finally {
- if (documentTypeBuilder != null) {
- this.manager.release(documentTypeBuilder);
- }
}
// Write Lenya-internal meta-data
Map lenyaMetaData = new HashMap(2);
- lenyaMetaData.put(LenyaMetaData.ELEMENT_RESOURCE_TYPE, documentTypeName);
+ lenyaMetaData.put(LenyaMetaData.ELEMENT_RESOURCE_TYPE, documentType.getName());
lenyaMetaData.put(LenyaMetaData.ELEMENT_CONTENT_TYPE, "xml");
newDocument.getMetaDataManager().setLenyaMetaData(lenyaMetaData);
@@ -363,9 +350,12 @@
* org.apache.lenya.cms.publication.Publication, java.lang.String,
* org.apache.lenya.cms.publication.Document, java.lang.String, java.lang.String)
*/
- public String[] canCreate(DocumentIdentityMap identityMap, Publication publication,
- String area, Document parent, String nodeId, String language)
- throws DocumentBuildException, DocumentException {
+ public String[] canCreate(DocumentIdentityMap identityMap,
+ Publication publication,
+ String area,
+ Document parent,
+ String nodeId,
+ String language) throws DocumentBuildException, DocumentException {
List errorMessages = new ArrayList();
@@ -740,4 +730,4 @@
copy(sortedSourceDocs[i], (Document) source2target.get(sortedSourceDocs[i]));
}
}
-}
+}
\ No newline at end of file
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=170727&r1=170726&r2=170727&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 01:45:18 2005
@@ -31,7 +31,10 @@
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;
@@ -105,21 +108,33 @@
// create new document
DocumentManager documentManager = null;
Document newDocument = null;
+ DocumentTypeBuilder documentTypeBuilder = null;
try {
- documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- newDocument =
- documentManager.add(getParentDocument(),
- getNewDocumentName(),
- getNewDocumentId(),
- getDocumentTypeName(),
- getParameterAsString(LANGUAGE),
- getParameterAsString(DublinCore.ELEMENT_TITLE),
- getInitialContentsURI(),
- null);
- }
- finally {
- if (documentManager != null)
- this.manager.release(documentManager);
+
+ documentTypeBuilder = (DocumentTypeBuilder) this.manager
+ .lookup(DocumentTypeBuilder.ROLE);
+
+ DocumentType documentType = documentTypeBuilder
+ .buildDocumentType(getDocumentTypeName(), getPublication());
+
+ documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+ newDocument = documentManager.add((DocumentIdentityMap) getUnitOfWork()
+ .getIdentityMap(),
+ getPublication(),
+ getSourceDocument().getArea(),
+ getNewDocumentId(),
+ getParameterAsString(LANGUAGE),
+ documentType,
+ getParameterAsString(DublinCore.ELEMENT_TITLE),
+ getInitialContentsURI(),
+ null);
+ } finally {
+ if (documentManager != null) {
+ this.manager.release(documentManager);
+ }
+ if (documentTypeBuilder != null) {
+ this.manager.release(documentTypeBuilder);
+ }
}
// set dublin core meta-data
@@ -130,7 +145,6 @@
}
-
/**
* @return the name of the document being created in the usecase
*/
@@ -149,10 +163,9 @@
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.
- *
+ * If the document created in the usecase shall have initial contents copied from an existing
+ * document, construct that document's URI in this method.
+ *
* @return a URI.
*/
protected abstract String getInitialContentsURI();
@@ -173,20 +186,16 @@
throw new IllegalArgumentException("parameter document may not be null");
Map dcMetaData = new HashMap();
- dcMetaData.put(DublinCore.ELEMENT_TITLE,
- getParameterAsString(DublinCore.ELEMENT_TITLE));
- dcMetaData.put(DublinCore.ELEMENT_CREATOR,
- getParameterAsString(DublinCore.ELEMENT_CREATOR));
+ dcMetaData.put(DublinCore.ELEMENT_TITLE, getParameterAsString(DublinCore.ELEMENT_TITLE));
+ dcMetaData
+ .put(DublinCore.ELEMENT_CREATOR, getParameterAsString(DublinCore.ELEMENT_CREATOR));
dcMetaData.put(DublinCore.ELEMENT_PUBLISHER,
getParameterAsString(DublinCore.ELEMENT_PUBLISHER));
- dcMetaData.put(DublinCore.ELEMENT_SUBJECT,
- getParameterAsString(DublinCore.ELEMENT_SUBJECT));
- dcMetaData.put(DublinCore.ELEMENT_DATE,
- getParameterAsString(DublinCore.ELEMENT_DATE));
- dcMetaData.put(DublinCore.ELEMENT_RIGHTS,
- getParameterAsString(DublinCore.ELEMENT_RIGHTS));
- dcMetaData.put(DublinCore.ELEMENT_LANGUAGE,
- getParameterAsString(LANGUAGE));
+ dcMetaData
+ .put(DublinCore.ELEMENT_SUBJECT, getParameterAsString(DublinCore.ELEMENT_SUBJECT));
+ dcMetaData.put(DublinCore.ELEMENT_DATE, getParameterAsString(DublinCore.ELEMENT_DATE));
+ dcMetaData.put(DublinCore.ELEMENT_RIGHTS, getParameterAsString(DublinCore.ELEMENT_RIGHTS));
+ dcMetaData.put(DublinCore.ELEMENT_LANGUAGE, getParameterAsString(LANGUAGE));
document.getMetaDataManager().setDublinCoreMetaData(dcMetaData);
}
@@ -214,7 +223,8 @@
}
/**
- * @return The source document or <code>null</code> if the usecase was not invoked on a document.
+ * @return The source document or <code>null</code> if the usecase was not invoked on a
+ * document.
*/
protected Document getSourceDocument() {
Document document = null;
@@ -240,12 +250,10 @@
private Publication publication;
/**
- * Access to the current publication.
- * Use this when the publication is not yet known in the usecase:
- * e.g. when creating a global asset. When adding a resource or a child
- * to a document, access the publication via that document's interface
- * instead.
- *
+ * Access to the current publication. Use this when the publication is not yet known in the
+ * usecase: e.g. when creating a global asset. When adding a resource or a child to a document,
+ * access the publication via that document's interface instead.
+ *
* @return the publication in which the use-case is being executed
*/
protected Publication getPublication() {
@@ -259,4 +267,4 @@
}
return this.publication;
}
-}
+}
\ No newline at end of file
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=170727&r1=170726&r2=170727&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 01:45:18 2005
@@ -28,10 +28,12 @@
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
+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.usecase.DocumentUsecase;
-
/**
* Usecase to create a Blog entry.
*
@@ -93,26 +95,36 @@
// document id (full path) and document id-name (this leaf's id)
// are the same
DocumentManager documentManager = null;
- Document newDocument = null;
+ DocumentTypeBuilder documentTypeBuilder = null;
try {
+ documentTypeBuilder = (DocumentTypeBuilder) this.manager
+ .lookup(DocumentTypeBuilder.ROLE);
+
+ DocumentType documentType = documentTypeBuilder
+ .buildDocumentType(getDocumentTypeName(), getSourceDocument().getPublication());
+
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- newDocument =
- documentManager.add(parent,
- documentId,
- documentId,
- getDocumentTypeName(),
- language,
- getParameterAsString(DublinCore.ELEMENT_TITLE),
- null,
- allParameters);
- }
- finally {
- if (documentManager != null)
+ documentManager.add((DocumentIdentityMap) getUnitOfWork().getIdentityMap(),
+ getSourceDocument().getPublication(),
+ getSourceDocument().getArea(),
+ documentId,
+ language,
+ documentType,
+ getParameterAsString(DublinCore.ELEMENT_TITLE),
+ null,
+ allParameters);
+ } finally {
+ if (documentManager != null) {
this.manager.release(documentManager);
+ }
+ if (documentTypeBuilder != null) {
+ this.manager.release(documentTypeBuilder);
+ }
}
}
/**
+ * @return The document name.
* @see org.apache.lenya.cms.site.usecases.Create#getNewDocumentName()
*/
protected String getNewDocumentName() {
@@ -120,9 +132,10 @@
}
/**
+ * @return The name of the document type.
* @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
*/
protected String getDocumentTypeName() {
return getParameterAsString(DOCUMENT_TYPE);
}
-}
+}
\ 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