diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21XmlEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21XmlEncoder.java index e26fb09a2..d726c4c9e 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21XmlEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21XmlEncoder.java @@ -17,13 +17,10 @@ import org.metafacture.framework.FluxCommand; -import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.StreamReceiver; import org.metafacture.framework.annotations.Description; import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; -import org.metafacture.framework.helpers.DefaultStreamPipe; - /** * Acts as a wrapper: pipes input to Marc21Encoder which output is piped to Marc21Decoder which output is piped to MarcXmlEncoder. @@ -35,7 +32,7 @@ @Out(String.class) @Description("Encodes MARC21 records as MARCXML. It wraps 'encode-marc21 | decode-marc21 | encode-marcxml ' to generate MARCXML more safely, especially when the building the 'leader'.") @FluxCommand("encode-marc21xml") -public class Marc21XmlEncoder extends DefaultStreamPipe> implements MarcXmlEncoderInterface { +public class Marc21XmlEncoder extends MarcXmlEncoderAbstract { private final Marc21Decoder marc21Decoder = new Marc21Decoder(); private final Marc21Encoder marc21Encoder = new Marc21Encoder (); private final MarcXmlEncoder marcXmlEncoder =new MarcXmlEncoder(); @@ -81,7 +78,7 @@ protected void onCloseStream() { } @Override - protected void onResetStream() { + public void onResetStream() { marc21Encoder.resetStream(); } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java index 4a4f20717..930171a6c 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java @@ -40,7 +40,7 @@ @In(StreamReceiver.class) @Out(String.class) @FluxCommand("encode-marcxml") -public class MarcXmlEncoder extends DefaultStreamPipe> implements MarcXmlEncoderInterface { +public class MarcXmlEncoder extends MarcXmlEncoderAbstract { public static final String NAMESPACE_NAME = "marc"; public static final String XML_ENCODING = "UTF-8"; @@ -282,7 +282,7 @@ else if (!writeLeader(currentEntity, value)) { } @Override - protected void onResetStream() { + public void onResetStream() { if (!atStreamStart) { writeFooter(); } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoderAbstract.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoderAbstract.java new file mode 100644 index 000000000..e941aa935 --- /dev/null +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoderAbstract.java @@ -0,0 +1,9 @@ +package org.metafacture.biblio.marc21; + +import org.metafacture.framework.ObjectReceiver; +import org.metafacture.framework.helpers.DefaultStreamPipe; + +public abstract class MarcXmlEncoderAbstract extends DefaultStreamPipe> implements MarcXmlEncoderInterface { + public void onResetStream(){ + } +} diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoderInterface.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoderInterface.java new file mode 100644 index 000000000..075ffc213 --- /dev/null +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoderInterface.java @@ -0,0 +1,49 @@ +package org.metafacture.biblio.marc21; + +public interface MarcXmlEncoderInterface { + + /** + * Sets the flag to decide whether to emit the {@value MarcXmlEncoder#NAMESPACE_NAME} + * namespace + * + * @param emitNamespace true if the namespace is emitted, otherwise false + */ + void setEmitNamespace(final boolean emitNamespace); + + /** + * Sets the flag to decide whether to omit the XML declaration. + * + * Default value: {@value MarcXmlEncoder#OMIT_XML_DECLARATION} + * + * @param currentOmitXmlDeclaration true if the XML declaration is omitted, otherwise + * false + */ + void omitXmlDeclaration(final boolean currentOmitXmlDeclaration); + + /** + * Sets the XML version. + * + * Default value: {@value MarcXmlEncoder#XML_VERSION} + * + * @param xmlVersion the XML version + */ + void setXmlVersion(final String xmlVersion); + + /** + * Sets the XML encoding. + * + * Default value: {@value MarcXmlEncoder#XML_ENCODING} + * + * @param xmlEncoding the XML encoding + */ + void setXmlEncoding(final String xmlEncoding); + + /** + * Formats the resulting xml by indentation. Aka "pretty printing". + * + * Default value: {@value MarcXmlEncoder#PRETTY_PRINTED} + * + * @param formatted true if formatting is activated, otherwise false + */ + void setFormatted(final boolean formatted); +} \ No newline at end of file diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java index da19ab7bd..4cb14d38c 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java @@ -82,6 +82,7 @@ public void setup() { marcXmlHandlerWrapper =new Marc21XmlEncoder(); + marcXmlHandlerWrapper.setFormatted(true); marc21Decoder.setReceiver(marcXmlHandlerWrapper); marcXmlHandlerWrapper.setReceiver(receiver); diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java index 679c2c9ea..5ffa1933b 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java @@ -24,7 +24,10 @@ import org.junit.Before; import org.junit.Test; import org.metafacture.framework.MetafactureException; +import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.helpers.DefaultObjectReceiver; +import org.metafacture.framework.helpers.DefaultStreamPipe; +import org.mockito.Mock; /** * Tests for class {@link MarcXmlEncoder}. @@ -34,7 +37,7 @@ * */ -public class MarcXmlEncoderTest { + class MarcXmlEncoderTest { private static final String XML_DECLARATION = ""; private static final String XML_1_DECLARATION = ""; @@ -49,11 +52,17 @@ public class MarcXmlEncoderTest { private static final String RECORD_ID = "92005291"; private static StringBuilder resultCollector; - private static MarcXmlEncoder encoder; + private static MarcXmlEncoderAbstract encoder; + // private DefaultObjectReceiver receiver = new DefaultObjectReceiver(); + + MarcXmlEncoderTest(MarcXmlEncoderAbstract encoder){ + MarcXmlEncoderTest.encoder=encoder; + // encoder.setReceiver(receiver); + setUp(); + } @Before public void setUp() { - encoder = new MarcXmlEncoder(); encoder.setFormatted(false); encoder.setReceiver(new DefaultObjectReceiver() { @Override @@ -68,7 +77,7 @@ public void process(final String obj) { public void tearDown() { } - private void addOneRecord(MarcXmlEncoder encoder) { + private void addOneRecord(MarcXmlEncoderAbstract encoder) { encoder.startRecord(RECORD_ID); encoder.literal("001", RECORD_ID); encoder.startEntity("010 "); diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderWrapperTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderWrapperTest.java new file mode 100644 index 000000000..0e7b32036 --- /dev/null +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderWrapperTest.java @@ -0,0 +1,13 @@ +package org.metafacture.biblio.marc21; + +import org.junit.Test; + +public class MarcXmlEncoderWrapperTest { + @Test + public void testMarcXmlEncoder() { + MarcXmlEncoderTest test = new MarcXmlEncoderTest(new MarcXmlEncoder()); + test.createAnRecordWithLeader(); + MarcXmlEncoderTest test1 = new MarcXmlEncoderTest(new Marc21XmlEncoder()); + test1.createAnRecordWithLeader(); + } +}