add line feed control to JSON writer, remove Asciidoclet for now

This commit is contained in:
Jörg Prante 2018-03-14 10:39:03 +01:00
parent 8499915b3a
commit d8426fcfc6
10 changed files with 49 additions and 23 deletions

View file

@ -31,18 +31,16 @@ repositories {
} }
configurations { configurations {
asciidoclet
wagon wagon
} }
dependencies { dependencies {
testCompile "org.junit.vintage:junit-vintage-engine:${project.property('junit-vintage.version')}"
testCompile "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}" testCompile "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}"
testCompile "org.xbib:content-core:${project.property('xbib-content.version')}" testCompile "org.xbib:content-core:${project.property('xbib-content.version')}"
testCompile "junit:junit:${project.property('junit.version')}"
testCompile "xalan:xalan:${project.property('xalan.version')}" testCompile "xalan:xalan:${project.property('xalan.version')}"
testCompile "org.xmlunit:xmlunit-matchers:${project.property('xmlunit-matchers.version')}" testCompile "org.xmlunit:xmlunit-matchers:${project.property('xmlunit-matchers.version')}"
testCompile "com.github.stefanbirkner:system-rules:${project.property('system-rules.version')}" testCompile "com.github.stefanbirkner:system-rules:${project.property('system-rules.version')}"
asciidoclet "org.xbib:asciidoclet:${project.property('asciidoclet.version')}"
wagon "org.apache.maven.wagon:wagon-ssh:${project.property('wagon.version')}" wagon "org.apache.maven.wagon:wagon-ssh:${project.property('wagon.version')}"
} }
@ -78,18 +76,6 @@ asciidoctor {
'source-highlighter': 'coderay' 'source-highlighter': 'coderay'
} }
javadoc {
options.docletpath = configurations.asciidoclet.files.asType(List)
options.doclet = 'org.xbib.asciidoclet.Asciidoclet'
options.overview = "src/docs/asciidoclet/overview.adoc"
options.addStringOption "-base-dir", "${projectDir}"
options.addStringOption "-attribute",
"name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}"
configure(options) {
noTimestamp = true
}
}
clean { clean {
delete 'out' delete 'out'
} }

View file

@ -1,12 +1,11 @@
group = org.xbib group = org.xbib
name = marc name = marc
version = 1.2.0 version = 1.2.1
xbib-content.version = 1.3.0 xbib-content.version = 1.3.0
xbib-bibliographic-character-sets.version = 1.0.0 xbib-bibliographic-character-sets.version = 1.0.0
xalan.version = 2.7.2 xalan.version = 2.7.2
xmlunit-matchers.version = 2.3.0 xmlunit-matchers.version = 2.3.0
system-rules.version = 1.16.0 system-rules.version = 1.16.0
asciidoclet.version = 1.6.0.0 junit-vintage.version = 4.12.0
junit.version = 4.12
wagon.version = 3.0.0 wagon.version = 3.0.0

Binary file not shown.

View file

@ -1,6 +1,6 @@
#Wed Feb 07 00:10:24 CET 2018 #Wed Mar 14 10:32:45 CET 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

View file

