aQute.libg.sax.SAXUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aQute.libg Show documentation
Show all versions of aQute.libg Show documentation
A library to be statically linked. Contains many small utilities. This bundle should not be installed in a framework, it is compile only.
package aQute.libg.sax;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Result;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import org.xml.sax.ContentHandler;
import org.xml.sax.XMLReader;
public class SAXUtil {
public static XMLReader buildPipeline(Result output, ContentFilter... filters) throws Exception {
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler handler = factory.newTransformerHandler();
handler.setResult(output);
ContentHandler last = handler;
if (filters != null)
for (ContentFilter filter : filters) {
filter.setParent(last);
last = filter;
}
XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setContentHandler(last);
return reader;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy