01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package org.quickserver.util.xmlreader;
16:
17: import org.apache.commons.digester.*;
18: import java.io.*;
19: import org.quickserver.util.*;
20: import java.util.logging.*;
21:
22: /**
23: * This class reads the xml configuration and gives
24: * QSAdminPluginConfig object.
25: * @author Akshathkumar Shetty
26: * @since 1.3.2
27: */
28: public class PluginConfigReader {
29: private static Logger logger = Logger
30: .getLogger(PluginConfigReader.class.getName());
31:
32: public static QSAdminPluginConfig read(String fileName)
33: throws Exception {
34: File input = new File(fileName);
35: return read(input);
36: }
37:
38: /**
39: * Parses XML config of QSAdmin Plugin
40: */
41: public static QSAdminPluginConfig read(File input) throws Exception {
42: Digester digester = new Digester();
43: digester.setValidating(false);
44:
45: String mainTag = "qsadmin-plugin";
46:
47: digester.addObjectCreate(mainTag, QSAdminPluginConfig.class);
48: digester.addBeanPropertySetter(mainTag + "/name", "name");
49: digester.addBeanPropertySetter(mainTag + "/desc", "desc");
50: digester.addBeanPropertySetter(mainTag + "/type", "type");
51: digester.addBeanPropertySetter(mainTag + "/main-class",
52: "mainClass");
53: digester.addBeanPropertySetter(mainTag + "/active", "active");
54:
55: logger.fine("Loading Plugin config from xml file : "
56: + input.getAbsolutePath());
57: QSAdminPluginConfig psc = (QSAdminPluginConfig) digester
58: .parse(input);
59: return psc;
60: }
61: }
|