{
log.debug("processPipeline(Configuration, File) - start");
}
boolean succesful = false;
Pipeline pipeline = (Pipeline)configuration.getPipeline();
File sourceFile = new File(pipeline.getSource().getFile());
InputSource input = null;
if (pipeline.getSource().getType().equals("ASN1"))
{
log.info(
"Processing ASN.1 file: " + sourceFile.getAbsolutePath());
SimpleNode root = Asn1Parser.parse(sourceFile);
if (root == null)
{
if (log.isEnabled(LogLevel.DEBUG))
{
log.debug("processPipeline(Configuration, File) - end");
}
return false;
}
// Set up the input stream
input = new InputSource(new StringReader(createXMLfromAST(root)));
}
else
{
log.info("Processing XML file: " + sourceFile.getAbsolutePath());
// Set up the input stream
try
{
input = new InputSource(new FileReader(sourceFile));
}
catch (FileNotFoundException e)
{
log.caught(
LogLevel.ERROR,
"processPipeline(Configuration, File) :" + e.getMessage(),
e);
return false;
}
}
try
{
// Set up to read the input file
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
// Create the filters
SAXTransformerFactory stf =
(SAXTransformerFactory)TransformerFactory.newInstance();
URIResolver resolver =
new ClasspathURIResolver(stf.getURIResolver());
stf.setURIResolver(resolver);
net.sf.saxon.Filter filter = null;
XMLReader parent = reader;
for (int i = 0; i < pipeline.getFilter().size(); i++)
{
// extract information from pipeline structure
PipelineType.FilterType filterType =
((PipelineType.FilterType)pipeline.getFilter().get(i));
if (!filterType.isDisabled())
{
log.info(
"attach filter: " + filterType.getId() + " ("
+ filterType.getXsl() + ")");
Source xslSource =
resolver.resolve(filterType.getXsl(), null);
filter = (net.sf.saxon.Filter)stf.newXMLFilter(xslSource);
filter.setParent(parent);
parent = filter;
// set XSL parameter; pipeline configuration
filter.getTransformer().setParameter(
"configFile",
replacePathSeparator(configurationFile));
// set XSL parameter; filterID
filter.getTransformer().setParameter(
"filterID",
filterType.getId());
// set XSL parameter; filterdescription
filter.getTransformer().setParameter(
"filterDescription",
filterType.getDescription());
}
}
// Set up the result stream
Writer writer = null;
if (pipeline.getSink() != null)
{
File ouputFile = new File(pipeline.getSink().getFile());
writer = new FileWriter(ouputFile);
}
else
{
writer = new StringWriter();
}
StreamResult result = new StreamResult(writer);
// Set up the transformer to process the SAX events generated
// by the last filter in the chain
Transformer transformer = stf.newTransformer();
// set outputproperties
transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(
OutputKeys.OMIT_XML_DECLARATION,
"no");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
log.info("Processing pipeline");
SAXSource transformSource = new SAXSource(parent, input);
transformer.transform(transformSource, result);
if (log.isEnabled(LogLevel.DEBUG))
{
if (pipeline.getSink() != null)
{
log.debug(
"processPipeline(Configuration, File) output:\n"
+ pipeline.getSink().getFile());
}
else
{
log.debug(
"processPipeline(Configuration, File) output:\n"