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.BooleanOption; 29 import org.enhydra.xml.xmlc.commands.options.Option; 30 import org.enhydra.xml.xmlc.commands.options.OptionSet; 31 import org.enhydra.xml.xmlc.metadata.MetaData; 32 import org.enhydra.xml.xmlc.metadata.ParserType; 33 import org.enhydra.xml.xmlc.metadata.XCatalog; 34 35 38 class ParserCmdOptions extends BaseCmdOptions { 39 42 private class ParserOption extends Option { 43 46 public ParserOption() { 47 super("-parser", 1, false, 48 "type - Specify the parser to use (tidy, swing, xerces)."); 49 } 50 51 54 protected void parse(String [] args, 55 ErrorReporter errorReporter, 56 Object clientData) throws XMLCException { 57 ParserType parser; 58 try { 59 parser = ParserType.getType(args[0].toLowerCase()); 60 } catch (IllegalArgumentException except) { 61 throw new XMLCException(except.getMessage(), 62 except); 63 } 64 ((MetaData)clientData).getParser().setName(parser); 65 } 66 } 67 68 71 private class XCatalogOption extends Option { 72 75 public XCatalogOption() { 76 super("-xcatalog", 1, true, 77 "catalog - XCatalog file to resolve external entities."); 78 } 79 80 83 protected void parse(String [] args, 84 ErrorReporter errorReporter, 85 Object clientData) throws XMLCException { 86 XCatalog xCatalog = ((MetaData)clientData).getParser().addXCatalog(); 87 xCatalog.setUrl(args[0]); 88 } 89 } 90 91 94 private class ValidateOption extends BooleanOption { 95 98 public ValidateOption() { 99 super("-validate", 100 "yes|no|true|false - Changes the default document validation mode of the parser"); 101 } 102 103 106 protected void set(boolean value, 107 Object clientData) throws XMLCException { 108 ((MetaData)clientData).getParser().setValidate(value ? Boolean.TRUE : Boolean.FALSE); 109 } 110 } 111 112 115 public ParserCmdOptions(OptionSet optionSet) { 116 super(optionSet); 117 optionSet.addOption(new ParserOption()); 118 optionSet.addOption(new XCatalogOption()); 119 optionSet.addOption(new ValidateOption()); 120 } 121 } 122 | Popular Tags |