try {
//Make sure that the xsltFile exists
try {
xslFileStream = new FileInputStream(this.xsltFile);
} catch (IOException ioe) {
throw new CruiseControlException("Error reading the xsltFile: " + this.xsltFile, ioe);
}
//construct a FileWriter to the outputFile path location
try {
out = new FileWriter(path);
} catch (IOException ioe) {
throw new CruiseControlException("Unable to write to th file location: " + path);
}
//Prepare the transformer
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(xslFileStream));
//cruisecontrolLog.get
XMLLogHelper helper = new XMLLogHelper(cruisecontrolLog);
String logFileName = helper.getLogFileName();
LOG.info("Transforming the log file: " + logFileName + " to: " + path + " using the xslt: " + this.xsltFile);
//Create the temporary log file - since we do not have access to the actual log file location
xmlFile = writeTempLogFile(cruisecontrolLog);
if (xmlFile == null || !xmlFile.exists() || !xmlFile.canRead()) {
throw new CruiseControlException("Unable to read the log file at path: " + logFileName);
}
//perform the transform, writing out the results to the output location
transformer.transform(new StreamSource(xmlFile), new StreamResult(out));
} catch (TransformerException te) {
throw new CruiseControlException("An error occurred during the transformation process", te);
} catch (Exception ioe) {
throw new CruiseControlException("An unexpected exception occurred, unable to publish the log file.", ioe);
} finally {
//clean up
if (xslFileStream != null) {
try {
xslFileStream.close();