1 package com.thaiopensource.relaxng.util; 2 3 import com.thaiopensource.util.PropertyMap; 4 import com.thaiopensource.util.PropertyMapBuilder; 5 import com.thaiopensource.validate.ValidateProperty; 6 import com.thaiopensource.validate.ValidationDriver; 7 import com.thaiopensource.validate.rng.CompactSchemaReader; 8 import com.thaiopensource.validate.rng.RngProperty; 9 import com.thaiopensource.xml.sax.XMLReaderCreator; 10 import com.thaiopensource.xml.sax.Sax2XMLReaderCreator; 11 import org.xml.sax.ErrorHandler ; 12 13 21 public class ValidationEngine extends ValidationDriver { 22 23 27 public static final int CHECK_ID_IDREF = 01; 28 32 public static final int COMPACT_SYNTAX = 02; 33 36 public static final int FEASIBLE = 04; 37 38 41 public ValidationEngine() { 42 this(null, null, CHECK_ID_IDREF); 43 } 44 59 public ValidationEngine(XMLReaderCreator xrc, 60 ErrorHandler eh, 61 int flags) { 62 super(makePropertyMap(xrc, eh, flags), 63 (flags & COMPACT_SYNTAX) == 0 ? null : CompactSchemaReader.getInstance()); 64 } 65 66 private static PropertyMap makePropertyMap(XMLReaderCreator xrc, ErrorHandler eh, int flags) { 67 PropertyMapBuilder builder = new PropertyMapBuilder(); 68 if (xrc == null) 69 xrc = new Sax2XMLReaderCreator(); 70 ValidateProperty.XML_READER_CREATOR.put(builder, xrc); 71 if (eh != null) 72 ValidateProperty.ERROR_HANDLER.put(builder, eh); 73 if ((flags & CHECK_ID_IDREF) != 0) 74 RngProperty.CHECK_ID_IDREF.add(builder); 75 if ((flags & FEASIBLE) != 0) 76 RngProperty.FEASIBLE.add(builder); 77 return builder.toPropertyMap(); 78 } 79 80 91 public ValidationEngine(XMLReaderCreator xrc, 92 ErrorHandler eh, 93 boolean checkIdIdref) { 94 this(xrc, eh, checkIdIdref ? CHECK_ID_IDREF : 0); 95 } 96 97 110 public ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref, boolean compactSyntax) { 111 this(xrc, 112 eh, 113 (checkIdIdref ? CHECK_ID_IDREF : 0) 114 | (compactSyntax ? COMPACT_SYNTAX : 0)); 115 } 116 117 118 public ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref, boolean compactSyntax, 119 boolean feasible) { 120 this(xrc, 121 eh, 122 (checkIdIdref ? CHECK_ID_IDREF : 0) 123 | (compactSyntax ? COMPACT_SYNTAX : 0) 124 | (feasible ? FEASIBLE : 0)); 125 } 126 127 } 128 | Popular Tags |