001 package com.thaiopensource.validate.schematron;
002
003 import com.thaiopensource.validate.StringPropertyId;
004 import com.thaiopensource.validate.FlagPropertyId;
005 import com.thaiopensource.validate.Option;
006 import com.thaiopensource.validate.FlagOption;
007 import com.thaiopensource.validate.StringOption;
008 import com.thaiopensource.validate.OptionArgumentFormatException;
009 import com.thaiopensource.validate.SchemaReader;
010 import com.thaiopensource.xml.util.Naming;
011
012 /**
013 * Properties for controlling schema reading and validation specific to Schematron.
014 */
015 public class SchematronProperty {
016 private SchematronProperty() { }
017
018 /**
019 * PropertyId that specifies the Schematron phase to use.
020 * This applies during schema creation.
021 */
022 public static final StringPropertyId PHASE = new StringPropertyId("PHASE");
023
024 static public class PhaseOption extends StringOption {
025 private PhaseOption() {
026 super(PHASE);
027 }
028
029 public String normalize(String value) throws OptionArgumentFormatException {
030 value = value.trim();
031 if (!value.equals("#ALL") && !Naming.isNcname(value))
032 throw new OptionArgumentFormatException();
033 return value;
034 }
035 }
036
037 public static final StringOption PHASE_OPTION = new PhaseOption();
038
039 /**
040 * PropertyId thats specifies that diagnostic messages should be included.
041 * This applies during validation.
042 */
043 public static final FlagPropertyId DIAGNOSE = new FlagPropertyId("DIAGNOSE");
044
045 public static Option getOption(String uri) {
046 if (!uri.startsWith(SchemaReader.BASE_URI))
047 return null;
048 uri = uri.substring(SchemaReader.BASE_URI.length());
049 if (uri.equals("diagnose"))
050 return new FlagOption(DIAGNOSE);
051 if (uri.equals("phase"))
052 return PHASE_OPTION;
053 return null;
054 }
055 }