CommentStripper commentStripper = new CommentStripper();
commentStripper.setUnderlyingReceiver(styleStripper);
// build the stylesheet document
DocumentImpl doc;
try {
Sender sender = new Sender(config);
AugmentedSource aug = AugmentedSource.makeAugmentedSource(styleSource);
aug.setSchemaValidation(Boolean.FALSE);
if (aug.getXMLReader() == null) {
aug.setXMLReader(config.getStyleParser());
}
sender.send(aug, commentStripper);
doc = (DocumentImpl)styleBuilder.getCurrentDocument();
} catch (XPathException err) {
Throwable cause = err.getException();
if (cause != null) {
if (cause instanceof SAXParseException) {
// This normally means there was an XML parsing error, in which
// case it has already been reported. But in the case of Crimson,
// the SAXParseException might wrap an exception that happened
// within callback code in Saxon.
SAXParseException spe = (SAXParseException)cause;
cause = spe.getException();
if (cause != null) {
if (cause instanceof TransformerConfigurationException) {
throw (TransformerConfigurationException)cause;
} else {
if (cause instanceof RuntimeException) {
// A RunTimeException during stylesheet compilation is bad news...
cause.printStackTrace();
}
throw new TransformerConfigurationException(cause);
}
}
// details already reported, don't repeat them
throw new TransformerConfigurationException("Failed to parse stylesheet");
} else if (cause instanceof TransformerConfigurationException) {
throw (TransformerConfigurationException)cause;
} else {
throw new TransformerConfigurationException(cause);
}
}
throw new TransformerConfigurationException(err);
}
if (doc.getDocumentElement()==null) {
throw new TransformerConfigurationException("Stylesheet is empty or absent");
}
return doc;