001 package com.thaiopensource.relaxng.impl; 002 003 import com.thaiopensource.validate.Validator; 004 import com.thaiopensource.xml.sax.ForkContentHandler; 005 import com.thaiopensource.xml.sax.ForkDTDHandler; 006 import org.xml.sax.ContentHandler; 007 import org.xml.sax.DTDHandler; 008 009 public class CombineValidator implements Validator { 010 private final Validator v1; 011 private final Validator v2; 012 private ContentHandler contentHandler; 013 private DTDHandler dtdHandler; 014 015 public CombineValidator(Validator v1, Validator v2) { 016 this.v1 = v1; 017 this.v2 = v2; 018 createHandlers(); 019 } 020 021 public void reset() { 022 v1.reset(); 023 v2.reset(); 024 createHandlers(); 025 } 026 027 public ContentHandler getContentHandler() { 028 return contentHandler; 029 } 030 031 public DTDHandler getDTDHandler() { 032 return dtdHandler; 033 } 034 035 private void createHandlers() { 036 contentHandler = new ForkContentHandler(v1.getContentHandler(), 037 v2.getContentHandler()); 038 DTDHandler d1 = v1.getDTDHandler(); 039 DTDHandler d2 = v2.getDTDHandler(); 040 if (d1 != null && d2 != null) 041 dtdHandler = new ForkDTDHandler(d1, d2); 042 else if (d1 != null) 043 dtdHandler = d1; 044 else if (d2 != null) 045 dtdHandler = d2; 046 else 047 dtdHandler = null; 048 } 049 }