KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > xml > XSLTransformer


1 package org.apache.slide.projector.processor.xml;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.xml.transform.Transformer JavaDoc;
6 import javax.xml.transform.TransformerConfigurationException JavaDoc;
7 import javax.xml.transform.TransformerFactory JavaDoc;
8 import javax.xml.transform.stream.StreamSource JavaDoc;
9
10 import org.apache.slide.projector.ConfigurableProcessor;
11 import org.apache.slide.projector.ConfigurationException;
12 import org.apache.slide.projector.Context;
13 import org.apache.slide.projector.descriptor.ParameterDescriptor;
14 import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
15 import org.apache.slide.projector.descriptor.XMLValueDescriptor;
16 import org.apache.slide.projector.i18n.DefaultMessage;
17 import org.apache.slide.projector.i18n.ErrorMessage;
18 import org.apache.slide.projector.i18n.ParameterMessage;
19 import org.apache.slide.projector.processor.SimpleProcessor;
20 import org.apache.slide.projector.value.DocumentValue;
21 import org.apache.slide.projector.value.StreamableValue;
22 import org.apache.slide.projector.value.Value;
23 import org.jdom.Document;
24 import org.jdom.transform.JDOMResult;
25 import org.jdom.transform.JDOMSource;
26
27 /**
28  * @version $Revision: 1.3 $
29  */

30
31 public class XSLTransformer extends SimpleProcessor implements ConfigurableProcessor {
32     private Transformer JavaDoc transformer;
33
34     public Value process(Value input, Context context) throws Exception JavaDoc {
35         Document document = ((DocumentValue)input).getDocument();
36         JDOMResult result = new JDOMResult();
37         transformer.transform(new JDOMSource(document), result);
38         return new DocumentValue(result.getDocument());
39     }
40
41     public ParameterDescriptor getParameterDescriptor() {
42         return new ParameterDescriptor(INPUT, new ParameterMessage("xslTransformer/parameter/input"), new XMLValueDescriptor());
43     }
44
45     public ResultEntryDescriptor getResultEntryDescriptor() {
46         return new ResultEntryDescriptor(OUTPUT, new DefaultMessage("xslTransformer/result/output"), "text/xml", true);
47     }
48
49     public void configure(StreamableValue config) throws ConfigurationException JavaDoc {
50         try {
51             transformer = TransformerFactory.newInstance().newTransformer(new StreamSource JavaDoc(config.getInputStream()));
52         } catch (TransformerConfigurationException JavaDoc e) {
53             throw new ConfigurationException JavaDoc(new ErrorMessage("xslTransformer/creationgFailed"), e);
54         } catch (IOException JavaDoc e) {
55             throw new ConfigurationException JavaDoc(new ErrorMessage("xslTransformer/ioException"), e);
56         }
57     }
58 }
Popular Tags