You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Bruno Verachten <Br...@laposte.net> on 2002/02/21 12:01:25 UTC
[LONG] Slight Problem with the Pipe.java example.
Hi!
I'm currently using xalan-j_2_3_D1 and trying to pipe transformations...
It should work, but I have a problem...
I implemented java.net.URLStreamHandler(s) for my needs, so that I can
call document('classdescriptor://java.util.Date') in my XSLTs to get extra
info (dynamicly generated XMLs).
It worked until I decided to chain the transformations...
FYI, my class implements URIResolver for finding the XSLs in the jar file.
Here's my code:
public String process(File xml, InputStream[] xsls)
throws TransformerException, TransformerConfigurationException {
StreamSource xslSource = null;
Transformer transformer = null;
TransformerHandler [] handlers = new
TransformerHandler[xsls.length];
XMLReader reader = null;
// Create a transform factory instance.
SAXTransformerFactory saxtfactory =
((SAXTransformerFactory) TransformerFactory.newInstance());
saxtfactory.setURIResolver(this);
// Create a TransformerHandler for each stylesheet.
for (int i=0; i < handlers.length; i++) {
TransformerHandler tempHandler =
saxtfactory.newTransformerHandler(new StreamSource(xsls[i]));
handlers[i] = tempHandler;
if (i >0) {
handlers[i - 1].setResult(new
SAXResult(tempHandler));
}
// Create an XMLReader.
try {
reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(handlers[0]);
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
handlers[0]);
} catch ( org.xml.sax.SAXNotRecognizedException
snre) {
snre.printStackTrace();
} catch (org.xml.sax.SAXException sae) {
sae.printStackTrace();
}
}
// outputs SAX events to the serializer.
Serializer serializer = SerializerFactory.getSerializer
(OutputProperties.getDefaultMethodProperties("xml"));
StringWriter result = new StringWriter();
serializer.setWriter(result);
handlers[handlers.length - 1].setResult(new
StreamResult(result));
try {
reader.parse(new InputSource(new
FileInputStream(xml)));
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
} catch (org.xml.sax.SAXException se) {
se.printStackTrace();
}
return result.toString();
}
I know the custom protocols are still reachable because
try {
java.net.URL myUrl = new
java.net.URL("classdescriptor://java.util.Date");
} catch (java.net.MalformedURLException mue) {
System.err.println("[ERROR] Classes description
won't be reachable by the protocol classdescriptor://!!!");
}
still works.
What did I forget?
Thanks a lot.
Bruno Verachten.
Re: [LONG] Slight Problem with the Pipe.java example.
Posted by Bruno Verachten <Br...@laposte.net>.
Please forget my last mail, it was a BAD bug from MY code... :-(
I implemented an URIResolver, and was ignoring the classdescriptor://xxx
URLs
I thought it was Xalan's fault, but it's mine, sorry...
BTW, can I get rid of this code? If I ever want to switch to XSLTC, it
won't work
anymore...
Serializer serializer = SerializerFactory.getSerializer
(OutputProperties.getDefaultMethodProperties("xml"));
StringWriter result = new StringWriter();
serializer.setWriter(result);
handlers[handlers.length - 1].setResult(new
StreamResult(result));
Thanks.
Bruno Verachten.