Skip to content

Commit

Permalink
Merge pull request DSpace#9045 from ChrisBethgster/9043_use_templates…
Browse files Browse the repository at this point in the history
…_instead_tranformer

OAI-PMH use Templates for compiled XSLT instead of Transformer (thread-safe)
  • Loading branch information
tdonohue authored Oct 30, 2023
2 parents 90d9dfa + 160ebbd commit 277994c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
39 changes: 4 additions & 35 deletions 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.4.0</xoai.version>
<jtwig.version>5.87.0.RELEASE</jtwig.version>
</properties>

Expand Down Expand Up @@ -55,41 +55,10 @@
<artifactId>xoai</artifactId>
<version>${xoai.version}</version>
<exclusions>
<!-- Use version provided by SolrJ -->
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</exclusion>
<exclusion>
<!--Hard pinned below.-->
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<!-- Later version provided by SolrJ -->
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
</exclusion>
<!-- Later version provided by Hibernate -->
<exclusion>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
<!-- We don't use this test framework & it causes dependency convergence issues -->
<exclusion>
<groupId>com.lyncode</groupId>
<artifactId>test-support</artifactId>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
</exclusion>
</exclusions>
</dependency>
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 277994c

Please sign in to comment.