Skip to content

Commit 045708d

Browse files
committed
Add original OAI-PMH opener by @dr0i
From https://github.com/hbz/metafacture-core/blob/4.0.0-HBZ-SNAPSHOT /src/main/java/org/culturegraph/mf/stream/source/OaiPmhOpener.java Sample flux usage: "https://duepublico2.uni-due.de/servlets/OAIDataProvider" |open-oaipmh(metadataPrefix="mods", dateFrom="2020-04-14") |decode-xml |handle-generic-xml |encode-formeta(style="multiline") |write("stdout");
1 parent eaaf750 commit 045708d

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

metafacture-biblio/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies {
2121
api project(':metafacture-framework')
2222
implementation project(':metafacture-commons')
2323
implementation project(':metafacture-flowcontrol')
24+
implementation 'org.dspace:oclc-harvester2:0.1.12'
25+
implementation 'xalan:xalan:2.7.1'
2426
testImplementation 'junit:junit:4.12'
2527
testImplementation 'org.mockito:mockito-core:2.5.5'
2628
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* Copyright 2013 Pascal Christoph.
2+
* Licensed under the Eclipse Public License 1.0 */
3+
4+
package org.metafacture.biblio;
5+
6+
import java.io.ByteArrayInputStream;
7+
import java.io.ByteArrayOutputStream;
8+
import java.io.IOException;
9+
import java.io.InputStreamReader;
10+
import java.io.Reader;
11+
12+
import javax.xml.parsers.ParserConfigurationException;
13+
import javax.xml.transform.TransformerException;
14+
15+
import org.metafacture.framework.MetafactureException;
16+
import org.metafacture.framework.ObjectReceiver;
17+
import org.metafacture.framework.annotations.Description;
18+
import org.metafacture.framework.annotations.In;
19+
import org.metafacture.framework.annotations.Out;
20+
import org.metafacture.framework.helpers.DefaultObjectPipe;
21+
import org.xml.sax.SAXException;
22+
23+
import ORG.oclc.oai.harvester2.app.RawWrite;
24+
25+
/**
26+
* Opens an OAI-PMH stream and passes a reader to the receiver.
27+
*
28+
* @author Pascal Christoph (dr0i)
29+
*
30+
*/
31+
@Description("Opens an OAI-PMH stream and passes a reader to the receiver. Mandatory arguments are: BASE_URL, DATE_FROM, DATE_UNTIL, METADATA_PREFIX, SET_SPEC .")
32+
@In(String.class)
33+
@Out(java.io.Reader.class)
34+
public final class OaiPmhOpener extends
35+
DefaultObjectPipe<String, ObjectReceiver<Reader>> {
36+
37+
private String encoding = "UTF-8";
38+
39+
final ByteArrayOutputStream OUTPUT_STREAM = new ByteArrayOutputStream();
40+
41+
private String dateFrom;
42+
43+
private String dateUntil;
44+
45+
private String setSpec;
46+
47+
private String metadataPrefix;
48+
49+
/**
50+
* Default constructor
51+
*/
52+
public OaiPmhOpener() {
53+
54+
}
55+
56+
/**
57+
* Sets the encoding to use. The default setting is UTF-8.
58+
*
59+
* @param encoding new default encoding
60+
*/
61+
public void setEncoding(final String encoding) {
62+
this.encoding = encoding;
63+
}
64+
65+
/**
66+
* Sets the beginning of the retrieving of updated data. The form is
67+
* YYYY-MM-DD .
68+
*
69+
* @param dateFrom The form is YYYY-MM-DD .
70+
*/
71+
public void setDateFrom(final String dateFrom) {
72+
this.dateFrom = dateFrom;
73+
}
74+
75+
/**
76+
* Sets the end of the retrieving of updated data. The form is YYYY-MM-DD .
77+
*
78+
* @param dateUntil The form is YYYY-MM-DD .
79+
*/
80+
public void setDateUntil(final String dateUntil) {
81+
this.dateUntil = dateUntil;
82+
}
83+
84+
/**
85+
* Sets the OAI-PM metadata prefix .
86+
*
87+
* @param metadataPrefix the OAI-PM metadata prefix
88+
*/
89+
public void setMetadataPrefix(final String metadataPrefix) {
90+
this.metadataPrefix = metadataPrefix;
91+
}
92+
93+
/**
94+
* Sets the OAI-PM set specification .
95+
*
96+
* @param setSpec th OAI-PM set specification
97+
*/
98+
public void setSetSpec(final String setSpec) {
99+
this.setSpec = setSpec;
100+
}
101+
102+
@Override
103+
public void process(final String baseUrl) {
104+
105+
try {
106+
RawWrite.run(baseUrl, this.dateFrom, this.dateUntil, this.metadataPrefix,
107+
this.setSpec, OUTPUT_STREAM);
108+
} catch (IOException e) {
109+
e.printStackTrace();
110+
} catch (ParserConfigurationException e) {
111+
e.printStackTrace();
112+
} catch (SAXException e) {
113+
e.printStackTrace();
114+
} catch (TransformerException e) {
115+
e.printStackTrace();
116+
} catch (NoSuchFieldException e) {
117+
e.printStackTrace();
118+
}
119+
try {
120+
getReceiver().process(
121+
new InputStreamReader(new ByteArrayInputStream(OUTPUT_STREAM
122+
.toByteArray()), encoding));
123+
} catch (IOException e) {
124+
throw new MetafactureException(e);
125+
}
126+
}
127+
}

metafacture-biblio/src/main/resources/flux-commands.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ handle-mabxml org.metafacture.biblio.AlephMabXmlHandler
2727
handle-comarcxml org.metafacture.biblio.ComarcXmlHandler
2828
decode-aseq org.metafacture.biblio.AseqDecoder
2929
decode-mab org.metafacture.biblio.MabDecoder
30+
31+
open-oaipmh org.metafacture.biblio.OaiPmhOpener

0 commit comments

Comments
 (0)