use of net.sf.saxon.trace.XSLTTraceListener in project ph-schematron by phax.
the class AbstractSchematronXSLTBasedResource method applySchematronValidation.
@Nullable
public final Document applySchematronValidation(@Nonnull final Node aXMLNode, @Nullable final String sBaseURI) throws TransformerException {
ValueEnforcer.notNull(aXMLNode, "XMLNode");
final ISchematronXSLTBasedProvider aXSLTProvider = getXSLTProvider();
if (aXSLTProvider == null || !aXSLTProvider.isValidSchematron()) {
// We cannot progress because of invalid Schematron
return null;
}
// Debug print the created XSLT document
if (SchematronDebug.isShowCreatedXSLT())
s_aLogger.info("Created XSLT document: " + XMLWriter.getNodeAsString(aXSLTProvider.getXSLTDocument()));
// Create result document
final Document ret = XMLFactory.newDocument();
// Create the transformer object from the templates specified in the
// constructor
final Transformer aTransformer = aXSLTProvider.getXSLTTransformer();
// Ensure an error listener is present
if (m_aCustomErrorListener != null)
aTransformer.setErrorListener(m_aCustomErrorListener);
else
aTransformer.setErrorListener(new LoggingTransformErrorListener(Locale.US));
// Set the optional URI Resolver
if (m_aCustomURIResolver != null)
aTransformer.setURIResolver(m_aCustomURIResolver);
// Set all custom parameters
if (m_aCustomParameters != null)
for (final Map.Entry<String, ?> aEntry : m_aCustomParameters.entrySet()) aTransformer.setParameter(aEntry.getKey(), aEntry.getValue());
if (s_aLogger.isDebugEnabled())
s_aLogger.debug("Applying Schematron XSLT on XML [start]");
// Enable this for hardcore Saxon debugging only
if (false)
if (aTransformer.getClass().getName().equals("net.sf.saxon.jaxp.TransformerImpl")) {
final XsltTransformer aXT = ((TransformerImpl) aTransformer).getUnderlyingXsltTransformer();
aXT.setMessageListener((a, b, c) -> s_aLogger.info("MessageListener: " + a + ", " + b + ", " + c));
aXT.setTraceFunctionDestination(new StandardLogger(System.err));
if (false)
aXT.getUnderlyingController().setTraceListener(new XSLTTraceListener());
if (false) {
final XSLTTraceListener aTL = new XSLTTraceListener();
aTL.setOutputDestination(new StandardLogger(System.err));
aXT.getUnderlyingController().setTraceListener(TraceEventMulticaster.add(aTL, null));
}
if (false)
System.out.println("mode=" + aXT.getInitialMode());
if (false)
System.out.println("temp=" + aXT.getInitialTemplate());
if (false)
System.out.println(aTransformer.getOutputProperties());
}
// Do the main transformation
aTransformer.transform(new DOMSource(aXMLNode), new DOMResult(ret));
if (s_aLogger.isDebugEnabled())
s_aLogger.debug("Applying Schematron XSLT on XML [end]");
// Debug print the created SVRL document
if (SchematronDebug.isShowCreatedSVRL())
s_aLogger.info("Created SVRL:\n" + XMLWriter.getNodeAsString(ret));
return ret;
}
Aggregations