KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.cocoon.components.flow.util.PipelineUtil;
19 import org.apache.cocoon.components.LifecycleHelper;
20
21 import java.util.Map JavaDoc;
22 import java.io.OutputStream JavaDoc;
23
24 public class PublicationProcessTaskUtil {
25     public static String JavaDoc getFileName(String JavaDoc path) {
26         int position = path.lastIndexOf('/');
27         if (position == -1) {
28             return path;
29         } else {
30             return path.substring(position + 1);
31         }
32     }
33
34     public static void executePipeline(String JavaDoc pipe, Map JavaDoc viewData, OutputStream JavaDoc os, PublicationContext context) throws Exception JavaDoc {
35         PipelineUtil pipelineUtil = new PipelineUtil();
36         try {
37             LifecycleHelper.setupComponent(pipelineUtil, null, context.getAvalonContext(), context.getServiceManager(), null, false);
38             pipelineUtil.processToStream(pipe, viewData, os);
39         } finally {
40             LifecycleHelper.dispose(pipelineUtil);
41         }
42     }
43
44     public static String JavaDoc getRequiredAttribute(Map JavaDoc attributes, String JavaDoc attrName, String JavaDoc processTaskName) throws Exception JavaDoc {
45         String JavaDoc value = (String JavaDoc)attributes.get(attrName);
46         if (value == null || value.trim().length() == 0) {
47             throw new Exception JavaDoc("Missing attribute for process task " + processTaskName + ": " + attrName);
48         }
49         return value;
50     }
51 }
52
Popular Tags