1 23 24 package org.enhydra.xml.xmlc.commands.xmlc; 25 26 import org.enhydra.xml.io.ErrorReporter; 27 import org.enhydra.xml.xmlc.XMLCException; 28 import org.enhydra.xml.xmlc.commands.options.Option; 29 import org.enhydra.xml.xmlc.commands.options.OptionSet; 30 import org.enhydra.xml.xmlc.metadata.HTMLAttr; 31 import org.enhydra.xml.xmlc.metadata.HTMLCompatibility; 32 import org.enhydra.xml.xmlc.metadata.HTMLTag; 33 import org.enhydra.xml.xmlc.metadata.HTMLTagSet; 34 import org.enhydra.xml.xmlc.metadata.HTMLTagSetType; 35 import org.enhydra.xml.xmlc.metadata.MetaData; 36 37 40 class HTMLCmdOptions extends BaseCmdOptions { 41 44 private class HTMLEncodingOption extends Option { 45 48 public HTMLEncodingOption() { 49 super("-html:encoding", 1, false, 50 "encoding - Specify the encoding to use when reading a HTML document."); 51 } 52 53 56 public void parse(String [] args, 57 ErrorReporter errorReporter, 58 Object clientData) throws XMLCException { 59 ((MetaData)clientData).getHTMLSection().setEncoding(args[0]); 60 } 61 } 62 63 66 private class HTMLFrameSetOption extends Option { 67 70 public HTMLFrameSetOption() { 71 super("-html:frameset", 0, false, 72 "- Deprecated and ignored."); 73 } 74 75 78 protected void parse(String [] args, 79 ErrorReporter errorReporter, 80 Object clientData) throws XMLCException { 81 errorReporter.warning("The -html:frameset option is deprecated and ignored"); 82 } 83 } 84 85 88 private class HTMLOldClassConstantsOption extends Option { 89 92 public HTMLOldClassConstantsOption() { 93 super("-html:old-class-constants", 0, false, 94 "- Generate old-style, all upper-case class constants"); 95 } 96 97 100 protected void parse(String [] args, 101 ErrorReporter errorReporter, 102 Object clientData) throws XMLCException { 103 HTMLCompatibility compat = ((MetaData)clientData).getHTMLSection().getCreateCompatibility(); 104 compat.setOldClassConstants(true); 105 errorReporter.warning("The " + getName() 106 + " option will be deprecated in a future release, please update your code"); 107 } 108 } 109 110 113 private class HTMLOldNameConstantsOption extends Option { 114 117 public HTMLOldNameConstantsOption() { 118 super("-html:old-name-constants", 0, false, 119 "- Generate old-style, all upper-case name constants"); 120 } 121 122 125 protected void parse(String [] args, 126 ErrorReporter errorReporter, 127 Object clientData) throws XMLCException { 128 HTMLCompatibility compat 129 = ((MetaData)clientData).getHTMLSection().getCreateCompatibility(); 130 compat.setOldNameConstants(true); 131 errorReporter.warning("The " + getName() 132 + " option will be deprecated in a future release, please update your code"); 133 } 134 } 135 136 139 private class HTMLAddTagSetOption extends Option { 140 143 public HTMLAddTagSetOption() { 144 super("-html:addtagset", 1, true, 145 "tagsetname - Add a predefined set of proprietary tags to the list of valid HTML tags."); 146 } 147 148 154 public void parse(String [] args, 155 ErrorReporter errorReporter, 156 Object clientData) throws XMLCException { 157 HTMLTagSet tagSet = ((MetaData)clientData).getHTMLSection().addHTMLTagSet(); 158 try { 159 tagSet.setTagSet(HTMLTagSetType.getType(args[0])); 160 } catch (IllegalArgumentException except) { 161 throw new XMLCException(except.getMessage(), 162 except); 163 } 164 } 165 } 166 167 170 private class HTMLAddTagOption extends Option { 171 174 public HTMLAddTagOption() { 175 super("-html:addtag", 2, true, 176 "tagname flags - Add a proprietary tag to the list of valid HTML tags."); 177 } 178 179 182 private void parseFlags(String flagsStr, 183 HTMLTag tag) throws XMLCException { 184 int startIdx = 0; 186 while (startIdx < flagsStr.length()) { 187 int nextIdx = flagsStr.indexOf(',', startIdx); 188 if (nextIdx < 0) { 189 nextIdx = flagsStr.length(); } 191 String flagStr = flagsStr.substring(startIdx, nextIdx); 192 if (flagStr.equalsIgnoreCase("inline")) { 193 tag.setInline(true); 194 } else if (flagStr.equalsIgnoreCase("block")) { 195 tag.setBlock(true); 196 } else if (flagStr.equalsIgnoreCase("empty")) { 197 tag.setEmpty(true); 198 } else if (flagStr.equalsIgnoreCase("opt")) { 199 tag.setOptclose(true); 200 } else { 201 throw new XMLCException("Invaild flag for " + name 202 + " \"" + flagStr + "\""); 203 } 204 startIdx = nextIdx+1; 205 } 206 } 207 208 214 public void parse(String [] args, 215 ErrorReporter errorReporter, 216 Object clientData) throws XMLCException { 217 HTMLTag tag = ((MetaData)clientData).getHTMLSection().addHTMLTag(); 218 tag.setName(args[0]); 219 parseFlags(args[1], tag); 220 } 221 } 222 223 226 private class HTMLAddAttrOption extends Option { 227 230 public HTMLAddAttrOption() { 231 super("-html:addattr", 1, true, 232 "attrname - Add a proprietary attribute the list of valid HTML attributes."); 233 } 234 235 241 public void parse(String [] args, 242 ErrorReporter errorReporter, 243 Object clientData) throws XMLCException { 244 HTMLAttr attr = ((MetaData)clientData).getHTMLSection().addHTMLAttr(); 245 attr.setName(args[0]); 246 } 247 } 248 249 252 public HTMLCmdOptions(OptionSet optionSet) { 253 super(optionSet); 254 optionSet.addOption(new HTMLFrameSetOption()); 255 optionSet.addOption(new HTMLEncodingOption()); 256 optionSet.addOption(new HTMLAddTagSetOption()); 257 optionSet.addOption(new HTMLAddTagOption()); 258 optionSet.addOption(new HTMLAddAttrOption()); 259 optionSet.addOption(new HTMLOldClassConstantsOption()); 260 optionSet.addOption(new HTMLOldNameConstantsOption()); 261 } 262 } 263 | Popular Tags |