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.net.qsadmin.gui;
016:
017: import org.quickserver.util.MyString;
018:
019: /**
020: * A Simple class that Stores information about QSAdmin Command
021: * that are common to any <code>target</code>
022: * @author Akshathkumar Shetty
023: */
024: public class SimpleCommand {
025: private String name;
026: private String target = "server";
027: private String command;
028: private String desc;
029: private String targetNeeded = "yes";
030: private String multiLineResponse = "no";
031: private String version = "1.3"; //when AdminUI was added
032:
033: public String getSimpleCommand() {
034: if (targetNeeded.equals("yes"))
035: return command + " " + target;
036: else
037: return command;
038: }
039:
040: public String getName() {
041: return name;
042: }
043:
044: public void setName(String name) {
045: this .name = name;
046: }
047:
048: public String getTarget() {
049: return target;
050: }
051:
052: public void setTarget(String target) {
053: this .target = target;
054: }
055:
056: public String getCommand() {
057: return command;
058: }
059:
060: public void setCommand(String command) {
061: this .command = command;
062: }
063:
064: public String getDesc() {
065: return desc;
066: }
067:
068: public void setDesc(String desc) {
069: this .desc = desc;
070: }
071:
072: public String getTargetNeeded() {
073: return targetNeeded;
074: }
075:
076: public void setTargetNeeded(String targetNeeded) {
077: this .targetNeeded = targetNeeded.toLowerCase();
078: }
079:
080: public String getMultiLineResponse() {
081: return multiLineResponse;
082: }
083:
084: public void setMultiLineResponse(String multiLineResponse) {
085: this .multiLineResponse = multiLineResponse.toLowerCase();
086: }
087:
088: public String getVersion() {
089: return version;
090: }
091:
092: public float getVersionNo() {
093: return getVersionNo(version);
094: }
095:
096: public void setVersion(String version) {
097: if (version != null && version.equals("") == false)
098: this .version = version.toLowerCase();
099: }
100:
101: public String toXML() {
102: StringBuffer sb = new StringBuffer();
103: sb.append("<simple-command>\n");
104: sb.append("\t<name>" + name + "</name>\n");
105: sb.append("\t<command>" + command + "</command>\n");
106: if (multiLineResponse != null
107: && multiLineResponse.equals("yes"))
108: sb
109: .append("\t<multi-line-response>yes</multi-line-response>\n");
110: else
111: sb
112: .append("\t<multi-line-response>no</multi-line-response>\n");
113: if (desc != null)
114: sb.append("\t<desc>" + desc + "</desc>\n");
115: sb.append("\t<version>" + version + "</version>\n");
116: if (targetNeeded != null && targetNeeded.equals("yes"))
117: sb.append("\t<target-needed>yes</target-needed>\n");
118: else
119: sb.append("\t<target-needed>no</target-needed>\n");
120: sb.append("</simple-command>\n");
121: return sb.toString();
122: }
123:
124: private static final float getVersionNo(String ver) {
125: //String ver = getVersion();
126: float version = 0;
127: int i = ver.indexOf(" "); //check if beta
128: if (i == -1)
129: i = ver.length();
130: ver = ver.substring(0, i);
131:
132: i = ver.indexOf("."); //check for sub version
133: if (i != -1) {
134: int j = ver.indexOf(".", i);
135: if (j != -1) {
136: ver = ver.substring(0, i)
137: + "."
138: + MyString.replaceAll(ver.substring(i + 1),
139: ".", "");
140: }
141: }
142:
143: try {
144: version = Float.parseFloat(ver);
145: } catch (NumberFormatException e) {
146: throw new RuntimeException("Corrupt QuickServer");
147: }
148: return version;
149: }
150: }
|