mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
[DS-2426] added possibility to use relative import in oai xslt transformers
This commit is contained in:
@@ -7,29 +7,46 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xoai.services.impl.resources;
|
package org.dspace.xoai.services.impl.resources;
|
||||||
|
|
||||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
|
|
||||||
import javax.xml.transform.Transformer;
|
|
||||||
import javax.xml.transform.TransformerConfigurationException;
|
|
||||||
import javax.xml.transform.TransformerFactory;
|
|
||||||
import javax.xml.transform.stream.StreamSource;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class DSpaceResourceResolver implements ResourceResolver {
|
import javax.xml.transform.Source;
|
||||||
private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
import javax.xml.transform.Transformer;
|
||||||
private final String basePath = ConfigurationManager.getProperty("oai", "config.dir");
|
import javax.xml.transform.TransformerConfigurationException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.stream.StreamSource;
|
||||||
|
|
||||||
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
|
||||||
|
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||||
|
|
||||||
|
public class DSpaceResourceResolver implements ResourceResolver
|
||||||
|
{
|
||||||
|
private static final TransformerFactory transformerFactory = TransformerFactory
|
||||||
|
.newInstance();
|
||||||
|
|
||||||
|
private final String basePath = ConfigurationManager.getProperty("oai",
|
||||||
|
"config.dir");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getResource(String path) throws IOException {
|
public InputStream getResource(String path) throws IOException
|
||||||
|
{
|
||||||
return new FileInputStream(new File(basePath, path));
|
return new FileInputStream(new File(basePath, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Transformer getTransformer(String path) throws IOException, TransformerConfigurationException {
|
public Transformer getTransformer(String path) throws IOException,
|
||||||
return transformerFactory.newTransformer(new StreamSource(getResource(path)));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user