public SchematronTransmogrifier(Class<T> outputFormat) { this(new XsltTransmogrifier<>(String.class), outputFormat); }
private static Source step(XsltTransmogrifier<String> t, Source input, String stylesheet, Map<String, Object> params) { String s = t.zap(input, stylesheet, params); return new StreamSource(new StringReader(s)); }
private void doZap(Source source, Result result, Object... params) { if (params.length == 0) { throw new IllegalArgumentException("Expected XSL location in first parameter"); } try { Templates template = resource(params); Transformer transformer = template.newTransformer(); transformer.setURIResolver(resolver); setXsltParameters(transformer, staticParams); setXsltParameters(transformer, resourceParameters(params)); transformer.transform(source, result); } catch (Exception e) { throw new RuntimeException("XSLT processing failed", e); } }
@Override protected Templates createResource(Object... params) { try { return factory.newTemplates(resourceContent(params)); } catch (TransformerConfigurationException e) { throw new IllegalArgumentException("Could not initialize XSLT template", e); } }
/** * Converts a Source into a Result using a XSL processor. * <p> * The XSL stylesheet resource location is mandatory in the first extra parameter. * XSL Parameters may be passed as a Map in the second parameter. * * @see Transmogrifier#zap(java.lang.Object, java.lang.Object[]) */ @Override public T zap(Source source, Object... params) { ResultHolder<T> accessor = ResultHolderFactory.create(outputFormat); if (accessor == null) throw new IllegalArgumentException("Format " + outputFormat.getClass() + " is not supported"); Result result = accessor.createResult(); doZap(source, result, params); return accessor.getResult(); }
public SchematronTransmogrifier(Class<T> outputFormat, Map<String, Object> staticParams) { this(new XsltTransmogrifier<>(String.class), outputFormat, staticParams); }
/** * Demonstrates how to include a Groovy class to be used in an XSLT script * * @throws IOException */ @Test public void testConvertString() throws IOException { Source content = new StreamSource(getClass().getResourceAsStream("/xslt/parameterExample.xml")); String s = transformer.zap(content, "/xslt/parameter.xslt", parameters); assertTrue(s.contains("ein negeR mi tgaz ellezaG tim regeN niE")); }
/** * Specifies that the transformation is done via XSLT * * @param clazz * the resulting type of the message body after the * transformation */ public <T> TransmogrifierAdapterDefinition xslt(Class<T> clazz) { transmogrifier = new XsltTransmogrifier<>(clazz); return (TransmogrifierAdapterDefinition)input(bodyAs(StreamSource.class)); }
@Test public void testConvertString() throws IOException { Source source = new StreamSource(getClass().getResourceAsStream("/xslt/createPatient.xml")); String result = transformer.zap(source, "/xslt/createPatient.xslt"); assertNotNull(result); }
/** * Specifies that the transformation is done via XSLT */ public TransmogrifierAdapterDefinition xslt() { transmogrifier = new XsltTransmogrifier<>(String.class); return (TransmogrifierAdapterDefinition)input(bodyAs(StreamSource.class)); }
@Before public void setUp() throws Exception { transformer = new XsltTransmogrifier<>(String.class); }
@Before public void setUp() throws Exception { parameters = new HashMap<>(); parameters.put("service", new XsltTestService()); transformer = new XsltTransmogrifier<>(String.class); }