01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.tools;
18:
19: import java.io.File;
20: import java.io.IOException;
21: import java.util.ArrayList;
22: import java.util.HashMap;
23:
24: import org.apache.avalon.framework.configuration.Configuration;
25: import org.apache.avalon.framework.configuration.ConfigurationException;
26: import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
27: import org.xml.sax.SAXException;
28:
29: /**
30: *
31: * @version CVS $Id: PortalToolBuilder.java 433543 2006-08-22 06:22:54Z crossley $
32: */
33: public class PortalToolBuilder {
34:
35: public PortalTool buildTool(File confFile, String rootDir,
36: String pluginDir, String i18nDir) {
37: PortalTool pTool = null;
38: try {
39: DefaultConfigurationBuilder dcb = new DefaultConfigurationBuilder();
40: Configuration conf = dcb.buildFromFile(confFile);
41: String toolName = conf.getAttribute("name");
42: String toolId = conf.getAttribute("id");
43: HashMap functions = new HashMap();
44: ArrayList i18n = new ArrayList();
45:
46: Configuration[] funcs = conf.getChild("functions")
47: .getChildren();
48: for (int i = 0; i < funcs.length; i++) {
49: PortalToolFunction ptf = new PortalToolFunction();
50: ptf.setName(funcs[i].getAttribute("name"));
51: ptf.setFunction(funcs[i].getAttribute("pipeline"));
52: ptf.setId(funcs[i].getAttribute("id"));
53: ptf.setInternal(new Boolean(funcs[i].getAttribute(
54: "internal", "false")).booleanValue());
55: functions.put(ptf.getName(), ptf);
56: }
57: Configuration[] i18ns = conf.getChild("i18n").getChildren();
58: for (int i = 0; i < i18ns.length; i++) {
59: PortalToolCatalogue ptc = new PortalToolCatalogue();
60: ptc.setId(i18ns[i].getAttribute("id"));
61: ptc.setLocation(rootDir + pluginDir + toolId + "/"
62: + i18nDir);
63: ptc.setName(i18ns[i].getAttribute("name"));
64: i18n.add(ptc);
65: }
66: pTool = new PortalTool(toolName, toolId, functions, i18n);
67: } catch (ConfigurationException ece) {
68: // TODO
69: } catch (SAXException esax) {
70: // TODO
71: } catch (IOException eio) {
72: // TODO
73: }
74: return pTool;
75: }
76:
77: }
|