Skip to content

Commit

Permalink
9043 use Templates for compiled XSLT instead of Transformer - use Tem…
Browse files Browse the repository at this point in the history
…plates are thread-safe and NOT Transformer
  • Loading branch information
ChrisBethgster committed Aug 29, 2023
1 parent c7c3022 commit 1160341
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dspace-oai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties>
<!-- This is the path to the root [dspace-src] directory. -->
<root.basedir>${basedir}/..</root.basedir>
<xoai.version>3.3.0</xoai.version>
<xoai.version>3.3.1-SNAPSHOT</xoai.version>
<jtwig.version>5.87.0.RELEASE</jtwig.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.IOException;
import java.io.InputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.Templates;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
Expand Down Expand Up @@ -40,15 +40,14 @@ public InputStream getResource(String path) throws IOException {
}

@Override
public Transformer getTransformer(String path) throws IOException,
TransformerConfigurationException {
public Templates getTemplates(String path) throws IOException, TransformerConfigurationException {
// construct a Source that reads from an InputStream
Source mySrc = new StreamSource(getResource(path));
// specify a system ID (the path to the XSLT-file on the filesystem)
// so the Source can resolve relative URLs that are encountered in
// XSLT-files (like <xsl:import href="utils.xsl"/>)
String systemId = basePath + "/" + path;
mySrc.setSystemId(systemId);
return transformerFactory.newTransformer(mySrc);
return transformerFactory.newTemplates(mySrc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void pipelineTest() throws Exception {
InputStream input = PipelineTest.class.getClassLoader().getResourceAsStream("item.xml");
InputStream xslt = PipelineTest.class.getClassLoader().getResourceAsStream("oai_dc.xsl");
String output = FileUtils.readAllText(new XSLPipeline(input, true)
.apply(factory.newTransformer(new StreamSource(xslt)))
.apply(factory.newTemplates(new StreamSource(xslt)))
.getTransformed());

assertThat(output, oai_dc().withXPath("/oai_dc:dc/dc:title", equalTo("Teste")));
Expand Down

0 comments on commit 1160341

Please sign in to comment.