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 2003/06/06 15:32:16 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication DocumentTypeBuilder.java
andreas 2003/06/06 06:32:16
Modified: src/java/org/apache/lenya/cms/publication
DocumentTypeBuilder.java
Log:
added workflow and creator handling
Revision Changes Path
1.5 +60 -32 cocoon-lenya/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java
Index: DocumentTypeBuilder.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/DocumentTypeBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DocumentTypeBuilder.java 30 May 2003 14:54:55 -0000 1.4
+++ DocumentTypeBuilder.java 6 Jun 2003 13:32:16 -0000 1.5
@@ -8,10 +8,9 @@
import java.io.File;
-import org.apache.lenya.xml.DocumentHelper;
-import org.apache.xpath.XPathAPI;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
/**
* A builder for document types.
@@ -19,24 +18,28 @@
* @author <a href="mailto:andreas.hartmann@wyona.org">Andreas Hartmann</a>
*/
public class DocumentTypeBuilder {
-
+
/** Creates a new instance of DocumentTypeBuilder */
- public DocumentTypeBuilder() {
+ private DocumentTypeBuilder() {
}
-
-
+
/**
* The default document types configuration directory, relative to the publication directory.
*/
- public static final String DOCTYPE_DIRECTORY
- = "config/doctypes".replace('/', File.separatorChar);
+ public static final String DOCTYPE_DIRECTORY =
+ "config/doctypes".replace('/', File.separatorChar);
/*
* The default document types configuration file, relative to the publication directory.
*/
- public static final String CONFIG_FILE
- = "doctypes.xconf".replace('/', File.separatorChar);
-
-
+ public static final String CONFIG_FILE = "doctypes.xconf".replace('/', File.separatorChar);
+
+ public static final String DOCTYPES_ELEMENT = "doctypes";
+ public static final String DOCTYPE_ELEMENT = "doc";
+ public static final String TYPE_ATTRIBUTE = "type";
+ public static final String CREATOR_ELEMENT = "creator";
+ public static final String SRC_ATTRIBUTE = "src";
+ public static final String WORKFLOW_ELEMENT = "workflow";
+
/**
* Builds a document type for a given name.
*
@@ -44,28 +47,53 @@
* @param publication The publication the document type belongs to.
* @return A document type object.
*/
- public DocumentType buildDocumentType(String name, Publication publication)
+ 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 {
- Document document = DocumentHelper.readDocument(configFile);
- DocumentHelper helper = new DocumentHelper();
-
- String xPath = "doctypes/doc[@type = '" + name + "']";
- Node doctypeNode = XPathAPI.selectSingleNode(document, xPath);
-
- // TODO add doctype initialization code
- }
- catch (Exception e) {
+ 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);
+ }
+
+ } catch (Exception e) {
throw new DocumentTypeBuildException(e);
- }
-
- DocumentType type = new DocumentType(name);
+ }
+
return type;
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org