01: package vicazh.hyperpool;
02:
03: import java.io.*;
04: import javax.management.*;
05: import javax.xml.transform.*;
06: import javax.xml.transform.stream.*;
07:
08: /**
09: * The xml processor
10: *
11: * @author Victor Zhigunov
12: * @version 0.4.0
13: */
14: public class Processor extends NotificationBroadcasterSupport {
15:
16: static private URIResolver resolver = new URIResolver() {
17: public Source resolve(String href, String base)
18: throws TransformerException {
19: return new StreamSource(getClass().getResource(href)
20: .toString());
21: }
22: };
23:
24: static private TransformerFactory transformerFactory = TransformerFactory
25: .newInstance();
26:
27: private Templates templates;
28:
29: public Processor(String t) throws TransformerException {
30: synchronized (transformerFactory) {
31: transformerFactory.setURIResolver(resolver);
32: templates = transformerFactory.newTemplates(resolver
33: .resolve(t, null));
34: }
35: }
36:
37: public byte[] transform(byte[] b) throws TransformerException {
38: ByteArrayOutputStream out = new ByteArrayOutputStream();
39: templates.newTransformer().transform(
40: new StreamSource(new ByteArrayInputStream(b)),
41: new StreamResult(out));
42: return out.toByteArray();
43: }
44:
45: }
|