@ -285,6 +285,7 @@ public final class Marc {
/** /**
* Pass a given chunk stream to a MARC generator, chunk by chunk. * Pass a given chunk stream to a MARC generator, chunk by chunk.
* Can process any MARC streams, not only separator streams. * Can process any MARC streams, not only separator streams.
* @param type the MARC record type
* @param stream a chunk stream * @param stream a chunk stream
* @param withCollection true if stream should be wrapped into a collection element * @param withCollection true if stream should be wrapped into a collection element
* @return the number of chunks in the stream * @return the number of chunks in the stream

View file

@ -115,6 +115,7 @@ public class MarcRecord extends LinkedHashMap<String, Object> {
/** /**
* Return the MARC fields of this record with a given tag. * Return the MARC fields of this record with a given tag.
* *
* @param tag the MARC tag
* @return the MARC field list matching the given tag. * @return the MARC field list matching the given tag.
*/ */
public List<MarcField> getFields(String tag) { public List<MarcField> getFields(String tag) {

View file

@ -55,7 +55,6 @@ public class MarcWriter extends MarcContentHandler implements Flushable, Closeab
* Create a MarcWriter on an underlying output stream. * Create a MarcWriter on an underlying output stream.
* @param out the underlying output stream * @param out the underlying output stream
* @param charset the character set * @param charset the character set
* @throws IOException if writer can not be created
*/ */
public MarcWriter(OutputStream out, Charset charset) { public MarcWriter(OutputStream out, Charset charset) {
this(out, charset, DEFAULT_BUFFER_SIZE); this(out, charset, DEFAULT_BUFFER_SIZE);
@ -66,7 +65,6 @@ public class MarcWriter extends MarcContentHandler implements Flushable, Closeab
* @param out the underlying output stream * @param out the underlying output stream
* @param charset the character set * @param charset the character set
* @param buffersize the buffer size writing to the underlying output stream * @param buffersize the buffer size writing to the underlying output stream
* @throws IOException if writer can not be created
*/ */
public MarcWriter(OutputStream out, Charset charset, int buffersize) { public MarcWriter(OutputStream out, Charset charset, int buffersize) {
this.out = new SeparatorOutputStream(out, buffersize); this.out = new SeparatorOutputStream(out, buffersize);

View file

@ -269,7 +269,7 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
sb.append("]"); sb.append("]");
} }
if (style == Style.ELASTICSEARCH_BULK) { if (style == Style.ELASTICSEARCH_BULK) {
// finish with line-feed // finish with line-feed "\n", not with System.lineSeparator()
sb.append("\n"); sb.append("\n");
} }
try { try {
@ -435,6 +435,10 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo
return exception; return exception;
} }
public void writeLine() throws IOException {
writer.write(System.lineSeparator());
}
private void handleException(IOException e) { private void handleException(IOException e) {
exception = e; exception = e;
if (fatalErrors) { if (fatalErrors) {

View file

@ -312,4 +312,39 @@ public class MarcJsonWriterTest {
assertNull(writer.getException()); assertNull(writer.getException());
} }
} }
@Test
public void testJsonWriterWithMultipleInput() throws Exception {
File file = File.createTempFile("multi.", ".json");
file.deleteOnExit();
FileOutputStream out = new FileOutputStream(file);
try (MarcJsonWriter writer = new MarcJsonWriter(out, MarcJsonWriter.Style.ARRAY)) {
writer.beginCollection();
try (InputStream inputStream = getClass().getResource("/org/xbib/marc/summerland.mrc").openStream()) {
Marc.builder()
.setFormat(MarcXchangeConstants.MARCXCHANGE_FORMAT)
.setType(MarcXchangeConstants.BIBLIOGRAPHIC_TYPE)
.setInputStream(inputStream)
.setCharset(Charset.forName("ANSEL"))
.setMarcRecordListener(writer)
.build()
.writeRecords();
}
writer.writeLine();
try (InputStream inputStream = getClass().getResource("/org/xbib/marc/chabon.mrc").openStream()) {
Marc.builder()
.setFormat(MarcXchangeConstants.MARCXCHANGE_FORMAT)
.setType(MarcXchangeConstants.BIBLIOGRAPHIC_TYPE)
.setInputStream(inputStream)
.setCharset(Charset.forName("ANSEL"))
.setMarcRecordListener(writer)
.build()
.writeRecords();
}
writer.endCollection();
}
assertStream("multi", getClass().getResource("/org/xbib/marc/json/multi.json").openStream(),
new FileInputStream(file));
}
} }

View file

@ -0,0 +1,2 @@
[{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00714cam a2200205 a 4500","001":["12883376"],"005":["20030616111422.0"],"008":["020805s2002 nyu j 000 1 eng "],"020":[{"__":[{"a":"0786808772"}]},{"__":[{"a":"0786816155 (pbk.)"}]}],"040":[{"__":[{"a":"DLC"},{"c":"DLC"},{"d":"DLC"}]}],"100":[{"1_":[{"a":"Chabon, Michael."}]}],"245":[{"10":[{"a":"Summerland /"},{"c":"Michael Chabon."}]}],"250":[{"__":[{"a":"1st ed."}]}],"260":[{"__":[{"a":"New York :"},{"b":"Miramax Books/Hyperion Books for Children,"},{"c":"c2002."}]}],"300":[{"__":[{"a":"500 p. ;"},{"c":"22 cm."}]}],"520":[{"__":[{"a":"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."}]}],"650":[{"_1":[{"a":"Fantasy."}]},{"_1":[{"a":"Baseball"},{"v":"Fiction."}]},{"_1":[{"a":"Magic"},{"v":"Fiction."}]}]}
,{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00759cam a2200229 a 4500","001":["11939876"],"005":["20041229190604.0"],"008":["000313s2000 nyu 000 1 eng "],"020":[{"__":[{"a":"0679450041 (acid-free paper)"}]}],"040":[{"__":[{"a":"DLC"},{"c":"DLC"},{"d":"DLC"}]}],"100":[{"1_":[{"a":"Chabon, Michael."}]}],"245":[{"14":[{"a":"The amazing adventures of Kavalier and Clay :"},{"b":"a novel /"},{"c":"Michael Chabon."}]}],"260":[{"__":[{"a":"New York :"},{"b":"Random House,"},{"c":"c2000."}]}],"300":[{"__":[{"a":"639 p. ;"},{"c":"25 cm."}]}],"650":[{"_0":[{"a":"Comic books, strips, etc."},{"x":"Authorship"},{"v":"Fiction."}]},{"_0":[{"a":"Heroes in mass media"},{"v":"Fiction."}]},{"_0":[{"a":"Czech Americans"},{"v":"Fiction."}]},{"_0":[{"a":"Young men"},{"v":"Fiction."}]},{"_0":[{"a":"Cartoonists"},{"v":"Fiction."}]}],"651":[{"_0":[{"a":"New York (N.Y.)"},{"v":"Fiction."}]}],"655":[{"_7":[{"a":"Humorous stories."},{"2":"gsafd"}]},{"_7":[{"a":"Bildungsromane."},{"2":"gsafd"}]}]},{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00714cam a2200205 a 4500","001":["12883376"],"005":["20030616111422.0"],"008":["020805s2002 nyu j 000 1 eng "],"020":[{"__":[{"a":"0786808772"}]},{"__":[{"a":"0786816155 (pbk.)"}]}],"040":[{"__":[{"a":"DLC"},{"c":"DLC"},{"d":"DLC"}]}],"100":[{"1_":[{"a":"Chabon, Michael."}]}],"245":[{"10":[{"a":"Summerland /"},{"c":"Michael Chabon."}]}],"250":[{"__":[{"a":"1st ed."}]}],"260":[{"__":[{"a":"New York :"},{"b":"Miramax Books/Hyperion Books for Children,"},{"c":"c2002."}]}],"300":[{"__":[{"a":"500 p. ;"},{"c":"22 cm."}]}],"520":[{"__":[{"a":"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."}]}],"650":[{"_1":[{"a":"Fantasy."}]},{"_1":[{"a":"Baseball"},{"v":"Fiction."}]},{"_1":[{"a":"Magic"},{"v":"Fiction."}]}]}]