001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.util.xmlreader;
016:
017: import java.util.*;
018:
019: /**
020: * This class encapsulate the Application Configuration.
021: * The example xml is <pre>
022: <quickserver>
023: ....
024: <application-configuration>
025: <property>
026: <property-name>FTP_ROOT</property-name>
027: <property-value>c:\</property-value>
028: </property>
029: <property>
030: <property-name>Server Name</property-name>
031: <property-value>My Server</property-value>
032: </property>
033: </application-configuration>
034: ....
035: </quickserver>
036: </pre>
037: * @author Akshathkumar Shetty
038: * @since 1.3.2
039: */
040: public class ApplicationConfiguration extends HashMap {
041: private String promptType = "gui";//OR console
042:
043: /**
044: * Sets the PromptType.
045: * XML Tag: <prompt-type>true</prompt-typ>
046: * Allowed values = <code>gui</code> | <code>console</code>
047: * @see #getPromptType
048: * @since 1.4.5
049: */
050: public void setPromptType(String promptType) {
051: if (promptType != null && promptType.equals("") == false)
052: if (promptType.equals("gui")
053: || promptType.equals("console"))
054: this .promptType = promptType;
055: }
056:
057: /**
058: * Returns the PromptType
059: * @see #setPromptType
060: * @since 1.4.5
061: */
062: public String getPromptType() {
063: return promptType;
064: }
065:
066: /**
067: * Addes the {@link Property} passed to the HashMap
068: */
069: public void addProperty(Property property) {
070: put(property.getName(), property.getValue());
071: }
072:
073: /**
074: * Finds if any {@link Property} is present.
075: * @return <code>null</code> if no Property was found.
076: */
077: public Property findProperty(String name) {
078: String temp = (String) get(name);
079: if (temp != null) {
080: return new Property(name, temp);
081: } else {
082: return null;
083: }
084: }
085:
086: /**
087: * Returns XML config of this class.
088: */
089: public String toXML(String pad) {
090: if (pad == null)
091: pad = "";
092: StringBuffer sb = new StringBuffer();
093: sb.append(pad + "<application-configuration>\n");
094:
095: sb.append(pad + "\t<prompt-type>" + getPromptType()
096: + "</prompt-type>");
097:
098: Iterator iterator = keySet().iterator();
099: while (iterator.hasNext()) {
100: String key = (String) iterator.next();
101: String value = (String) get(key);
102: sb.append(pad + "\t<property>");
103: sb.append(pad + "\t\t<property-name>" + key
104: + "</property-name>\n");
105: sb.append(pad + "\t\t<property-value>" + value
106: + "</property-value>\n");
107: sb.append(pad + "\t</property>\n");
108: }
109: sb.append(pad + "</application-configuration>\n");
110: return sb.toString();
111: }
112: }
|