01: package org.contineo.util.config;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05: import java.util.List;
06:
07: import org.contineo.util.config.XMLBean;
08: import org.jdom.Element;
09:
10: /**
11: * Configurator for the faces-config.xml file
12: *
13: * @author Marco Meschieri
14: * @version $Id:$
15: * @since 3.0
16: */
17: public class FacesConfigurator extends XMLBean {
18:
19: public FacesConfigurator() {
20: super (System.getProperty("contineo.app.rootdir")
21: + "/WEB-INF/faces-config.xml");
22: }
23:
24: @SuppressWarnings("unchecked")
25: public void addBundle(String bundlePath) {
26: // Retrieve the <application> element
27: Element application = getRootElement().getChild("application",
28: getRootElement().getNamespace());
29:
30: // Check if the bundle was already added
31: List bundles = application.getChildren("message-bundle",
32: application.getNamespace());
33: for (Iterator iterator = bundles.iterator(); iterator.hasNext();) {
34: Element element = (Element) iterator.next();
35: if (bundlePath.equals(element.getText()))
36: return;
37: }
38:
39: // The bundle is new and must be appended
40: Element bundle = new Element("message-bundle", application
41: .getNamespace());
42: bundle.setText(bundlePath);
43: application.addContent(bundle);
44: writeXMLDoc();
45: }
46:
47: @SuppressWarnings("unchecked")
48: public List<String> getBundles() {
49: List<String> bundles = new ArrayList<String>();
50:
51: // Retrieve the <application> element
52: Element application = getRootElement().getChild("application",
53: getRootElement().getNamespace());
54:
55: // Iterate over bundles
56: List elements = application.getChildren("message-bundle",
57: application.getNamespace());
58: for (Iterator iterator = elements.iterator(); iterator
59: .hasNext();) {
60: Element element = (Element) iterator.next();
61: bundles.add(element.getText());
62: }
63:
64: return bundles;
65: }
66: }
|