Changeset 5073
- Timestamp:
- 04/25/14 14:38:07 (10 years ago)
- Location:
- CMDIValidator/trunk/src/main/java/eu/clarin/cmdi/validator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
CMDIValidator/trunk/src/main/java/eu/clarin/cmdi/validator/CMDIValidatorFactory.java
r5056 r5073 2 2 3 3 import java.io.File; 4 import java.net.MalformedURLException; 4 5 import java.net.URL; 5 6 … … 36 37 37 38 38 private CMDIValidatorFactory(File cacheDirectory, boolean disableSchematron) 39 private CMDIValidatorFactory(File cacheDirectory, 40 File schematronSchemaFile, boolean disableSchematron) 39 41 throws CMDIValidatorInitException { 40 42 /* … … 93 95 if (!disableSchematron) { 94 96 logger.debug("initializing Schematron validator ..."); 95 URL schema = this.getClass().getResource(DEFAULT_SCHEMATRON_SCHEMA); 96 if (schema == null) { 97 throw new CMDIValidatorInitException( 98 "cannot locate schematron schema"); 97 98 URL schema = null; 99 if (schematronSchemaFile != null) { 100 if (!schematronSchemaFile.exists()) { 101 throw new CMDIValidatorInitException("file '" + 102 schematronSchemaFile.getAbsolutePath() + 103 "' does not exist"); 104 } 105 if (!schematronSchemaFile.isFile()) { 106 throw new CMDIValidatorInitException("file '" + 107 schematronSchemaFile.getAbsolutePath() + 108 "' is not a regular file"); 109 } 110 if (!schematronSchemaFile.canRead()) { 111 throw new CMDIValidatorInitException("file '" + 112 schematronSchemaFile.getAbsolutePath() + 113 "' cannot be read"); 114 } 115 try { 116 schema = schematronSchemaFile.toURI().toURL(); 117 } catch (MalformedURLException e) { 118 throw new CMDIValidatorInitException("internal error", e); 119 } 120 } else { 121 schema = this.getClass().getResource(DEFAULT_SCHEMATRON_SCHEMA); 122 if (schema == null) { 123 throw new CMDIValidatorInitException( 124 "cannot locate bundled Schematron schema: " + 125 DEFAULT_SCHEMATRON_SCHEMA); 126 } 99 127 } 100 128 final XsltCompiler compiler = processor.newXsltCompiler(); … … 132 160 133 161 public static CMDIValidatorFactory newInstance(File cacheDircetory, 134 boolean disableSchematron) throws CMDIValidatorInitException { 135 return new CMDIValidatorFactory(cacheDircetory, disableSchematron); 162 File schematronSchemaFile, boolean disableSchematron) 163 throws CMDIValidatorInitException { 164 return new CMDIValidatorFactory(cacheDircetory, schematronSchemaFile, 165 disableSchematron); 136 166 } 137 167 … … 139 169 public static CMDIValidatorFactory newInstance() 140 170 throws CMDIValidatorInitException { 141 return new CMDIValidatorFactory(null, false);171 return new CMDIValidatorFactory(null, null, false); 142 172 } 143 173 -
CMDIValidator/trunk/src/main/java/eu/clarin/cmdi/validator/tool/CMDIValidatorTool.java
r5056 r5073 45 45 private static final char OPT_NO_THREADS = 'T'; 46 46 private static final char OPT_NO_ESTIMATE = 'E'; 47 private static final char OPT_SCHEMA_CACHE_DIR = ' C';47 private static final char OPT_SCHEMA_CACHE_DIR = 'c'; 48 48 private static final char OPT_NO_SCHEMATRON = 'S'; 49 49 private static final char OPT_SCHEMATRON_FILE = 's'; … … 65 65 File schemaCacheDir = null; 66 66 boolean disableSchematron = false; 67 File schematronFile = null; 67 68 68 69 /* … … 120 121 String dir = line.getOptionValue(OPT_SCHEMA_CACHE_DIR); 121 122 if ((dir == null) || dir.isEmpty()) { 122 throw new ParseException("invalid argument for -S"); 123 throw new ParseException("invalid argument for -" + 124 OPT_SCHEMA_CACHE_DIR); 123 125 } 124 126 schemaCacheDir = new File(dir); … … 126 128 if (line.hasOption(OPT_NO_SCHEMATRON)) { 127 129 disableSchematron = true; 130 } 131 if (line.hasOption(OPT_SCHEMATRON_FILE)) { 132 String name = line.getOptionValue(OPT_SCHEMATRON_FILE); 133 if ((name == null) || name.isEmpty()) { 134 throw new ParseException("invalid argument for -" + 135 OPT_SCHEMATRON_FILE); 136 } 137 schematronFile = new File(name); 128 138 } 129 139 … … 157 167 logger.info("using schema cache directory: {}", schemaCacheDir); 158 168 } 169 if (schematronFile != null) { 170 logger.info("using Schematron schema from file: {}", schematronFile); 171 } 159 172 final CMDIValidatorFactory factory = 160 173 CMDIValidatorFactory.newInstance(schemaCacheDir, 161 disableSchematron);174 schematronFile, disableSchematron); 162 175 163 176 /* … … 340 353 .withLongOpt("no-schematron") 341 354 .create(OPT_NO_SCHEMATRON)); 342 //g3.addOption(OptionBuilder343 // .withDescription("load Schematron validator rulesfrom file")344 //.hasArg()345 //.withArgName("FILE")346 //.withLongOpt("schematron-file")347 //.create(OPT_SCHEMATRON_FILE));355 g3.addOption(OptionBuilder 356 .withDescription("load Schematron schema from file") 357 .hasArg() 358 .withArgName("FILE") 359 .withLongOpt("schematron-file") 360 .create(OPT_SCHEMATRON_FILE)); 348 361 options.addOptionGroup(g3); 349 362 return options;
Note: See TracChangeset
for help on using the changeset viewer.