in MODS test, replace external XSL loading from loc.gov by internal XSL
This commit is contained in:
parent
bcb4df4cce
commit
392a61dc12
4 changed files with 5279 additions and 131 deletions
|
@ -1,7 +1,13 @@
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral {
|
||||||
|
metadataSources {
|
||||||
|
mavenPom()
|
||||||
|
artifact()
|
||||||
|
ignoreGradleMetadataRedirection()
|
||||||
|
}
|
||||||
|
}
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class MarcToModsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSax() throws Exception {
|
public void testSax() throws Exception {
|
||||||
String s = "summerland.mrc";
|
String s = "summerland.mrc";
|
||||||
InputStream marcInputStream = getClass().getResource(s).openStream();
|
try (InputStream marcInputStream = getClass().getResource(s).openStream()) {
|
||||||
Marc marc = Marc.builder()
|
Marc marc = Marc.builder()
|
||||||
.setInputStream(marcInputStream)
|
.setInputStream(marcInputStream)
|
||||||
.setCharset(Charset.forName("ANSEL"))
|
.setCharset(Charset.forName("ANSEL"))
|
||||||
|
@ -65,11 +65,12 @@ public class MarcToModsTest {
|
||||||
assertThat(writer.toString(),
|
assertThat(writer.toString(),
|
||||||
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-sax-marc.xml").openStream()));
|
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-sax-marc.xml").openStream()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDom() throws Exception {
|
public void testDom() throws Exception {
|
||||||
String s = "summerland.mrc";
|
String s = "summerland.mrc";
|
||||||
InputStream marcInputStream = getClass().getResource(s).openStream();
|
try (InputStream marcInputStream = getClass().getResource(s).openStream()) {
|
||||||
Marc marc = Marc.builder()
|
Marc marc = Marc.builder()
|
||||||
.setInputStream(marcInputStream)
|
.setInputStream(marcInputStream)
|
||||||
.setCharset(Charset.forName("ANSEL"))
|
.setCharset(Charset.forName("ANSEL"))
|
||||||
|
@ -89,11 +90,12 @@ public class MarcToModsTest {
|
||||||
assertThat(writer.toString(),
|
assertThat(writer.toString(),
|
||||||
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-dom-marc.xml").openStream()));
|
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-dom-marc.xml").openStream()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStylesheetSax() throws Exception {
|
public void testStylesheetSax() throws Exception {
|
||||||
String s = "summerland.mrc";
|
String s = "summerland.mrc";
|
||||||
InputStream marcInputStream = getClass().getResource(s).openStream();
|
try (InputStream marcInputStream = getClass().getResource(s).openStream()) {
|
||||||
Marc marc = Marc.builder()
|
Marc marc = Marc.builder()
|
||||||
.setInputStream(marcInputStream)
|
.setInputStream(marcInputStream)
|
||||||
.setCharset(Charset.forName("ANSEL"))
|
.setCharset(Charset.forName("ANSEL"))
|
||||||
|
@ -104,6 +106,7 @@ public class MarcToModsTest {
|
||||||
StreamResult streamResult = new StreamResult(out);
|
StreamResult streamResult = new StreamResult(out);
|
||||||
InputStream xslInputStream = getClass().getResourceAsStream("MARC21slim2MODS3-6.xsl");
|
InputStream xslInputStream = getClass().getResourceAsStream("MARC21slim2MODS3-6.xsl");
|
||||||
TransformerFactory factory = TransformerFactory.newInstance();
|
TransformerFactory factory = TransformerFactory.newInstance();
|
||||||
|
// required for realtive URI resolving in xsl:include
|
||||||
factory.setURIResolver(new ClasspathResourceURIResolver());
|
factory.setURIResolver(new ClasspathResourceURIResolver());
|
||||||
Transformer transformer = factory.newTemplates(new StreamSource(xslInputStream)).newTransformer();
|
Transformer transformer = factory.newTemplates(new StreamSource(xslInputStream)).newTransformer();
|
||||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
|
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
|
||||||
|
@ -133,11 +136,12 @@ public class MarcToModsTest {
|
||||||
assertThat(out.toByteArray(),
|
assertThat(out.toByteArray(),
|
||||||
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-sax-mods.xml").openStream()));
|
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-sax-mods.xml").openStream()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStylesheetDom() throws Exception {
|
public void testStylesheetDom() throws Exception {
|
||||||
String s = "summerland.mrc";
|
String s = "summerland.mrc";
|
||||||
InputStream marcInputStream = getClass().getResource(s).openStream();
|
try (InputStream marcInputStream = getClass().getResource(s).openStream()) {
|
||||||
Marc marc = Marc.builder()
|
Marc marc = Marc.builder()
|
||||||
.setInputStream(marcInputStream)
|
.setInputStream(marcInputStream)
|
||||||
.setCharset(Charset.forName("ANSEL"))
|
.setCharset(Charset.forName("ANSEL"))
|
||||||
|
@ -179,11 +183,18 @@ public class MarcToModsTest {
|
||||||
assertThat(out.toByteArray(),
|
assertThat(out.toByteArray(),
|
||||||
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-dom-mods.xml").openStream()));
|
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-dom-mods.xml").openStream()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With regard to sandboxed CI/CD platforms, we avoid loading external XSL style sheets from loc.gov
|
||||||
|
* We run the test with a local copy.
|
||||||
|
*
|
||||||
|
* @throws Exception if test fails
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testLocStyleSheet() throws Exception {
|
public void testLocLocalCopyStyleSheet() throws Exception {
|
||||||
String s = "summerland.mrc";
|
String s = "summerland.mrc";
|
||||||
InputStream marcInputStream = getClass().getResource(s).openStream();
|
try (InputStream marcInputStream = getClass().getResource(s).openStream()) {
|
||||||
Marc marc = Marc.builder()
|
Marc marc = Marc.builder()
|
||||||
.setInputStream(marcInputStream)
|
.setInputStream(marcInputStream)
|
||||||
.setCharset(Charset.forName("ANSEL"))
|
.setCharset(Charset.forName("ANSEL"))
|
||||||
|
@ -191,17 +202,18 @@ public class MarcToModsTest {
|
||||||
.build();
|
.build();
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Result result = new StreamResult(sw);
|
Result result = new StreamResult(sw);
|
||||||
System.setProperty("http.agent", "Java Agent");
|
URL url = getClass().getResource("MARC21slim2MODS3.xsl");
|
||||||
marc.transform(TransformerFactory.newInstance(),
|
TransformerFactory factory = TransformerFactory.newInstance();
|
||||||
new URL("http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3.xsl"), result);
|
factory.setURIResolver(new ClasspathResourceURIResolver());
|
||||||
|
marc.transform(factory, url, result);
|
||||||
assertThat(sw.toString(),
|
assertThat(sw.toString(),
|
||||||
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-mods-loc-goc.xml").openStream()));
|
CompareMatcher.isIdenticalTo(getClass().getResource("summerland-mods-loc-goc-local-copy.xml").openStream()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ClasspathResourceURIResolver implements URIResolver {
|
private static class ClasspathResourceURIResolver implements URIResolver {
|
||||||
@Override
|
@Override
|
||||||
public Source resolve(String href, String base) throws TransformerException {
|
public Source resolve(String href, String base) {
|
||||||
return new StreamSource(getClass().getResourceAsStream(href));
|
return new StreamSource(getClass().getResourceAsStream(href));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5076
src/test/resources/org/xbib/marc/MARC21slim2MODS3.xsl
Normal file
5076
src/test/resources/org/xbib/marc/MARC21slim2MODS3.xsl
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,54 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?><mods xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd" version="3.4">
|
||||||
|
<titleInfo>
|
||||||
|
<title>Summerland</title>
|
||||||
|
</titleInfo>
|
||||||
|
<name type="personal" usage="primary">
|
||||||
|
<namePart>Chabon, Michael.</namePart>
|
||||||
|
</name>
|
||||||
|
<typeOfResource>text</typeOfResource>
|
||||||
|
<originInfo>
|
||||||
|
<place>
|
||||||
|
<placeTerm type="code" authority="marccountry">nyu</placeTerm>
|
||||||
|
</place>
|
||||||
|
<place>
|
||||||
|
<placeTerm type="text">New York</placeTerm>
|
||||||
|
</place>
|
||||||
|
<publisher>Miramax Books/Hyperion Books for Children</publisher>
|
||||||
|
<dateIssued>c2002</dateIssued>
|
||||||
|
<dateIssued encoding="marc">2002</dateIssued>
|
||||||
|
<edition>1st ed.</edition>
|
||||||
|
<issuance>monographic</issuance>
|
||||||
|
<frequency/>
|
||||||
|
</originInfo>
|
||||||
|
<language>
|
||||||
|
<languageTerm type="code" authority="iso639-2b">eng</languageTerm>
|
||||||
|
</language>
|
||||||
|
<physicalDescription>
|
||||||
|
<form authority="marcform">print</form>
|
||||||
|
<extent>500 p. ; 22 cm.</extent>
|
||||||
|
</physicalDescription>
|
||||||
|
<abstract>Ethan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy.</abstract>
|
||||||
|
<targetAudience authority="marctarget">juvenile</targetAudience>
|
||||||
|
<subject authority="lcshac">
|
||||||
|
<topic>Fantasy</topic>
|
||||||
|
</subject>
|
||||||
|
<subject authority="lcshac">
|
||||||
|
<topic>Baseball</topic>
|
||||||
|
<genre>Fiction</genre>
|
||||||
|
</subject>
|
||||||
|
<subject authority="lcshac">
|
||||||
|
<topic>Magic</topic>
|
||||||
|
<genre>Fiction</genre>
|
||||||
|
</subject>
|
||||||
|
<identifier type="isbn">0786808772</identifier>
|
||||||
|
<identifier type="isbn">0786816155 (pbk.)</identifier>
|
||||||
|
<recordInfo>
|
||||||
|
<descriptionStandard>aacr</descriptionStandard>
|
||||||
|
<recordContentSource authority="marcorg">DLC</recordContentSource>
|
||||||
|
<recordCreationDate encoding="marc">020805</recordCreationDate>
|
||||||
|
<recordChangeDate encoding="iso8601">20030616111422.0</recordChangeDate>
|
||||||
|
<recordIdentifier>12883376</recordIdentifier>
|
||||||
|
<recordOrigin>Converted from MARCXML to MODS version 3.4 using MARC21slim2MODS3-4.xsl
|
||||||
|
(Revision 1.70)</recordOrigin>
|
||||||
|
</recordInfo>
|
||||||
|
</mods>
|
Loading…
Reference in a new issue