1 package com.thaiopensource.relaxng.impl; 2 3 import com.thaiopensource.validate.Validator; 4 import com.thaiopensource.xml.sax.ForkContentHandler; 5 import com.thaiopensource.xml.sax.ForkDTDHandler; 6 import org.xml.sax.ContentHandler ; 7 import org.xml.sax.DTDHandler ; 8 9 public class CombineValidator implements Validator { 10 private final Validator v1; 11 private final Validator v2; 12 private ContentHandler contentHandler; 13 private DTDHandler dtdHandler; 14 15 public CombineValidator(Validator v1, Validator v2) { 16 this.v1 = v1; 17 this.v2 = v2; 18 createHandlers(); 19 } 20 21 public void reset() { 22 v1.reset(); 23 v2.reset(); 24 createHandlers(); 25 } 26 27 public ContentHandler getContentHandler() { 28 return contentHandler; 29 } 30 31 public DTDHandler getDTDHandler() { 32 return dtdHandler; 33 } 34 35 private void createHandlers() { 36 contentHandler = new ForkContentHandler(v1.getContentHandler(), 37 v2.getContentHandler()); 38 DTDHandler d1 = v1.getDTDHandler(); 39 DTDHandler d2 = v2.getDTDHandler(); 40 if (d1 != null && d2 != null) 41 dtdHandler = new ForkDTDHandler(d1, d2); 42 else if (d1 != null) 43 dtdHandler = d1; 44 else if (d2 != null) 45 dtdHandler = d2; 46 else 47 dtdHandler = null; 48 } 49 } 50 | Popular Tags |