net.sf.saxon.s9api.XsltExecutable Java Examples
The following examples show how to use
net.sf.saxon.s9api.XsltExecutable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentRepository.java From validator with Apache License 2.0 | 6 votes |
/** * Lädt ein XSL von der angegebenen URI * * @param uri die URI der XSL Definition * @return ein XSLT Executable */ public XsltExecutable loadXsltScript(final URI uri) { log.info("Loading XSLT script from {}", uri); final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler(); final CollectingErrorEventHandler listener = new CollectingErrorEventHandler(); try { xsltCompiler.setErrorListener(listener); if (getResolver() != null) { // otherwise use default resolver xsltCompiler.setURIResolver(getResolver()); } return xsltCompiler.compile(resolveInRepository(uri)); } catch (final SaxonApiException e) { listener.getErrors().forEach(event -> event.log(log)); throw new IllegalStateException("Can not compile xslt executable for uri " + uri, e); } finally { if (!listener.hasErrors() && listener.hasEvents()) { log.warn("Received warnings or errors while loading a xslt script {}", uri); listener.getErrors().forEach(e -> e.log(log)); } } }
Example #2
Source File: SchematronValidationActionTest.java From validator with Apache License 2.0 | 5 votes |
@Test public void testProcessingError() throws IOException, SaxonApiException { final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()), true); final Scenario scenario = bag.getScenarioSelectionResult().getObject(); final XsltExecutable exec = mock(XsltExecutable.class); final XsltTransformer transformer = mock(XsltTransformer.class); doThrow(new SaxonApiException("invalid")).when(transformer).transform(); when(exec.load()).thenReturn(transformer); final ResourceType resourceType = new ResourceType(); resourceType.setName("invalid internal"); scenario.setSchematronValidations(Collections.singletonList(new Transformation(exec, resourceType))); this.action.check(bag); assertThat(bag.getReportInput().getProcessingError().getError()).isNotEmpty(); }
Example #3
Source File: SaxonSecurityTest.java From validator with Apache License 2.0 | 5 votes |
@Test public void testEvilStylesheets() throws IOException { final Processor p = TestObjectFactory.createProcessor(); for (int i = 1; i <= 5; i++) { try { final URL resource = SaxonSecurityTest.class.getResource(String.format("/evil/evil%s.xsl", i)); final XsltCompiler compiler = p.newXsltCompiler(); final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY_URI); compiler.setURIResolver(resolver); final XsltExecutable executable = compiler.compile(new StreamSource(resource.openStream())); final XsltTransformer transformer = executable.load(); final Source document = InputFactory.read("<root/>".getBytes(), "dummy").getSource(); // transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver); transformer.setURIResolver(resolver); transformer.setSource(document); final XdmDestination result = new XdmDestination(); transformer.setDestination(result); transformer.transform(); // wenn der Punkt erreicht wird, sollte wenigstens, das Element evil nicht mit 'bösen' Inhalten gefüllt sein! if (StringUtils.isNotBlank(result.getXdmNode().getStringValue())) { fail(String.format("Saxon configuration should prevent expansion within %s", resource)); } } catch (final SaxonApiException | RuntimeException e) { log.info("Expected exception detected {}", e.getMessage(), e); } } }
Example #4
Source File: TECore.java From teamengine with Apache License 2.0 | 5 votes |
XPathContext getXPathContext(TestEntry test, String sourcesName, XdmNode contextNode) throws Exception { XPathContext context = null; if (test.usesContext()) { XsltExecutable xe = engine.loadExecutable(test, sourcesName); Executable ex = xe.getUnderlyingCompiledStylesheet() .getExecutable(); context = new XPathContextMajor(contextNode.getUnderlyingNode(), ex); } return context; }
Example #5
Source File: TECore.java From teamengine with Apache License 2.0 | 5 votes |
public XdmNode executeTemplate(TemplateEntry template, XdmNode params, XPathContext context) throws Exception { if (stop) { throw new Exception("Execution was stopped by the user."); } XsltExecutable executable = engine.loadExecutable(template, opts.getSourcesName()); XsltTransformer xt = executable.load(); XdmDestination dest = new XdmDestination(); xt.setDestination(dest); if (template.usesContext() && context != null) { xt.setSource((NodeInfo) context.getContextItem()); } else { xt.setSource(new StreamSource(new StringReader("<nil/>"))); } xt.setParameter(TECORE_QNAME, new ObjValue(this)); if (params != null) { xt.setParameter(TEPARAMS_QNAME, params); } // test may set global verdict, e.g. by calling ctl:fail if (LOGR.isLoggable( FINE)) { LOGR.log( FINE, "Executing TemplateEntry {0}" + template.getQName()); } xt.transform(); XdmNode ret = dest.getXdmNode(); if (ret != null && LOGR.isLoggable( FINE)) { LOGR.log( FINE, "Output:\n" + ret.toString()); } return ret; }
Example #6
Source File: CreateReportAction.java From validator with Apache License 2.0 | 4 votes |
private static XsltExecutable loadFromScenario(final Scenario object) { return object.getReportTransformation().getExecutable(); }
Example #7
Source File: CreateReportAction.java From validator with Apache License 2.0 | 4 votes |
private static XsltExecutable getTransformation(final Bag results) { return loadFromScenario(results.getScenarioSelectionResult().getObject()); }
Example #8
Source File: ContentRepository.java From validator with Apache License 2.0 | 4 votes |
public Transformation createTransformation(final ResourceType resource) { final XsltExecutable executable = loadXsltScript(URI.create(resource.getLocation())); return new Transformation(executable, resource); }
Example #9
Source File: ContentRepositoryTest.java From validator with Apache License 2.0 | 4 votes |
@Test public void testLoadXSLT() { final XsltExecutable executable = this.repository.loadXsltScript(Simple.REPORT_XSL); assertThat(executable).isNotNull(); }
Example #10
Source File: Engine.java From teamengine with Apache License 2.0 | 4 votes |
public Map<String, XsltExecutable> getLoadedExecutables() { return loadedExecutables; }
Example #11
Source File: Engine.java From teamengine with Apache License 2.0 | 4 votes |
public XsltExecutable getFormExecutable() { return formExecutable; }