1 23 24 package org.enhydra.xml.xmlc.misc; 25 26 import java.io.IOException ; 27 import java.util.ArrayList ; 28 29 31 34 final class SSIDirective { 35 38 class Arg { 39 40 public final String name; 41 42 43 public final String value; 44 45 48 public Arg(String argName, 49 String argValue) { 50 name = argName; 51 value = argValue; 52 } 53 } 54 55 56 private final String fCmd; 57 58 59 private final String fSystemId; 60 61 65 private ArrayList fArgs = new ArrayList (); 66 67 70 public SSIDirective(String cmd, 71 String systemId) { 72 fCmd = cmd; 73 fSystemId = systemId; 74 } 75 76 79 public void addArg(String name, 80 String value) { 81 fArgs.add(new Arg(name, value)); 82 } 83 84 87 public String getCmd() { 88 return fCmd; 89 } 90 91 94 public String getSystemId() { 95 return fSystemId; 96 } 97 98 101 public int getNumArgs() { 102 return fArgs.size(); 103 } 104 105 108 public String getArgName(int idx) { 109 return ((Arg)fArgs.get(idx)).name; 110 } 111 112 115 public String getArgValue(int idx) { 116 return ((Arg)fArgs.get(idx)).value; 117 } 118 119 122 public String getArgValue(String name) { 123 int len = fArgs.size(); 124 for (int i = 0; i < len; i++) { 125 if (name.equals(getArgName(i))) { 126 return getArgValue(i); 127 } 128 } 129 return null; 130 } 131 132 135 public void validateArgumentNames(String [] validNames) throws IOException { 136 int len = fArgs.size(); 137 for (int i = 0; i < len; i++) { 138 String name = getArgName(i); 139 boolean valid = false; 140 for (int j = 0; j < validNames.length; j++) { 141 if (validNames[j].equals(name)) { 142 valid = true; 143 break; 144 } 145 } 146 if (!valid) { 147 throw new IOException ("invalid argument name for SSI " 148 + fCmd + " command \"" 149 + name + "\": " + fSystemId); 150 } 151 } 152 } 153 154 157 public String toString() { 158 StringBuffer buf = new StringBuffer (1024); 159 buf.append("cmd=`"); 160 buf.append(fCmd); 161 buf.append("' systemId="); 162 buf.append(fSystemId); 163 buf.append(" args:"); 164 int len = fArgs.size(); 165 for (int i = 0; i < len; i++) { 166 buf.append(" "); 167 buf.append(getArgName(i)); 168 buf.append("=`"); 169 buf.append(getArgValue(i)); 170 buf.append("'"); 171 } 172 return buf.toString(); 173 } 174 } 175 | Popular Tags |