001: package org.contineo.util.config;
002:
003: import java.util.Iterator;
004: import java.util.List;
005:
006: import org.jdom.Element;
007:
008: /**
009: * Configurator for the web.xml file
010: *
011: * @author Marco Meschieri
012: * @version $Id:$
013: * @since 3.0
014: */
015: public class WebConfigurator extends XMLBean {
016: public WebConfigurator() {
017: super (System.getProperty("contineo.app.rootdir")
018: + "/WEB-INF/web.xml");
019: }
020:
021: @SuppressWarnings("unchecked")
022: public void setDefaultSkin(String skin) {
023: // Retrieve the <application> element
024: List params = getRootElement().getChildren("context-param",
025: getRootElement().getNamespace());
026: for (Iterator iterator = params.iterator(); iterator.hasNext();) {
027: Element param = (Element) iterator.next();
028: Element name = param.getChild("param-name", param
029: .getNamespace());
030: if ("xkins.defaultSkin".equals(name.getText())) {
031: Element value = param.getChild("param-value", param
032: .getNamespace());
033: value.setText(skin);
034: writeXMLDoc();
035: }
036: }
037: }
038:
039: @SuppressWarnings("unchecked")
040: public void setRelease(String release) {
041: // Retrieve the <application> element
042: List params = getRootElement().getChildren("context-param",
043: getRootElement().getNamespace());
044: for (Iterator iterator = params.iterator(); iterator.hasNext();) {
045: Element param = (Element) iterator.next();
046: Element name = param.getChild("param-name", param
047: .getNamespace());
048: if ("release".equals(name.getText())) {
049: Element value = param.getChild("param-value", param
050: .getNamespace());
051: value.setText(release);
052: writeXMLDoc();
053: }
054: }
055: }
056:
057: public String getRelease() {
058: // Retrieve the <application> element
059: List params = getRootElement().getChildren("context-param",
060: getRootElement().getNamespace());
061: for (Iterator iterator = params.iterator(); iterator.hasNext();) {
062: Element param = (Element) iterator.next();
063: Element name = param.getChild("param-name", param
064: .getNamespace());
065: if ("release".equals(name.getText())) {
066: Element value = param.getChild("param-value", param
067: .getNamespace());
068: return value.getText();
069: }
070: }
071: return "";
072: }
073:
074: @SuppressWarnings("unchecked")
075: public void setStore(String store) {
076: // Retrieve the <application> element
077: List params = getRootElement().getChildren("context-param",
078: getRootElement().getNamespace());
079: for (Iterator iterator = params.iterator(); iterator.hasNext();) {
080: Element param = (Element) iterator.next();
081: Element name = param.getChild("param-name", param
082: .getNamespace());
083: if ("store".equals(name.getText())) {
084: Element value = param.getChild("param-value", param
085: .getNamespace());
086: value.setText(store);
087: writeXMLDoc();
088: }
089: }
090: }
091:
092: public void setDisplayName(String displayName) {
093: // Retrieve the <display-name> element
094: Element element = getRootElement().getChild("display-name",
095: getRootElement().getNamespace());
096: element.setText(displayName);
097: writeXMLDoc();
098: }
099:
100: public String getDisplayName() {
101: // Retrieve the <display-name> element
102: Element element = getRootElement().getChild("display-name",
103: getRootElement().getNamespace());
104: return element.getText();
105: }
106:
107: public void setDescription(String description) {
108: // Retrieve the <display-name> element
109: Element element = getRootElement().getChild("description",
110: getRootElement().getNamespace());
111: element.setText(description);
112: writeXMLDoc();
113: }
114: }
|