KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > tools > PortalToolBuilder


1 /*
2  * Copyright 1999-2005 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 package org.apache.cocoon.portal.tools;
17
18 import java.io.File JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.avalon.framework.configuration.ConfigurationException;
25 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
26 import org.xml.sax.SAXException JavaDoc;
27
28 /**
29  *
30  * @version CVS $Id: PortalToolBuilder.java 149055 2005-01-29 18:21:34Z cziegeler $
31  */

32 public class PortalToolBuilder {
33     
34     public PortalTool buildTool(File JavaDoc confFile, String JavaDoc rootDir, String JavaDoc pluginDir, String JavaDoc i18nDir) {
35         PortalTool pTool = null;
36         try {
37             DefaultConfigurationBuilder dcb = new DefaultConfigurationBuilder();
38             Configuration conf = dcb.buildFromFile(confFile);
39             String JavaDoc toolName = conf.getAttribute("name");
40             String JavaDoc toolId = conf.getAttribute("id");
41             HashMap JavaDoc functions = new HashMap JavaDoc();
42             ArrayList JavaDoc i18n = new ArrayList JavaDoc();
43              
44             Configuration[] funcs = conf.getChild("functions").getChildren();
45             for(int i = 0; i < funcs.length; i++) {
46                 PortalToolFunction ptf = new PortalToolFunction();
47                 ptf.setName(funcs[i].getAttribute("name"));
48                 ptf.setFunction(funcs[i].getAttribute("pipeline"));
49                 ptf.setId(funcs[i].getAttribute("id"));
50                 ptf.setInternal(new Boolean JavaDoc(funcs[i].getAttribute("internal", "false")).booleanValue());
51                 functions.put(ptf.getName(), ptf);
52             }
53             Configuration[] i18ns = conf.getChild("i18n").getChildren();
54             for(int i = 0; i < i18ns.length; i++) {
55                 PortalToolCatalogue ptc = new PortalToolCatalogue();
56                 ptc.setId(i18ns[i].getAttribute("id"));
57                 ptc.setLocation(rootDir + pluginDir + toolId + "/" + i18nDir);
58                 ptc.setName(i18ns[i].getAttribute("name"));
59                 i18n.add(ptc);
60             }
61             pTool = new PortalTool(toolName, toolId, functions, i18n);
62         } catch (ConfigurationException ece) {
63             // TODO
64
} catch (SAXException JavaDoc esax) {
65             // TODO
66
} catch (IOException JavaDoc eio) {
67             // TODO
68
}
69         return pTool;
70     }
71    
72 }
73
Popular Tags