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/04/21 14:18:15 UTC
svn commit: r164044 - in /lenya/trunk/src: java/org/apache/lenya/
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/site/usecases/
Author: jwkaltz
Date: Thu Apr 21 05:18:15 2005
New Revision: 164044
URL: http://svn.apache.org/viewcvs?rev=164044&view=rev
Log:
Made DocumentTypeBuilder a service.
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java
lenya/trunk/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.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/java/org/apache/lenya/lenya.roles
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/DefaultCreator.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java?rev=164044&r1=164043&r2=164044&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 Thu Apr 21 05:18:15 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.
@@ -29,58 +29,27 @@
import org.w3c.dom.Document;
/**
- * The default creator
+ * The default creator for documents
*/
-public class DefaultCreator implements ParentChildCreatorInterface {
- private static Logger log = Logger.getLogger(DefaultCreator.class);
- /**
- * <code>RESOURCE_NAME</code> The resource name parameter
- */
- public static final String RESOURCE_NAME = "resource-name";
- /**
- * <code>RESOURCE_META_NAME</code> The resource meta name parameter
- */
- public static final String RESOURCE_META_NAME = "resource-meta-name";
- /**
- * <code>SAMPLE_NAME</code> The sample name parameter
- */
- public static final String SAMPLE_NAME = "sample-name";
- /**
- * <code>SAMPLE_META_NAME</code> The sample meta name parameter
- */
- public static final String SAMPLE_META_NAME = "sample-meta-name";
+public class DefaultCreator implements ParentChildCreatorInterface {
+
+ // FIXME: remove direct reference to log4j. A logger could be passed
+ // to init(), as DocumentTypeBuilder is a service. However, whoever
+ // creates blog entries is not yet a service, so that would need
+ // to be switched as well at the same time.
+ private Logger log = Logger.getLogger(DefaultCreator.class);
+
+ public Logger getLogger() {
+ return log;
+ }
- private String resourceName = null;
- private String resourceMetaName = null;
private String sampleResourceName = null;
- private String sampleMetaName = null;
/**
* @see org.apache.lenya.cms.authoring.ParentChildCreatorInterface#init(Configuration)
*/
public void init(Configuration conf) {
- if (conf == null) {
- return;
- }
-
- if (conf.getChild(RESOURCE_NAME, false) != null) {
- this.resourceName = conf.getChild(RESOURCE_NAME).getValue("index.xml");
- }
-
- if (conf.getChild(RESOURCE_META_NAME, false) != null) {
- this.resourceMetaName =
- conf.getChild(RESOURCE_META_NAME).getValue("index-meta.xml");
- }
-
- if (conf.getChild(SAMPLE_NAME, false) != null) {
- this.sampleResourceName =
- conf.getChild(SAMPLE_NAME).getValue("sampleindex.xml");
- }
-
- if (conf.getChild(SAMPLE_META_NAME, false) != null) {
- this.sampleMetaName =
- conf.getChild(SAMPLE_META_NAME).getValue("samplemeta.xml");
- }
+ // nothing to configure in current implementation
}
/**
@@ -119,11 +88,11 @@
}
/**
- * @see org.apache.lenya.cms.authoring.ParentChildCreatorInterface#create(File, File,
+ * @see org.apache.lenya.cms.authoring.ParentChildCreatorInterface#create(String, File,
* String, short, String, String, Map)
*/
public void create(
- File samplesDir,
+ String samplesLocation,
File parentDir,
String childId,
short childType,
@@ -131,29 +100,35 @@
String language,
Map parameters)
throws Exception {
+
// Set filenames
String id = generateTreeId(childId, childType);
String filename = getChildFileName(parentDir, id, language);
String filenameMeta = getChildMetaFileName(parentDir, id, language);
- String doctypeSample = samplesDir + File.separator + this.sampleResourceName;
- String doctypeMeta = samplesDir + File.separator + this.sampleMetaName;
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("DefaultCreator.create(), ready to read sample contents, samplesLocation [" + samplesLocation + "]");
- File sampleFile = new File(doctypeSample);
- if (!sampleFile.exists()) {
- log.error("No such sample file: " + sampleFile + " Have you configured the sample within doctypes.xconf?");
- throw new FileNotFoundException("" + sampleFile);
+ File sampleFile = null;
+ if (samplesLocation != null) {
+ sampleFile = new File(samplesLocation.replace('/', File.separatorChar));
+ if (!sampleFile.exists())
+ throw new FileNotFoundException("Sample file [" + sampleFile + "] not found, make sure you configured it within doctypes.xconf");
}
+ else
+ throw new Exception("sample configuration setup error, samplesLocation is not set - verify your doctypes.xconf");
+
// Read sample file
- log.debug("Read sample file: " + doctypeSample);
+ Document doc = DocumentHelper.readDocument(sampleFile);
- Document doc = DocumentHelper.readDocument(new File(doctypeSample));
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("sample document: " + doc);
- log.debug("sample document: " + doc);
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("transform sample file: ");
// transform the xml if needed
- log.debug("transform sample file: ");
transformXML(doc, id, childType, childName, parameters);
// write the document (create the path, i.e. the parent
@@ -164,25 +139,12 @@
parent.mkdirs();
}
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("write file: " + filename);
+
// Write file
- log.debug("write file: " + filename);
DocumentHelper.writeDocument(doc, new File(filename));
- // now do the same thing for the meta document if the
- // sampleMetaName is specified
- if (this.sampleMetaName != null) {
- doc = DocumentHelper.readDocument(new File(doctypeMeta));
-
- transformMetaXML(doc, id, childType, childName, parameters);
-
- parent = new File(new File(filenameMeta).getParent());
-
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- DocumentHelper.writeDocument(doc, new File(filenameMeta));
- }
}
/**
Modified: lenya/trunk/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java?rev=164044&r1=164043&r2=164044&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java Thu Apr 21 05:18:15 2005
@@ -25,7 +25,7 @@
import org.apache.avalon.framework.configuration.Configuration;
/**
- * Interface for creation of hierarchial documents
+ * Interface for creation of hierarchical documents
*/
public interface ParentChildCreatorInterface {
/**
@@ -85,7 +85,7 @@
/**
* Create a new document.
*
- * @param samplesDir the directory where the template file is located.
+ * @param samplesLocation the location where samples for this document can be found.
* @param parentDir in which directory the document is to be created.
* @param childId the document id of the new document
* @param childType the type of the new document.
@@ -96,7 +96,7 @@
* @exception Exception if an error occurs
*/
void create(
- File samplesDir,
+ String samplesLocation,
File parentDir,
String childId,
short childType,
@@ -104,4 +104,5 @@
String language,
Map parameters)
throws Exception;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?rev=164044&r1=164043&r2=164044&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Thu Apr 21 05:18:15 2005
@@ -99,6 +99,10 @@
this.identityMap = map;
this.language = _language;
setArea(_area);
+
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("DefaultDocument() done building instance with _id [" + _id + "], _language [" + _language + "]");
+
}
/**
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java?rev=164044&r1=164043&r2=164044&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentType.java Thu Apr 21 05:18:15 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.
@@ -19,13 +19,17 @@
package org.apache.lenya.cms.publication;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+
import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
/**
* A document type.
*/
-public class DocumentType {
+public class DocumentType extends AbstractLogEnabled {
/**
* <code>NAMESPACE</code> The doctypes namespace
*/
@@ -38,11 +42,18 @@
/** Creates a new instance of DocumentType
*
* @param _name the name of the document type
- *
+ * @param _sampleContentLocation location of sample contents
*/
- protected DocumentType(String _name) {
+ protected DocumentType(String _name, Logger _logger) {
assert _name != null;
+
+ ContainerUtil.enableLogging(this, _logger);
this.name = _name;
+
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("DocumentType() constructed with"
+ + "\n\t name [" + name + "]"
+ );
}
private String name;
@@ -106,13 +117,6 @@
this.workflowFile = string;
}
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return getName();
- }
-
private String[] linkAttributeXPaths = { };
/**
@@ -131,4 +135,33 @@
public void setLinkAttributeXPaths(String[] xPaths) {
this.linkAttributeXPaths = xPaths;
}
+
+
+ private String sampleContentLocation;
+
+ /**
+ * Returns the location of sample contents for this type
+ * @return A string value.
+ */
+ public String getSampleContentLocation() {
+ return this.sampleContentLocation;
+ }
+
+ /**
+ * Set the location of sample contents for this type
+ * @param _location the location
+ */
+ public void setSampleContentLocation(String _location) {
+ this.sampleContentLocation = _location;
+ }
+
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return getName();
+ }
+
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java?rev=164044&r1=164043&r2=164044&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java Thu Apr 21 05:18:15 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.
@@ -15,73 +15,24 @@
*
*/
-/* $Id$ */
-
package org.apache.lenya.cms.publication;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
-import org.xml.sax.SAXException;
-
/**
- * A builder for document types.
+ * Interface for a builder for document types.
+ *
+ * Note that the term "document types" is deprecated, and
+ * will be replaced by the term "resource types" in the future.
+ *
+ * @version $Id$
*/
-public final class DocumentTypeBuilder {
- /** Creates a new instance of DocumentTypeBuilder */
- private DocumentTypeBuilder() {
- // do nothing
- }
+public interface DocumentTypeBuilder {
/**
- * The default document types configuration directory, relative to the publication directory.
- */
- public static final String DOCTYPE_DIRECTORY = "config/doctypes".replace('/', File.separatorChar);
-
- /**
- * <code>CONFIG_FILE</code> The default document types configuration file, relative to the publication directory.
- */
- public static final String CONFIG_FILE = "doctypes.xconf".replace('/', File.separatorChar);
- /**
- * <code>DOCTYPES_ELEMENT</code> The doctypes element
- */
- public static final String DOCTYPES_ELEMENT = "doctypes";
- /**
- * <code>DOCTYPE_ELEMENT</code> The doctype element
- */
- public static final String DOCTYPE_ELEMENT = "doc";
- /**
- * <code>TYPE_ATTRIBUTE</code> The type attribute
- */
- public static final String TYPE_ATTRIBUTE = "type";
- /**
- * <code>CREATOR_ELEMENT</code> The creator element
- */
- public static final String CREATOR_ELEMENT = "creator";
- /**
- * <code>SRC_ATTRIBUTE</code> The src attribute
+ * The Avalon role.
*/
- public static final String SRC_ATTRIBUTE = "src";
- /**
- * <code>WORKFLOW_ELEMENT</code> The workflow element
- */
- public static final String WORKFLOW_ELEMENT = "workflow";
- /**
- * <code>ELEMENT_REWRITE_ATTRIBUTE</code> The link-attribute element.
- */
- public static final String ELEMENT_REWRITE_ATTRIBUTE = "link-attribute";
- /**
- * <code>ATTRIBUTE_XPATH</code> The xpath attribute.
- */
- public static final String ATTRIBUTE_XPATH = "xpath";
-
+ String ROLE = DocumentTypeBuilder.class.getName();
+
/**
* Builds a document type for a given name.
* @param name A string value.
@@ -89,76 +40,7 @@
* @return A document type object.
* @throws DocumentTypeBuildException When something went wrong.
*/
- public static DocumentType buildDocumentType(String name, Publication publication)
- throws DocumentTypeBuildException {
- DocumentType type = new DocumentType(name);
-
- File configDirectory = new File(publication.getDirectory(), DOCTYPE_DIRECTORY);
- File configFile = new File(configDirectory, CONFIG_FILE);
-
- try {
- Configuration configuration = new DefaultConfigurationBuilder().buildFromFile(configFile);
-
- Configuration[] doctypeConfigurations = configuration.getChildren(DOCTYPE_ELEMENT);
- Configuration doctypeConf = null;
-
- for (int i = 0; i < doctypeConfigurations.length; i++) {
- if (doctypeConfigurations[i].getAttribute(TYPE_ATTRIBUTE).equals(name)) {
- doctypeConf = doctypeConfigurations[i];
- }
- }
-
- if (doctypeConf == null) {
- throw new DocumentTypeBuildException("No definition found for doctype '" + name +
- "'!");
- }
-
- ParentChildCreatorInterface creator;
- Configuration creatorConf = doctypeConf.getChild(CREATOR_ELEMENT, false);
-
- if (creatorConf != null) {
- String creatorClassName = creatorConf.getAttribute(SRC_ATTRIBUTE);
- Class creatorClass = Class.forName(creatorClassName);
- creator = (ParentChildCreatorInterface) creatorClass.newInstance();
- creator.init(creatorConf);
- } else {
- creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
- }
-
- type.setCreator(creator);
-
- Configuration workflowConf = doctypeConf.getChild(WORKFLOW_ELEMENT, false);
-
- if (workflowConf != null) {
- String workflowFileName = workflowConf.getAttribute(SRC_ATTRIBUTE);
- type.setWorkflowFileName(workflowFileName);
- }
-
- Configuration[] rewriteAttributeConfigs = doctypeConf.getChildren(ELEMENT_REWRITE_ATTRIBUTE);
- List xPaths = new ArrayList();
- for (int i = 0; i < rewriteAttributeConfigs.length; i++) {
- String xPath = rewriteAttributeConfigs[i].getAttribute(ATTRIBUTE_XPATH);
- xPaths.add(xPath);
- }
- String[] xPathArray = (String[]) xPaths.toArray(new String[xPaths.size()]);
- type.setLinkAttributeXPaths(xPathArray);
-
- } catch (final ConfigurationException e) {
- throw new DocumentTypeBuildException(e);
- } catch (final SAXException e) {
- throw new DocumentTypeBuildException(e);
- } catch (final IOException e) {
- throw new DocumentTypeBuildException(e);
- } catch (final DocumentTypeBuildException e) {
- throw new DocumentTypeBuildException(e);
- } catch (final ClassNotFoundException e) {
- throw new DocumentTypeBuildException(e);
- } catch (final InstantiationException e) {
- throw new DocumentTypeBuildException(e);
- } catch (final IllegalAccessException e) {
- throw new DocumentTypeBuildException(e);
- }
+ public DocumentType buildDocumentType(String name, Publication publication)
+ throws DocumentTypeBuildException;
- return type;
- }
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java?rev=164044&r1=164043&r2=164044&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java Thu Apr 21 05:18:15 2005
@@ -73,6 +73,8 @@
DocumentType documentType;
URIParameterizer parameterizer = null;
Map map = null;
+ DocumentTypeBuilder documentTypeBuilder = null;
+
try {
parameterizer = (URIParameterizer) this.manager.lookup(URIParameterizer.ROLE);
@@ -95,13 +97,18 @@
if (getLogger().isDebugEnabled())
getLogger().debug("DocumentTypeResolverImpl.resolve() name = [" + name + "], now calling DocumentTypeBuilder");
- documentType = DocumentTypeBuilder.buildDocumentType(name, document.getPublication());
+ documentTypeBuilder = (DocumentTypeBuilder) this.manager.lookup(DocumentTypeBuilder.ROLE);
+
+ documentType = documentTypeBuilder.buildDocumentType(name, document.getPublication());
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (parameterizer != null) {
this.manager.release(parameterizer);
+ }
+ if (documentTypeBuilder != null) {
+ this.manager.release(documentTypeBuilder);
}
}
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=164044&r1=164043&r2=164044&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 Apr 21 05:18:15 2005
@@ -103,6 +103,10 @@
super.doExecute();
Document document = createDocument();
+
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("Create.doExecute() got document instance, now notifying document manager");
+
DocumentManager documentManager = null;
ServiceSelector selector = null;
SiteManager siteManager = null;
@@ -126,7 +130,11 @@
}
}
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("Create.doExecute() done notifying document manager, now setting meta data");
+
setMetaData(document);
+
setTargetURL(document.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=164044&r1=164043&r2=164044&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 Apr 21 05:18:15 2005
@@ -85,6 +85,10 @@
* @see org.apache.lenya.cms.site.usecases.Create#createDocument()
*/
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);
@@ -93,7 +97,7 @@
String language = getParameterAsString(LANGUAGE);
if (getLogger().isDebugEnabled()) {
- getLogger().debug("Creating document");
+ getLogger().debug("createDocument() read parameters:");
getLogger().debug(" Parent document: [" + parent.getId() + "]");
getLogger().debug(" Child document: [" + documentId + "]");
getLogger().debug(" Language: [" + language + "]");
@@ -113,22 +117,31 @@
nodes[i].lock();
}
- DocumentType documentType = DocumentTypeBuilder.buildDocumentType(documentTypeName,
- publication);
+ // create an instance of DocumentType
+ DocumentTypeBuilder documentTypeBuilder = null;
+ DocumentType documentType = null;
+ try {
+ documentTypeBuilder = (DocumentTypeBuilder) this.manager.lookup(DocumentTypeBuilder.ROLE);
- String parentId = parent.getId().substring(1);
- String childId = document.getName();
+ documentType = documentTypeBuilder.buildDocumentType(documentTypeName, publication);
- File doctypesDirectory = new File(publication.getDirectory(),
- DocumentTypeBuilder.DOCTYPE_DIRECTORY);
+ String parentId = parent.getId().substring(1);
+ String childId = document.getName();
- documentType.getCreator().create(new File(doctypesDirectory, "samples"),
+ 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);
+ }
+ }
return document;
}
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=164044&r1=164043&r2=164044&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 Apr 21 05:18:15 2005
@@ -131,27 +131,37 @@
nodes[i].lock();
}
- DocumentType 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();
+ // 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);
+ }
- File doctypesDirectory = new File(publication.getDirectory(),
- DocumentTypeBuilder.DOCTYPE_DIRECTORY);
+ String childId = document.getName();
- documentType.getCreator().create(new File(doctypesDirectory, "samples"),
+ 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);
+ }
+ }
+
return document;
}
@@ -181,4 +191,4 @@
return this.documentTypeName;
}
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?rev=164044&r1=164043&r2=164044&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Thu Apr 21 05:18:15 2005
@@ -118,6 +118,10 @@
shorthand="document-manager"
default-class="org.apache.lenya.cms.publication.DocumentManagerImpl"/>
+ <role name="org.apache.lenya.cms.publication.DocumentTypeBuilder"
+ shorthand="document-type-builder"
+ default-class="org.apache.lenya.cms.publication.DocumentTypeBuilderImpl"/>
+
<role name="org.apache.lenya.cms.publication.ResourcesManager"
shorthand="resources-manager"
default-class="org.apache.lenya.cms.publication.DefaultResourcesManager"/>
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=164044&r1=164043&r2=164044&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 Thu Apr 21 05:18:15 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.
@@ -35,8 +35,9 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.usecase.DocumentUsecase;
+
/**
- * Usecase to create a document.
+ * Usecase to create a Blog entry.
*
* @version $Id$
*/
@@ -105,25 +106,35 @@
documentId,
language);
- DocumentType documentType = DocumentTypeBuilder.buildDocumentType(documentTypeName,
- publication);
-
- String childId = document.getName();
-
- File doctypesDirectory = new File(publication.getDirectory(),
- DocumentTypeBuilder.DOCTYPE_DIRECTORY);
+ // 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 childId = document.getName();
+
+ HashMap allParameters = new HashMap();
+ allParameters.put(Identity.class.getName(), session.getAttribute(Identity.class.getName()));
+ allParameters.put("title", title);
- HashMap allParameters = new HashMap();
- allParameters.put(Identity.class.getName(), session.getAttribute(Identity.class.getName()));
- allParameters.put("title", title);
-
- documentType.getCreator().create(new File(doctypesDirectory, "samples"),
+ documentType.getCreator().create(
+ documentType.getSampleContentLocation(),
new File(publication.getContentDirectory(area), ""),
childId,
ParentChildCreatorInterface.LEAF_NODE,
title,
language,
allParameters);
+ }
+ finally {
+ if (documentTypeBuilder != null) {
+ this.manager.release(documentTypeBuilder);
+ }
+ }
+
}
@@ -133,4 +144,4 @@
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