KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > bean > helpers > AntDelegate


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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
17 package org.apache.cocoon.bean.helpers;
18
19 import org.w3c.dom.Document JavaDoc;
20 import org.apache.cocoon.bean.CocoonBean;
21 import org.apache.cocoon.bean.helpers.OutputStreamListener;
22 import org.apache.cocoon.bean.helpers.BeanConfigurator;
23
24 /**
25  * Delegate class for use by the Cocoon Ant task. Allows Ant to run
26  * Cocoon with a single method call that can happily be started with
27  * introspection (due to classpath issues).
28  *
29  * @author <a HREF="mailto:uv@upaya.co.uk">Upayavira</a>
30  * @version CVS $Id: AntDelegate.java 54552 2004-10-11 10:35:06Z upayavira $
31  */

32 public class AntDelegate {
33
34     public static int process(Document JavaDoc xconf, String JavaDoc uriGroup) throws Exception JavaDoc {
35         CocoonBean cocoon = new CocoonBean();
36         OutputStreamListener listener = new OutputStreamListener(System.out);
37         cocoon.addListener(listener);
38         BeanConfigurator.configure(xconf, cocoon, "", uriGroup, listener);
39
40         System.out.println(CocoonBean.getProlog());
41
42         if (!cocoon.isPrecompileOnly() && cocoon.getTargetCount() ==0) {
43             listener.messageGenerated("Please, specify at least one starting URI.");
44             System.exit(1);
45         }
46
47         cocoon.initialize();
48         cocoon.process();
49         cocoon.dispose();
50
51         listener.complete();
52         return listener.isSuccessful() ? 0 : 1;
53     }
54 }
55
56
Popular Tags