1 16 package org.apache.cocoon.portal.tools; 17 18 import java.io.File ; 19 import java.io.IOException ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 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 ; 27 28 32 public class PortalToolBuilder { 33 34 public PortalTool buildTool(File confFile, String rootDir, String pluginDir, String i18nDir) { 35 PortalTool pTool = null; 36 try { 37 DefaultConfigurationBuilder dcb = new DefaultConfigurationBuilder(); 38 Configuration conf = dcb.buildFromFile(confFile); 39 String toolName = conf.getAttribute("name"); 40 String toolId = conf.getAttribute("id"); 41 HashMap functions = new HashMap (); 42 ArrayList i18n = new ArrayList (); 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 (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 } catch (SAXException esax) { 65 } catch (IOException eio) { 67 } 69 return pTool; 70 } 71 72 } 73 | Popular Tags |