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 12:09:13 UTC
svn commit: r170732 - in /lenya/trunk/src:
java/org/apache/lenya/cms/authoring/ java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/site/usecases/
webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/authoring/
webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/site/usecases/
Author: andreas
Date: Wed May 18 03:09:10 2005
New Revision: 170732
URL: http://svn.apache.org/viewcvs?rev=170732&view=rev
Log:
simplified Creator interface
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java
lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java
lenya/trunk/src/java/org/apache/lenya/cms/authoring/NodeCreatorInterface.java
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/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/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/authoring/NewBlogEntryCreator.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/authoring/DefaultBranchCreator.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java?rev=170732&r1=170731&r2=170732&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java Wed May 18 03:09:10 2005
@@ -24,23 +24,4 @@
*/
public class DefaultBranchCreator extends DefaultCreator {
- /**
- * @see org.apache.lenya.cms.authoring.NodeCreatorInterface#getNewDocumentURI(String, String, String, String)
- */
- public String getNewDocumentURI(
- String contentBaseURI,
- String parentId,
- String newId,
- String language) {
- return
- contentBaseURI
- + parentId
- + "/"
- + newId
- + "/"
- + "index"
- + getLanguageSuffix(language)
- + ".xml";
- }
-
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java?rev=170732&r1=170731&r2=170732&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java Wed May 18 03:09:10 2005
@@ -33,13 +33,14 @@
* Base creator for creating documents
* @version $Id$
*/
-public abstract class DefaultCreator extends AbstractLogEnabled implements NodeCreatorInterface {
+public abstract class DefaultCreator extends AbstractLogEnabled implements NodeCreatorInterface {
private String sampleResourceName = null;
private ServiceManager manager;
/**
- * @see org.apache.lenya.cms.authoring.NodeCreatorInterface#init(Configuration, ServiceManager, Logger)
+ * @see org.apache.lenya.cms.authoring.NodeCreatorInterface#init(Configuration, ServiceManager,
+ * Logger)
*/
public void init(Configuration conf, ServiceManager _manager, Logger _logger) {
// parameter conf ignored: nothing to configure in current implementation
@@ -62,74 +63,45 @@
/**
* @see NodeCreatorInterface#create(String, String, String, String, Map)
- */
- public void create(
- String initialContentsURI,
- String newURI,
- String childId,
- String childName,
- Map parameters)
- throws Exception {
+ */
+ public void create(String initialContentsURI,
+ org.apache.lenya.cms.publication.Document document,
+ Map parameters) throws Exception {
if (getLogger().isDebugEnabled())
- getLogger().debug("DefaultCreator::create() called with\n"
- + "\t initialContentsURI [" + initialContentsURI + "]\n"
- + "\t newURI [" + newURI + "]\n"
- + "\t childId [" + childId + "]\n"
- + "\t childName [" + childName + "]\n"
- + "\t non-empty parameters [" + (parameters != null) + "]\n"
- );
+ getLogger().debug("DefaultCreator::create() called with\n" + "\t initialContentsURI ["
+ + initialContentsURI + "]\n" + "\t document [" + document + "]\n"
+ + "\t non-empty parameters [" + (parameters != null) + "]\n");
// Read initial contents as DOM
if (getLogger().isDebugEnabled())
- getLogger().debug("DefaultCreator::create(), ready to read initial contents from URI [" + initialContentsURI + "]");
+ getLogger().debug("DefaultCreator::create(), ready to read initial contents from URI ["
+ + initialContentsURI + "]");
- Document doc = null;
+ Document xmlDoc = null;
try {
- doc = SourceUtil.readDOM(initialContentsURI, manager);
- }
- catch (Exception e) {
- throw new DocumentException("could not read document at location [ " + initialContentsURI + "]", e);
+ xmlDoc = SourceUtil.readDOM(initialContentsURI, manager);
+ } catch (Exception e) {
+ throw new DocumentException("could not read document at location [ "
+ + initialContentsURI + "]", e);
}
if (getLogger().isDebugEnabled())
getLogger().debug("transform sample file: ");
// transform the xml if needed
- transformXML(doc, childId, childName, parameters);
+ transformXML(xmlDoc, document, parameters);
- // write the document
+ // write the document
try {
- SourceUtil.writeDOM(doc, newURI, manager);
+ SourceUtil.writeDOM(xmlDoc, document.getSourceURI(), manager);
+ } catch (Exception e) {
+ throw new DocumentBuildException("could not write document [" + document
+ + "], exception " + e.toString(), e);
}
- catch (Exception e) {
- throw new DocumentBuildException("could not write document to URI [" + newURI + "], exception " + e.toString(), e);
- }
- }
-
- /**
- * Default implementation: do nothing
- * @see #transformXML(Document, String, String, Map)
- */
- public void transformXML(
- Document doc,
- String childId,
- String childName,
- Map parameters)
- throws Exception {
- // do nothing
}
/**
- * @see org.apache.lenya.cms.authoring.NodeCreatorInterface#getNewDocumentURI(String, String, String, String)
- */
- public abstract String getNewDocumentURI(
- String contentBaseURI,
- String parentId,
- String newId,
- String language);
-
- /**
* Create the language suffix for a file name given a language string
* @param language the language
* @return the suffix for the language dependant file name
@@ -137,4 +109,18 @@
protected String getLanguageSuffix(String language) {
return (language != null) ? "_" + language : "";
}
-}
+
+ /**
+ * Apply some transformation on the newly created document.
+ * @param doc the xml document
+ * @param childId the id of the child
+ * @param childName the name of the child
+ * @param parameters additional parameters that can be used in the transformation
+ * @throws Exception if the transformation fails
+ */
+ protected void transformXML(Document doc,
+ org.apache.lenya.cms.publication.Document document,
+ Map parameters) throws Exception {
+ }
+
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/cms/authoring/NodeCreatorInterface.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/authoring/NodeCreatorInterface.java?rev=170732&r1=170731&r2=170732&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/authoring/NodeCreatorInterface.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/authoring/NodeCreatorInterface.java Wed May 18 03:09:10 2005
@@ -22,7 +22,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
-import org.w3c.dom.Document;
/**
* Interface for creation of nodes in the document hierarchy
@@ -38,9 +37,10 @@
* @param logger A logger
*/
void init(Configuration doctypeConf, ServiceManager manager, Logger logger);
+
/**
* Describe <code>getChildName</code> method here.
- *
+ *
* @param childname a <code>String</code> value
* @return a <code>String</code> value
* @exception Exception if an error occurs
@@ -49,52 +49,15 @@
/**
* Create a physical representation for a new document.
- *
+ *
* @param initialContentsURI the URI where initial content for this document can be found.
- * @param newURI the URI under which the new node is to be created. Can be retrieved via getNewDocumentURI()
- * @param childId the document id of the new document
- * @param childName the name of the new document.
+ * @param document The document to create.
* @param parameters additional parameters that can be used when creating the document
*
- * @see #getNewDocumentURI(String,String,String,String)
* @exception Exception if an error occurs
*/
- void create(
- String initialContentsURI,
- String newURI,
- String childId,
- String childName,
- Map parameters)
- throws Exception;
-
- /**
- * Get the URI of a new document
- * @param contentBaseURI the base URI of where contents are found
- * @param parentId the id of the parent, if known
- * @param newId the id of the new document
- * @param language for which the document is created
- * @return the new URI
- */
- String getNewDocumentURI(
- String contentBaseURI,
- String parentId,
- String newId,
- String language);
-
- /**
- * Apply some transformation on the newly created document.
- * @param doc the xml document
- * @param childId the id of the child
- * @param childName the name of the child
- * @param parameters additional parameters that can be used in the transformation
- * @throws Exception if the transformation fails
- */
- void transformXML(
- Document doc,
- String childId,
- String childName,
- Map parameters)
- throws Exception;
-
+ void create(String initialContentsURI,
+ org.apache.lenya.cms.publication.Document document,
+ Map parameters) throws Exception;
-}
+}
\ No newline at end of file
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=170732&r1=170731&r2=170732&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 03:09:10 2005
@@ -62,28 +62,19 @@
* 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 document The document to add.
* @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 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(DocumentIdentityMap map,
- Publication publication,
- String area,
- String newDocumentId,
- String language,
+ void add(Document document,
DocumentType documentType,
String navigationTitle,
String initialContentsURI,
@@ -124,27 +115,13 @@
* exist.
*/
void copy(DocumentSet sources, DocumentSet destinations) 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 publication The publication.
- * @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,
- Publication publication,
- String area,
- Document parent,
- String nodeId,
- String language) throws DocumentBuildException, DocumentException;
+ * Checks if a document name is valid.
+ * @param documentName The document name.
+ * @return A boolean value.
+ */
+ boolean isValidDocumentName(String documentName);
/**
* Moves a document to another location, incl. all requiring documents. If a sitetree is used,
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=170732&r1=170731&r2=170732&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 03:09:10 2005
@@ -16,9 +16,7 @@
*/
package org.apache.lenya.cms.publication;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.context.Context;
@@ -56,39 +54,27 @@
* 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(DocumentIdentityMap,
- * Publication,String,String,String,DocumentType,String,String,Map)
+ * @see DocumentManager#add(Document, DocumentType, String, String, Map)
* @see org.apache.lenya.cms.authoring.NodeCreatorInterface
* @see org.apache.lenya.cms.publication.DocumentBuilder
*/
- public Document add(DocumentIdentityMap map,
- Publication publication,
- String area,
- String newDocumentId,
- String language,
+ public void add(Document document,
DocumentType documentType,
String navigationTitle,
String initialContentsURI,
Map parameters) throws DocumentBuildException, PublicationException {
- if (getLogger().isDebugEnabled())
- 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");
+ 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.
*/
- if (getLogger().isDebugEnabled())
- getLogger().debug("DocumentManagerImpl::add() creating Document instance");
- 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");
// Call the creator for the document type to physically create a document of this type
try {
@@ -103,41 +89,14 @@
// look up creator for documents of this type
NodeCreatorInterface creator = documentType.getCreator();
- // the concrete creator implementation decides
- // where, relative to content base (and potentially to the parent
- // as well), the new document shall be created
- String contentBaseURI = publication.getContentURI(area);
-
- 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
- // publication dependant; this is handled through the creator
- // for that type in that publication.
- // Therefore, we must ask the creator what this URI is
- // and set it in the document.
- newDocument.setSourceURI(newDocumentURI);
-
// now that the source is determined, lock involved nodes
- Transactionable[] nodes = newDocument.getRepositoryNodes();
+ Transactionable[] nodes = document.getRepositoryNodes();
for (int i = 0; i < nodes.length; i++) {
nodes[i].lock();
}
//
- creator.create(initialContentsURI,
- newDocumentURI,
- newDocumentNodeName,
- navigationTitle,
- parameters);
+ creator.create(initialContentsURI, document, parameters);
} catch (Exception e) {
throw new DocumentBuildException("call to creator for new document failed", e);
}
@@ -146,12 +105,10 @@
Map lenyaMetaData = new HashMap(2);
lenyaMetaData.put(LenyaMetaData.ELEMENT_RESOURCE_TYPE, documentType.getName());
lenyaMetaData.put(LenyaMetaData.ELEMENT_CONTENT_TYPE, "xml");
- newDocument.getMetaDataManager().setLenyaMetaData(lenyaMetaData);
+ document.getMetaDataManager().setLenyaMetaData(lenyaMetaData);
// Notify site manager about new document
- addToSiteManager(newDocument, navigationTitle);
-
- return newDocument;
+ addToSiteManager(document, navigationTitle);
}
private void addToSiteManager(Document document, String navigationTitle)
@@ -346,41 +303,10 @@
}
/**
- * @see org.apache.lenya.cms.publication.DocumentManager#canCreate(org.apache.lenya.cms.publication.DocumentIdentityMap,
- * org.apache.lenya.cms.publication.Publication, java.lang.String,
- * org.apache.lenya.cms.publication.Document, java.lang.String, java.lang.String)
+ * @see org.apache.lenya.cms.publication.DocumentManager#isValidDocumentName(java.lang.String)
*/
- public String[] canCreate(DocumentIdentityMap identityMap,
- Publication publication,
- 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.isValidDocumentId(newDocumentId)) {
- Document newDocument = identityMap.get(publication, 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()]);
+ public boolean isValidDocumentName(String documentName) {
+ return !documentName.equals("") && documentName.indexOf("/") < 0;
}
/**
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?rev=170732&r1=170731&r2=170732&view=diff
==============================================================================
--- 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 Wed May 18 03:09:10 2005
@@ -127,17 +127,22 @@
DocumentIdentityMap identityMap = getSourceDocument().getIdentityMap();
String nodeId = getParameterAsString(NODE_ID);
- Document parent = identityMap.getParent(getSourceDocument());
DocumentManager documentManager = null;
try {
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- String[] messages = documentManager.canCreate(identityMap,
- getSourceDocument().getPublication(),
- getSourceDocument().getArea(),
- parent,
- nodeId,
- getSourceDocument().getLanguage());
- addErrorMessages(messages);
+ if (!documentManager.isValidDocumentName(nodeId)) {
+ addErrorMessage("The document ID is not valid.");
+ } else {
+ Document parent = identityMap.getParent(getSourceDocument());
+ Publication publication = getSourceDocument().getPublication();
+ Document document = identityMap.get(publication,
+ getSourceDocument().getArea(),
+ parent.getId() + "/" + nodeId,
+ getSourceDocument().getLanguage());
+ if (document.exists()) {
+ addErrorMessage("The document does already exist.");
+ }
+ }
} finally {
if (documentManager != null) {
this.manager.release(documentManager);
@@ -232,4 +237,4 @@
return newDocumentId;
}
-}
+}
\ 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=170732&r1=170731&r2=170732&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 03:09:10 2005
@@ -107,7 +107,6 @@
// create new document
DocumentManager documentManager = null;
- Document newDocument = null;
DocumentTypeBuilder documentTypeBuilder = null;
try {
@@ -118,16 +117,24 @@
.buildDocumentType(getDocumentTypeName(), getPublication());
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- newDocument = documentManager.add((DocumentIdentityMap) getUnitOfWork()
- .getIdentityMap(),
- getPublication(),
- getSourceDocument().getArea(),
+
+ DocumentIdentityMap map = (DocumentIdentityMap) getUnitOfWork().getIdentityMap();
+ Document document = map.get(getPublication(),
+ getArea(),
getNewDocumentId(),
- getParameterAsString(LANGUAGE),
+ getParameterAsString(LANGUAGE));
+
+ documentManager.add(document,
documentType,
getParameterAsString(DublinCore.ELEMENT_TITLE),
getInitialContentsURI(),
null);
+
+ setMetaData(document);
+
+ // the location to navigate to after completion of usecase
+ setTargetURL(document.getCanonicalWebappURL());
+
} finally {
if (documentManager != null) {
this.manager.release(documentManager);
@@ -136,12 +143,6 @@
this.manager.release(documentTypeBuilder);
}
}
-
- // set dublin core meta-data
- setMetaData(newDocument);
-
- // the location to navigate to after completion of usecase
- setTargetURL(newDocument.getCanonicalWebappURL());
}
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=170732&r1=170731&r2=170732&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 03:09:10 2005
@@ -19,6 +19,7 @@
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;
/**
* Usecase to create a document.
@@ -53,19 +54,20 @@
protected void doCheckExecutionConditions() throws Exception {
super.doCheckExecutionConditions();
- String nodeId = getParameterAsString(DOCUMENT_ID);
- Document parent = getSourceDocument();
+ String documentName = getParameterAsString(DOCUMENT_ID);
String language = getParameterAsString(LANGUAGE);
DocumentManager documentManager = null;
try {
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- String[] messages = documentManager.canCreate(getDocumentIdentityMap(),
- parent.getPublication(),
- getArea(),
- parent,
- nodeId,
+ Document parent = getSourceDocument();
+ Publication publication = getSourceDocument().getPublication();
+ Document document = getSourceDocument().getIdentityMap().get(publication,
+ getSourceDocument().getArea(),
+ parent.getId() + "/" + documentName,
language);
- addErrorMessages(messages);
+ if (document.exists()) {
+ addErrorMessage("The document does already exist.");
+ }
} finally {
if (documentManager != null) {
this.manager.release(documentManager);
@@ -88,7 +90,8 @@
}
/**
- * In this usecase, the parent document is simply the source document the usecase was invoked upon.
+ * In this usecase, the parent document is simply the source document the usecase was invoked
+ * upon.
* @see Create#getParentDocument()
*/
protected Document getParentDocument() throws DocumentBuildException {
@@ -103,11 +106,10 @@
return null;
}
-
/**
* @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
*/
protected String getDocumentTypeName() {
return getParameterAsString(DOCUMENT_TYPE);
}
-}
+}
\ No newline at end of file
Modified: lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/authoring/NewBlogEntryCreator.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/authoring/NewBlogEntryCreator.java?rev=170732&r1=170731&r2=170732&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/authoring/NewBlogEntryCreator.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/blog/java/src/org/apache/lenya/cms/authoring/NewBlogEntryCreator.java Wed May 18 03:09:10 2005
@@ -17,10 +17,6 @@
package org.apache.lenya.cms.authoring;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceManager;
-
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -39,131 +35,83 @@
*/
public class NewBlogEntryCreator extends DefaultBranchCreator {
- private String year;
- private String month;
- private String day;
- private Date date;
-
/**
- * @see org.apache.lenya.cms.authoring.DefaultBranchCreator#init(Configuration, ServiceManager, Logger)
+ * @see org.apache.lenya.cms.authoring.DefaultCreator#transformXML(org.w3c.dom.Document,
+ * org.apache.lenya.cms.publication.Document, java.util.Map)
*/
- public void init(Configuration conf, ServiceManager _manager, Logger _logger) {
- super.init(conf, _manager, _logger);
+ public void transformXML(Document doc,
+ org.apache.lenya.cms.publication.Document document,
+ Map parameters) throws Exception {
+
+ // sanity check: blog entry creation depends on certain parameters
+ if (parameters == null)
+ throw new IllegalArgumentException("parameters may not be null for blog entry creation");
- DateFormat fmtyyyy = new SimpleDateFormat("yyyy");
- DateFormat fmtMM = new SimpleDateFormat("MM");
- DateFormat fmtdd = new SimpleDateFormat("dd");
- date = new Date();
-
- year = fmtyyyy.format(date);
- month = fmtMM.format(date);
- day = fmtdd.format(date);
+ Element parent = doc.getDocumentElement();
if (getLogger().isDebugEnabled())
- getLogger().debug("NewBlogEntryCreator.init(): " + year + "/" + month + "/" + day);
- }
+ getLogger().debug("NewBlogEntryCreator.transformXML(): " + document);
- /**
- * The blog publication has a specific site structuring:
- * it uses the filesystem hierarchy to group nodes by date.
- * In particular, the new URI of a blog entry is not dependent upon a "parent", so parameter <code>parentId</code> is unused.
- *
- * <p>Example structuring of blog entries:</p>
- * <ul>
- * <li>2004</li>
- * <li>2005</li>
- * <ul>
- * <li>01</li>
- * <li>02</li>
- * <ul>
- * <li>23</li>
- * <li>24</li>
- * <ul>
- * <li>article-one</li>
- * <li>article-two</li>
- * </ul>
- * </ul>
- * </ul>
- * </ul>
- *
- * @see org.apache.lenya.cms.authoring.NodeCreatorInterface#getNewDocumentURI(String, String, String, String)
- */
- public String getNewDocumentURI(
- String contentBaseURI,
- String parentId,
- String newId,
- String language) {
- return
- contentBaseURI
- + "/"
- + "entries"
- + "/"
- + year
- + "/"
- + month
- + "/"
- + day
- + "/"
- + newId
- + "/"
- + "index.xml";
- }
+ String[] steps = document.getId().split("/");
+ String nodeId = steps[5];
- /**
- * @see #transformXML(Document, String, String, Map)
- */
- public void transformXML(Document doc, String childId, String childName, Map parameters) throws Exception {
-
- // sanity check: blog entry creation depends on certain parameters
- if (parameters == null)
- throw new IllegalArgumentException("parameters may not be null for blog entry creation");
-
- Element parent = doc.getDocumentElement();
-
- if (getLogger().isDebugEnabled())
- getLogger().debug("NewBlogEntryCreator.transformXML(): " + childId);
-
- // Replace id
- Element element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'id']");
- DocumentHelper.setSimpleElementText(element, "tag:bob.blog," + year + ":" + month + ":" + day + ":" + childId);
-
- // Replace title
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'title']");
- DocumentHelper.setSimpleElementText(element, (String)parameters.get("title"));
-
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'link']");
- element.setAttribute("rel","alternate");
- element.setAttribute("href","http://bob.blog");
- element.setAttribute("type","text/xml");
+ // Replace id
+ Element element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'id']");
+
+ String year = steps[2];
+ String month = steps[3];
+ String day = steps[4];
+
+ DocumentHelper.setSimpleElementText(element, "tag:bob.blog," + year + ":" + month + ":"
+ + day + ":" + nodeId);
+
+ // Replace title
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'title']");
+ DocumentHelper.setSimpleElementText(element, (String) parameters.get("title"));
+
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'link']");
+ element.setAttribute("rel", "alternate");
+ element.setAttribute("href", "http://bob.blog");
+ element.setAttribute("type", "text/xml");
// Replace Summary
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'summary']");
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'summary']");
DocumentHelper.setSimpleElementText(element, "Summary");
-
// Replace author
Identity identity = (Identity) parameters.get(Identity.class.getName());
-
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'author']/*[local-name() = 'name']");
-
+
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'author']/*[local-name() = 'name']");
+
if (element == null) {
throw new RuntimeException("Element entry/author/name not found.");
}
-
+
DocumentHelper.setSimpleElementText(element, identity.getUser().getId());
- // Replace date created (and issued and modified, FIXME: issued should be set during first time publishing, modified should be set during re-publishing)
+ // Replace date created (and issued and modified, FIXME: issued should be set during first
+ // time publishing, modified should be set during re-publishing)
DateFormat datefmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
DateFormat ofsfmt = new SimpleDateFormat("Z");
+ Date date = new Date();
String dateofs = ofsfmt.format(date);
- String datestr = datefmt.format(date) + dateofs.substring(0, 3) + ":" + dateofs.substring(3, 5);
+ String datestr = datefmt.format(date) + dateofs.substring(0, 3) + ":"
+ + dateofs.substring(3, 5);
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'created']");
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'created']");
DocumentHelper.setSimpleElementText(element, datestr);
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'issued']");
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'issued']");
DocumentHelper.setSimpleElementText(element, datestr);
- element = (Element) XPathAPI.selectSingleNode(parent, "/*[local-name() = 'entry']/*[local-name() = 'modified']");
+ element = (Element) XPathAPI.selectSingleNode(parent,
+ "/*[local-name() = 'entry']/*[local-name() = 'modified']");
DocumentHelper.setSimpleElementText(element, datestr);
}
-}
+}
\ 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=170732&r1=170731&r2=170732&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 03:09:10 2005
@@ -16,6 +16,9 @@
*/
package org.apache.lenya.cms.site.usecases;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Map;
import java.util.HashMap;
@@ -80,7 +83,6 @@
super.doExecute();
// prepare values necessary for blog entry creation
- String documentId = "/" + getNewDocumentName();
Document parent = getSourceDocument();
String language = parent.getPublication().getDefaultLanguage();
Map objectModel = ContextHelper.getObjectModel(getContext());
@@ -104,11 +106,14 @@
.buildDocumentType(getDocumentTypeName(), getSourceDocument().getPublication());
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- documentManager.add((DocumentIdentityMap) getUnitOfWork().getIdentityMap(),
- getSourceDocument().getPublication(),
- getSourceDocument().getArea(),
- documentId,
- language,
+
+ DocumentIdentityMap map = (DocumentIdentityMap) getUnitOfWork().getIdentityMap();
+
+ String documentId = getDocumentID();
+ Document document = map.get(getSourceDocument().getPublication(), getSourceDocument()
+ .getArea(), documentId, language);
+
+ documentManager.add(document,
documentType,
getParameterAsString(DublinCore.ELEMENT_TITLE),
null,
@@ -121,6 +126,46 @@
this.manager.release(documentTypeBuilder);
}
}
+ }
+
+ /**
+ * The blog publication has a specific site structuring: it groups nodes by date.
+ *
+ * <p>
+ * Example structuring of blog entries:
+ * </p>
+ * <ul>
+ * <li>2004</li>
+ * <li>2005</li>
+ * <ul>
+ * <li>01</li>
+ * <li>02</li>
+ * <ul>
+ * <li>23</li>
+ * <li>24</li>
+ * <ul>
+ * <li>article-one</li>
+ * <li>article-two</li>
+ * </ul>
+ * </ul>
+ * </ul>
+ * </ul>
+ *
+ * @return The document ID.
+ */
+ protected String getDocumentID() {
+ DateFormat fmtyyyy = new SimpleDateFormat("yyyy");
+ DateFormat fmtMM = new SimpleDateFormat("MM");
+ DateFormat fmtdd = new SimpleDateFormat("dd");
+ Date date = new Date();
+
+ String year = fmtyyyy.format(date);
+ String month = fmtMM.format(date);
+ String day = fmtdd.format(date);
+
+ String documentId = "/entries/" + year + "/" + month + "/" + day + "/"
+ + getNewDocumentName() + "/index";
+ return documentId;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org