KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > publisher > impl > publicationprocess > PublicationProcessBuilder


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.books.publisher.impl.publicationprocess;
17
18 import org.outerx.daisy.x10Bookpubtype.*;
19 import org.apache.xmlbeans.XmlOptions;
20 import org.apache.xmlbeans.XmlObject;
21 import org.outerj.daisy.books.publisher.impl.util.CustomImplementationHelper;
22
23 import java.util.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25
26 public class PublicationProcessBuilder {
27     public static PublicationProcess build(PublicationProcessDocument.PublicationProcess publicationProcessXml) throws Exception JavaDoc {
28         List JavaDoc tasks = new ArrayList JavaDoc();
29         XmlObject[] tasksXml = publicationProcessXml.selectPath("*");
30         for (int i = 0; i < tasksXml.length; i++) {
31             if (tasksXml[i] instanceof ApplyDocumentTypeStylingDocument.ApplyDocumentTypeStyling) {
32                 ApplyDocumentTypeStylingTask task = new ApplyDocumentTypeStylingTask();
33                 tasks.add(task);
34             } else if (tasksXml[i] instanceof ShiftHeadersDocument.ShiftHeaders) {
35                 ShiftHeadersTask task = new ShiftHeadersTask();
36                 tasks.add(task);
37             } else if (tasksXml[i] instanceof AssembleBookDocument.AssembleBook) {
38                 AssembleBookDocument.AssembleBook taskXml = (AssembleBookDocument.AssembleBook)tasksXml[i];
39                 AssembleBookTask task = new AssembleBookTask(taskXml.getOutput());
40                 tasks.add(task);
41             } else if (tasksXml[i] instanceof VerifyIdsAndLinksDocument.VerifyIdsAndLinks) {
42                 VerifyIdsAndLinksDocument.VerifyIdsAndLinks taskXml = (VerifyIdsAndLinksDocument.VerifyIdsAndLinks)tasksXml[i];
43                 VerifyIdsAndLinksTask task = new VerifyIdsAndLinksTask(taskXml.getInput(), taskXml.getOutput());
44                 tasks.add(task);
45             } else if (tasksXml[i] instanceof ApplyPipelineDocument.ApplyPipeline) {
46                 ApplyPipelineDocument.ApplyPipeline taskXml = (ApplyPipelineDocument.ApplyPipeline)tasksXml[i];
47                 ApplyPipelineTask task = new ApplyPipelineTask(taskXml.getInput(), taskXml.getOutput(), taskXml.getPipe());
48                 tasks.add(task);
49             } else if (tasksXml[i] instanceof AddTocAndListsDocument.AddTocAndLists) {
50                 AddTocAndListsDocument.AddTocAndLists taskXml = (AddTocAndListsDocument.AddTocAndLists)tasksXml[i];
51                 AddTocAndListsTask task = new AddTocAndListsTask(taskXml.getInput(), taskXml.getOutput());
52                 tasks.add(task);
53             } else if (tasksXml[i] instanceof SplitInChunksDocument.SplitInChunks) {
54                 SplitInChunksDocument.SplitInChunks taskXml = (SplitInChunksDocument.SplitInChunks)tasksXml[i];
55                 String JavaDoc publishExtension = taskXml.isSetPublishExtension() ? taskXml.getPublishExtension() : ".html";
56                 String JavaDoc chunkNamePrefix = taskXml.isSetChunkNamePrefix() ? taskXml.getChunkNamePrefix() : "chunk";
57                 SplitInChunksTask task = new SplitInChunksTask(taskXml.getInput(), taskXml.getOutput(),
58                         chunkNamePrefix, taskXml.getFirstChunkName(), publishExtension);
59                 tasks.add(task);
60             } else if (tasksXml[i] instanceof WriteChunksDocument.WriteChunks) {
61                 WriteChunksDocument.WriteChunks taskXml = (WriteChunksDocument.WriteChunks)tasksXml[i];
62                 WriteChunksTask task = new WriteChunksTask(taskXml.getInput(), taskXml.getOutputPrefix(),
63                         taskXml.getChunkFileExtension(), taskXml.getApplyPipeline(), taskXml.getPipelineOutputPrefix(),
64                         taskXml.getChunkAfterPipelineFileExtension());
65                 tasks.add(task);
66             } else if (tasksXml[i] instanceof AddNumberingDocument.AddNumbering) {
67                 AddNumberingDocument.AddNumbering taskXml = (AddNumberingDocument.AddNumbering)tasksXml[i];
68                 NumberingTask task = new NumberingTask(taskXml.getInput(), taskXml.getOutput());
69                 tasks.add(task);
70             } else if (tasksXml[i] instanceof AddSectionTypesDocument.AddSectionTypes) {
71                 AddSectionTypesTask task = new AddSectionTypesTask();
72                 tasks.add(task);
73             } else if (tasksXml[i] instanceof AddIndexDocument.AddIndex) {
74                 AddIndexDocument.AddIndex taskXml = (AddIndexDocument.AddIndex)tasksXml[i];
75                 AddIndexTask task = new AddIndexTask(taskXml.getInput(), taskXml.getOutput());
76                 tasks.add(task);
77             } else if (tasksXml[i] instanceof CopyResourceDocument.CopyResource) {
78                 CopyResourceDocument.CopyResource taskXml = (CopyResourceDocument.CopyResource)tasksXml[i];
79                 CopyResourceTask task = new CopyResourceTask(taskXml.getFrom(), taskXml.getTo());
80                 tasks.add(task);
81             } else if (tasksXml[i] instanceof MakePDFDocument.MakePDF) {
82                 MakePDFDocument.MakePDF taskXml = (MakePDFDocument.MakePDF)tasksXml[i];
83                 MakePdfTask task = new MakePdfTask(taskXml.getInput(), taskXml.getOutput());
84                 tasks.add(task);
85             } else if (tasksXml[i] instanceof GetDocumentPartDocument.GetDocumentPart) {
86                 GetDocumentPartDocument.GetDocumentPart taskXml = (GetDocumentPartDocument.GetDocumentPart)tasksXml[i];
87                 GetDocumentPartTask task = new GetDocumentPartTask(taskXml.getPropertyName(), taskXml.getPropertyOrigin(), taskXml.getPartName(), taskXml.getSaveAs(), taskXml.getSetProperty());
88                 tasks.add(task);
89             } else if (tasksXml[i] instanceof CopyBookInstanceImagesDocument.CopyBookInstanceImages) {
90                 // copyBookInstanceImages task is deprecated in favour of copyBookInstanceResources, but still
91
// here for backwards compatibility
92
CopyBookInstanceImagesDocument.CopyBookInstanceImages taskXml = (CopyBookInstanceImagesDocument.CopyBookInstanceImages)tasksXml[i];
93                 CopyBookInstanceImagesTask task = new CopyBookInstanceImagesTask(taskXml.getInput(), taskXml.getOutput(), taskXml.getTo());
94                 tasks.add(task);
95             } else if (tasksXml[i] instanceof CopyBookInstanceResourcesDocument.CopyBookInstanceResources) {
96                 CopyBookInstanceResourcesDocument.CopyBookInstanceResources taskXml = (CopyBookInstanceResourcesDocument.CopyBookInstanceResources)tasksXml[i];
97                 CopyBookInstanceResourcesTask task = new CopyBookInstanceResourcesTask(taskXml.getInput(), taskXml.getOutput(), taskXml.getTo());
98                 tasks.add(task);
99             } else if (tasksXml[i] instanceof ZipDocument.Zip) {
100                 ZipTask task = new ZipTask();
101                 tasks.add(task);
102             } else if (tasksXml[i] instanceof CustomDocument.Custom) {
103                 CustomDocument.Custom customXml = (CustomDocument.Custom)tasksXml[i];
104                 String JavaDoc className = customXml.getClass1();
105                 Class JavaDoc clazz;
106                 try {
107                     clazz = PublicationProcessBuilder.class.getClassLoader().loadClass(className);
108                 } catch (ClassNotFoundException JavaDoc e) {
109                     throw new Exception JavaDoc("Non-existing class specified in custom publication process task: " + className, e);
110                 }
111                 if (!PublicationProcessTask.class.isAssignableFrom(clazz)) {
112                     throw new Exception JavaDoc("The class specified in the custom publication process task does not implement PublicationProcessTask: " + className);
113                 }
114
115                 PublicationProcessTask customTask = (PublicationProcessTask)CustomImplementationHelper.instantiateComponent(clazz, customXml);
116                 tasks.add(customTask);
117             } else {
118                 XmlOptions xmlOptions = new XmlOptions();
119                 xmlOptions.setSaveOuter();
120                 throw new Exception JavaDoc("Unsupport publication process task element encountered: " + tasksXml[i].xmlText(xmlOptions));
121             }
122         }
123         PublicationProcess publicationProcess = new PublicationProcess((PublicationProcessTask[])tasks.toArray(new PublicationProcessTask[tasks.size()]));
124         return publicationProcess;
125     }
126 }
127
Popular Tags