1 14 15 package org.quickserver.net.qsadmin.gui; 16 17 import org.quickserver.util.MyString; 18 19 24 public class SimpleCommand { 25 private String name; 26 private String target = "server"; 27 private String command; 28 private String desc; 29 private String targetNeeded = "yes"; 30 private String multiLineResponse = "no"; 31 private String version = "1.3"; 33 public String getSimpleCommand() { 34 if(targetNeeded.equals("yes")) 35 return command+" "+target; 36 else 37 return command; 38 } 39 40 public String getName(){ 41 return name; 42 } 43 public void setName(String name) { 44 this.name = name; 45 } 46 47 public String getTarget() { 48 return target; 49 } 50 public void setTarget(String target) { 51 this.target = target; 52 } 53 54 public String getCommand() { 55 return command; 56 } 57 public void setCommand(String command) { 58 this.command = command; 59 } 60 61 public String getDesc() { 62 return desc; 63 } 64 public void setDesc(String desc) { 65 this.desc = desc; 66 } 67 68 public String getTargetNeeded() { 69 return targetNeeded; 70 } 71 public void setTargetNeeded(String targetNeeded) { 72 this.targetNeeded = targetNeeded.toLowerCase(); 73 } 74 75 public String getMultiLineResponse() { 76 return multiLineResponse; 77 } 78 public void setMultiLineResponse(String multiLineResponse) { 79 this.multiLineResponse = multiLineResponse.toLowerCase(); 80 } 81 82 public String getVersion() { 83 return version; 84 } 85 public float getVersionNo() { 86 return getVersionNo(version); 87 } 88 public void setVersion(String version) { 89 if(version!=null && version.equals("")==false) 90 this.version = version.toLowerCase(); 91 } 92 93 public String toXML() { 94 StringBuffer sb = new StringBuffer (); 95 sb.append("<simple-command>\n"); 96 sb.append("\t<name>"+name+"</name>\n"); 97 sb.append("\t<command>"+command+"</command>\n"); 98 if(multiLineResponse!=null && multiLineResponse.equals("yes")) 99 sb.append("\t<multi-line-response>yes</multi-line-response>\n"); 100 else 101 sb.append("\t<multi-line-response>no</multi-line-response>\n"); 102 if(desc!=null) 103 sb.append("\t<desc>"+desc+"</desc>\n"); 104 sb.append("\t<version>"+version+"</version>\n"); 105 if(targetNeeded!=null && targetNeeded.equals("yes")) 106 sb.append("\t<target-needed>yes</target-needed>\n"); 107 else 108 sb.append("\t<target-needed>no</target-needed>\n"); 109 sb.append("</simple-command>\n"); 110 return sb.toString(); 111 } 112 113 private static final float getVersionNo(String ver) { 114 float version = 0; 116 int i = ver.indexOf(" "); if(i == -1) 118 i = ver.length(); 119 ver = ver.substring(0, i); 120 121 i = ver.indexOf("."); if(i!=-1) { 123 int j = ver.indexOf(".", i); 124 if(j!=-1) { 125 ver = ver.substring(0, i)+"."+ 126 MyString.replaceAll(ver.substring(i+1), ".", ""); 127 } 128 } 129 130 try { 131 version = Float.parseFloat(ver); 132 } catch(NumberFormatException e) { 133 throw new RuntimeException ("Corrupt QuickServer"); 134 } 135 return version; 136 } 137 } 138 | Popular Tags |