com.thaiopensource.validate.CombineValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicketstuff-jing Show documentation
Show all versions of wicketstuff-jing Show documentation
Jing is a validator for RELAX NG and other schema languages. This
project was taken from http://code.google.com/p/jing-trang and
mavenized for inclusion in the Wicket Stuff HTML Validator.
The code was taken from the 20091111 release.
package com.thaiopensource.validate;
import com.thaiopensource.xml.sax.ForkContentHandler;
import com.thaiopensource.xml.sax.ForkDTDHandler;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
public class CombineValidator implements Validator {
private final Validator v1;
private final Validator v2;
private ContentHandler contentHandler;
private DTDHandler dtdHandler;
public CombineValidator(Validator v1, Validator v2) {
this.v1 = v1;
this.v2 = v2;
createHandlers();
}
public void reset() {
v1.reset();
v2.reset();
createHandlers();
}
public ContentHandler getContentHandler() {
return contentHandler;
}
public DTDHandler getDTDHandler() {
return dtdHandler;
}
private void createHandlers() {
contentHandler = new ForkContentHandler(v1.getContentHandler(),
v2.getContentHandler());
DTDHandler d1 = v1.getDTDHandler();
DTDHandler d2 = v2.getDTDHandler();
if (d1 != null && d2 != null)
dtdHandler = new ForkDTDHandler(d1, d2);
else if (d1 != null)
dtdHandler = d1;
else if (d2 != null)
dtdHandler = d2;
else
dtdHandler = null;
}
}