1 package org.apache.slide.projector.processor.xml;2 3 import java.io.IOException ;4 5 import javax.xml.transform.Transformer ;6 import javax.xml.transform.TransformerConfigurationException ;7 import javax.xml.transform.TransformerFactory ;8 import javax.xml.transform.stream.StreamSource ;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 transformer;33 34 public Value process(Value input, Context context) throws Exception {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 {50 try {51 transformer = TransformerFactory.newInstance().newTransformer(new StreamSource (config.getInputStream()));52 } catch (TransformerConfigurationException e) {53 throw new ConfigurationException (new ErrorMessage("xslTransformer/creationgFailed"), e);54 } catch (IOException e) {55 throw new ConfigurationException (new ErrorMessage("xslTransformer/ioException"), e);56 }57 }58 }