Fields Summary |
---|
private final ValidatorHandlerImpl | handlerThe actual validation will be done by this object. |
private Transformer | identityTransformer1Lazily created identity transformer. |
private TransformerHandler | identityTransformer2 |
private final ErrorHandler | errorForwarderForwards the error to the {@link ValidatorHandler}.
If the {@link ValidatorHandler} doesn't have its own
{@link ErrorHandler}, behave draconian. |
private final EntityResolver | resolutionForwarderForwards the entity resolution to the {@link ValidatorHandler}.
If the {@link ValidatorHandler} doesn't have its own
{@link DOMResourceResolver}, let the parser do the resolution. |
Methods Summary |
---|
public org.xml.sax.ErrorHandler | getErrorHandler()
return handler.getErrorHandler();
|
public org.w3c.dom.ls.LSResourceResolver | getResourceResolver()
return handler.getResourceResolver();
|
private void | process(javax.xml.transform.sax.SAXSource source, javax.xml.transform.sax.SAXResult result)Parses a {@link SAXSource} potentially to a {@link SAXResult}.
if( result!=null ) {
handler.setContentHandler(result.getHandler());
}
try {
XMLReader reader = source.getXMLReader();
if( reader==null ) {
// create one now
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
try {
reader = spf.newSAXParser().getXMLReader();
} catch( Exception e ) {
// this is impossible, but better safe than sorry
throw new FactoryConfigurationError(e);
}
}
reader.setErrorHandler(errorForwarder);
reader.setEntityResolver(resolutionForwarder);
reader.setContentHandler(handler);
InputSource is = source.getInputSource();
reader.parse(is);
} finally {
// release the reference to user's handler ASAP
handler.setContentHandler(null);
}
|
private void | process(javax.xml.transform.dom.DOMSource source, javax.xml.transform.dom.DOMResult result)Parses a {@link DOMSource} potentially to a {@link DOMResult}.
if( identityTransformer1==null ) {
try {
SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
identityTransformer1 = tf.newTransformer();
identityTransformer2 = tf.newTransformerHandler();
} catch (TransformerConfigurationException e) {
// this is impossible, but again better safe than sorry
throw new TransformerFactoryConfigurationError(e);
}
}
if( result!=null ) {
handler.setContentHandler(identityTransformer2);
identityTransformer2.setResult(result);
}
try {
identityTransformer1.transform( source, new SAXResult(handler) );
} catch (TransformerException e) {
if( e.getException() instanceof SAXException )
throw (SAXException)e.getException();
throw new SAXException(e);
} finally {
handler.setContentHandler(null);
}
|
public void | reset()
handler.reset();
// I don't think this is necessary, but I don't think it hurts either.
// so reset just for the kick.
if(identityTransformer1!=null) {
identityTransformer1.reset();
}
|
public void | setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
handler.setErrorHandler(errorHandler);
|
public void | setResourceResolver(org.w3c.dom.ls.LSResourceResolver resolver)
handler.setResourceResolver(resolver);
|
public void | validate(javax.xml.transform.Source source, javax.xml.transform.Result result)
if( source instanceof DOMSource ) {
if( result!=null && !(result instanceof DOMResult) )
throw new IllegalArgumentException(result.getClass().getName());
process( (DOMSource)source, (DOMResult)result );
return;
}
if( source instanceof SAXSource ) {
if( result!=null && !(result instanceof SAXResult) )
throw new IllegalArgumentException(result.getClass().getName());
process( (SAXSource)source, (SAXResult)result );
return;
}
if( source instanceof StreamSource ) {
if( result!=null )
throw new IllegalArgumentException(result.getClass().getName());
StreamSource ss = (StreamSource)source;
InputSource is = new InputSource();
is.setByteStream(ss.getInputStream());
is.setCharacterStream(ss.getReader());
is.setPublicId(ss.getPublicId());
is.setSystemId(ss.getSystemId());
process( new SAXSource(is), null );
return;
}
throw new IllegalArgumentException(source.getClass().getName());
|