From 7576665e7a2992d5e2b9788ff7a69ac5206a37d7 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 24 Sep 2021 19:17:11 +0200 Subject: [PATCH 1/7] Make simple XML encoder attribute marker configurable. --- metafacture-xml/build.gradle | 7 ++ .../org/metafacture/xml/SimpleXmlEncoder.java | 13 ++- .../metafacture/xml/SimpleXmlEncoderTest.java | 79 +++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/metafacture-xml/build.gradle b/metafacture-xml/build.gradle index c91c82c8e..7949ccd4d 100644 --- a/metafacture-xml/build.gradle +++ b/metafacture-xml/build.gradle @@ -26,3 +26,10 @@ dependencies { testImplementation 'org.mockito:mockito-core:2.5.5' testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21' } + +test { + testLogging { + showStandardStreams = true + exceptionFormat = 'full' + } +} diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java index 4cfb69c28..7a659e510 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java @@ -72,6 +72,7 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe namespaces = new HashMap(); @@ -146,6 +147,14 @@ public void setNamespaces(final Map namespaces) { this.namespaces = namespaces; } + public void setAttributeMarker(final String attributeMarker) { + this.attributeMarker = attributeMarker; + } + + public String getAttributeMarker() { + return attributeMarker; + } + @Override public void startRecord(final String identifier) { if (separateRoots) { @@ -195,8 +204,8 @@ public void literal(final String name, final String value) { if (name.isEmpty()) { element.setText(value); } - else if (name.startsWith(ATTRIBUTE_MARKER)) { - element.addAttribute(name.substring(1), value); + else if (name.startsWith(attributeMarker)) { + element.addAttribute(name.substring(attributeMarker.length()), value); } else { element.createChild(name).setText(value); diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java index 7ea246f0e..057a8edb0 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java @@ -179,6 +179,85 @@ public void shouldAddNamespaceWithEmptyKeyFromPropertiesFileAsDefaultNamespaceTo getResultXml()); } + @Test + public void testShouldEncodeMarkedLiteralsAsAttributes() { + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.literal(TAG, VALUE); + simpleXmlEncoder.literal("~attr", VALUE); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "value" + + "" + + "", + getResultXml()); + } + + @Test + public void testShouldNotEncodeMarkedEntitiesAsAttributes() { + simpleXmlEncoder.setAttributeMarker("*"); + + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.startEntity("~entity"); + simpleXmlEncoder.literal(TAG, VALUE); + simpleXmlEncoder.endEntity(); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "<~entity>" + + "value" + + "" + + "" + + "", + getResultXml()); + } + + @Test + public void testShouldNotEncodeLiteralsWithDifferentMarkerAsAttributes() { + simpleXmlEncoder.setAttributeMarker("*"); + + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.literal(TAG, VALUE); + simpleXmlEncoder.literal("~attr", VALUE); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "value" + + "<~attr>value" + + "" + + "", + getResultXml()); + } + + @Test + public void testShouldEncodeMarkedLiteralsWithConfiguredMarkerAsAttributes() { + final String marker = "**"; + simpleXmlEncoder.setAttributeMarker(marker); + + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.literal(TAG, VALUE); + simpleXmlEncoder.literal(marker + "attr", VALUE); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "value" + + "" + + "", + getResultXml()); + } + private void emitTwoRecords() { simpleXmlEncoder.startRecord("X"); simpleXmlEncoder.literal(TAG, VALUE); From 70fefd5e60ff41656b3acfe94d9be091127e69d3 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 24 Sep 2021 19:24:46 +0200 Subject: [PATCH 2/7] Make generic XML handler attribute marker configurable. Fixes #379. --- .../metafacture/xml/GenericXmlHandler.java | 13 +++++- .../xml/GenericXMLHandlerTest.java | 44 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java index abc3aaeb9..1b3b06670 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java @@ -40,12 +40,15 @@ @FluxCommand("handle-generic-xml") public final class GenericXmlHandler extends DefaultXmlPipe { + public static final String DEFAULT_ATTRIBUTE_MARKER = ""; + public static final String DEFAULT_RECORD_TAG = "record"; public static final boolean EMIT_NAMESPACE = false; private static final Pattern TABS = Pattern.compile("\t+"); + private String attributeMarker = DEFAULT_ATTRIBUTE_MARKER; private String recordTagName = DEFAULT_RECORD_TAG; private boolean inRecord; @@ -110,6 +113,14 @@ public boolean getEmitNamespace() { return this.emitNamespace; } + public void setAttributeMarker(final String attributeMarker) { + this.attributeMarker = attributeMarker; + } + + public String getAttributeMarker() { + return attributeMarker; + } + @Override public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { if (inRecord) { @@ -170,7 +181,7 @@ private void writeAttributes(final Attributes attributes) { for (int i = 0; i < length; ++i) { final String name = emitNamespace ? attributes.getQName(i) : attributes.getLocalName(i); final String value = attributes.getValue(i); - getReceiver().literal(name, value); + getReceiver().literal(attributeMarker + name, value); } } diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java index e376c24b1..7ba0a47f3 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java @@ -25,6 +25,7 @@ import org.metafacture.framework.StreamReceiver; import org.mockito.InOrder; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.xml.sax.helpers.AttributesImpl; @@ -141,6 +142,47 @@ public void shouldEmitNamespaceOnEntityElementAndAttribute() { final InOrder ordered = inOrder(receiver); ordered.verify(receiver).startEntity("ns:entity"); - ordered.verify(receiver).literal("ns:attr","attr-value"); + ordered.verify(receiver).literal("ns:attr", "attr-value"); } + + @Test + public void shouldNotEncodeAttributesAsMarkedLiterals() { + attributes.addAttribute("", "attr", "attr", "CDATA", "attr-value"); + genericXmlHandler.startElement("", "record", "record", attributes); + genericXmlHandler.endElement("", "record", "record"); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord(""); + ordered.verify(receiver).literal("attr", "attr-value"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + Mockito.verifyNoMoreInteractions(receiver); + } + + @Test + public void issue379_shouldEncodeAttributesAsLiteralsWithConfiguredMarker() { + final String marker = "~"; + genericXmlHandler.setAttributeMarker(marker); + + genericXmlHandler.startElement("", "record", "record", attributes); + attributes.addAttribute("", "authority", "authority", "CDATA", "marcrelator"); + attributes.addAttribute("", "type", "type", "CDATA", "text"); + genericXmlHandler.startElement("", "roleTerm", "roleTerm", attributes); + final char[] charData = "Author".toCharArray(); + genericXmlHandler.characters(charData, 0, charData.length); + genericXmlHandler.endElement("", "roleTerm", "roleTerm"); + genericXmlHandler.endElement("", "record", "record"); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord(""); + ordered.verify(receiver).startEntity("roleTerm"); + ordered.verify(receiver).literal(marker + "authority", "marcrelator"); + ordered.verify(receiver).literal(marker + "type", "text"); + ordered.verify(receiver).literal("value", "Author"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + Mockito.verifyNoMoreInteractions(receiver); + } + } From d2b0bdc5ced4dbdc23194b5c095acaba85339ef6 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 24 Sep 2021 20:04:05 +0200 Subject: [PATCH 3/7] Make MARC21 XML handler attribute marker configurable. Related to: #336, #379 --- metafacture-biblio/build.gradle | 7 ++++ .../biblio/marc21/MarcXmlHandler.java | 17 +++++++-- .../biblio/marc21/MarcXmlHandlerTest.java | 37 +++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/metafacture-biblio/build.gradle b/metafacture-biblio/build.gradle index 7faf64733..87bbff635 100644 --- a/metafacture-biblio/build.gradle +++ b/metafacture-biblio/build.gradle @@ -31,3 +31,10 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.5.5' } + +test { + testLogging { + showStandardStreams = true + exceptionFormat = 'full' + } +} diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java index 7de7fb1ef..37fa25fa9 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java @@ -38,6 +38,8 @@ @FluxCommand("handle-marcxml") public final class MarcXmlHandler extends DefaultXmlPipe { + public static final String DEFAULT_ATTRIBUTE_MARKER = ""; + private static final String SUBFIELD = "subfield"; private static final String DATAFIELD = "datafield"; private static final String CONTROLFIELD = "controlfield"; @@ -45,6 +47,8 @@ public final class MarcXmlHandler extends DefaultXmlPipe { private static final String NAMESPACE = "http://www.loc.gov/MARC21/slim"; private static final String LEADER = "leader"; private static final String TYPE = "type"; + + private String attributeMarker = DEFAULT_ATTRIBUTE_MARKER; private String currentTag = ""; private String namespace = NAMESPACE; private StringBuilder builder = new StringBuilder(); @@ -60,6 +64,14 @@ private boolean checkNamespace(final String uri) { return namespace == null || namespace.equals(uri); } + public void setAttributeMarker(final String attributeMarker) { + this.attributeMarker = attributeMarker; + } + + public String getAttributeMarker() { + return attributeMarker; + } + @Override public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { if (SUBFIELD.equals(localName)) { @@ -75,7 +87,7 @@ else if (CONTROLFIELD.equals(localName)) { } else if (RECORD.equals(localName) && checkNamespace(uri)) { getReceiver().startRecord(""); - getReceiver().literal(TYPE, attributes.getValue(TYPE)); + getReceiver().literal(attributeMarker + TYPE, attributes.getValue(TYPE)); } else if (LEADER.equals(localName)) { builder = new StringBuilder(); @@ -87,18 +99,15 @@ else if (LEADER.equals(localName)) { public void endElement(final String uri, final String localName, final String qName) throws SAXException { if (SUBFIELD.equals(localName)) { getReceiver().literal(currentTag, builder.toString().trim()); - } else if (DATAFIELD.equals(localName)) { getReceiver().endEntity(); } else if (CONTROLFIELD.equals(localName)) { getReceiver().literal(currentTag, builder.toString().trim()); - } else if (RECORD.equals(localName) && checkNamespace(uri)) { getReceiver().endRecord(); - } else if (LEADER.equals(localName)) { getReceiver().literal(currentTag, builder.toString()); diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java index 094b4547e..3902a6041 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java @@ -23,7 +23,9 @@ import org.junit.Before; import org.junit.Test; import org.metafacture.framework.StreamReceiver; +import org.mockito.InOrder; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; @@ -130,4 +132,39 @@ public void issue330ShouldOptionallyRecognizeRecordsWithoutNamespace() verifyNoMoreInteractions(receiver); } + @Test + public void shouldNotEncodeTypeAttributeAsMarkedLiteral() throws SAXException { + final AttributesImpl attributes = new AttributesImpl(); + attributes.addAttribute(NAMESPACE, "type", "type", "CDATA", "bibliographic"); + + marcXmlHandler.startElement(NAMESPACE, RECORD, "", attributes); + marcXmlHandler.endElement(NAMESPACE, RECORD, ""); + + final InOrder ordered = Mockito.inOrder(receiver); + ordered.verify(receiver).startRecord(""); + ordered.verify(receiver).literal(TYPE, "bibliographic"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + verifyNoMoreInteractions(receiver); + } + + @Test + public void issue336_shouldEncodeTypeAttributeAsLiteralWithConfiguredMarker() throws SAXException { + final String marker = "~"; + marcXmlHandler.setAttributeMarker(marker); + + final AttributesImpl attributes = new AttributesImpl(); + attributes.addAttribute(NAMESPACE, "type", "type", "CDATA", "bibliographic"); + + marcXmlHandler.startElement(NAMESPACE, RECORD, "", attributes); + marcXmlHandler.endElement(NAMESPACE, RECORD, ""); + + final InOrder ordered = Mockito.inOrder(receiver); + ordered.verify(receiver).startRecord(""); + ordered.verify(receiver).literal(marker + TYPE, "bibliographic"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + verifyNoMoreInteractions(receiver); + } + } From 56c96a3d2b8485adc677a2773cccbbe6d028bbf6 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 24 Sep 2021 20:27:23 +0200 Subject: [PATCH 4/7] Make generic XML handler value tag name configurable. --- .../metafacture/xml/GenericXmlHandler.java | 13 ++++++++++- .../xml/GenericXMLHandlerTest.java | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java index 1b3b06670..ef7110070 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java @@ -44,12 +44,15 @@ public final class GenericXmlHandler extends DefaultXmlPipe { public static final String DEFAULT_RECORD_TAG = "record"; + public static final String DEFAULT_VALUE_TAG = "value"; + public static final boolean EMIT_NAMESPACE = false; private static final Pattern TABS = Pattern.compile("\t+"); private String attributeMarker = DEFAULT_ATTRIBUTE_MARKER; private String recordTagName = DEFAULT_RECORD_TAG; + private String valueTagName = DEFAULT_VALUE_TAG; private boolean inRecord; private StringBuilder valueBuffer = new StringBuilder(); @@ -95,6 +98,14 @@ public String getRecordTagName() { return recordTagName; } + public void setValueTagName(final String valueTagName) { + this.valueTagName = valueTagName; + } + + public String getValueTagName() { + return valueTagName; + } + /** * Triggers namespace awareness. If set to "true" input data like "foo:bar" * will be passed through as "foo:bar". For backward compatibility the default @@ -170,7 +181,7 @@ public void characters(final char[] chars, final int start, final int length) { private void writeValue() { final String value = valueBuffer.toString(); if (!value.trim().isEmpty()) { - getReceiver().literal("value", value.replace('\n', ' ')); + getReceiver().literal(valueTagName, value.replace('\n', ' ')); } valueBuffer = new StringBuilder(); } diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java index 7ba0a47f3..ff35baad8 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java @@ -133,6 +133,28 @@ public void shouldEmitPCDataAsALiteralNamedValue() { ordered.verify(receiver).literal("value", "char-data"); } + @Test + public void shouldEmitPCDataAsALiteralWithConfiguredValueTagName() { + final String name = "data"; + genericXmlHandler.setValueTagName(name); + + final char[] charData = "char-data".toCharArray(); + genericXmlHandler.startElement("", "record", "record", attributes); + genericXmlHandler.startElement("", "entity", "entity", attributes); + genericXmlHandler.characters(charData, 0, charData.length); + genericXmlHandler.endElement("", "entity", "entity"); + genericXmlHandler.endElement("", "record", "record"); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord(""); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal(name, "char-data"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + Mockito.verifyNoMoreInteractions(receiver); + } + @Test public void shouldEmitNamespaceOnEntityElementAndAttribute() { genericXmlHandler.setEmitNamespace(true); From 881911519234fa7ed69688840b684970223b6ac2 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 24 Sep 2021 20:41:42 +0200 Subject: [PATCH 5/7] Make simple XML encoder value tag name configurable. Fixes #379. --- .../org/metafacture/xml/SimpleXmlEncoder.java | 12 ++++- .../metafacture/xml/SimpleXmlEncoderTest.java | 53 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java index 7a659e510..f2844c325 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java @@ -55,6 +55,7 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe namespaces = new HashMap(); private boolean writeRootTag = true; private boolean writeXmlHeader = true; @@ -97,6 +99,14 @@ public void setRecordTag(final String tag) { recordTag = tag; } + public void setValueTag(final String valueTag) { + this.valueTag = valueTag; + } + + public String getValueTag() { + return valueTag; + } + public void setNamespaceFile(final String file) { final Properties properties; try { @@ -201,7 +211,7 @@ public void endEntity() { @Override public void literal(final String name, final String value) { - if (name.isEmpty()) { + if (name.isEmpty() || name.equals(valueTag)) { element.setText(value); } else if (name.startsWith(attributeMarker)) { diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java index 057a8edb0..9c65dd328 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java @@ -179,6 +179,59 @@ public void shouldAddNamespaceWithEmptyKeyFromPropertiesFileAsDefaultNamespaceTo getResultXml()); } + @Test + public void testShouldEncodeEmptyLiteralsAsText() { + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.literal("", VALUE); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "value" + + "" + + "", + getResultXml()); + } + + @Test + public void testShouldNotEncodeLiteralsWithDifferentValueTagNameAsText() { + simpleXmlEncoder.setValueTag("data"); + + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.literal(TAG, VALUE); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "value" + + "" + + "", + getResultXml()); + } + + @Test + public void issue379_testShouldEncodeConfiguredValueLiteralsAsText() { + final String name = "data"; + simpleXmlEncoder.setValueTag(name); + + simpleXmlEncoder.startRecord(""); + simpleXmlEncoder.literal(name, VALUE); + simpleXmlEncoder.endRecord(); + simpleXmlEncoder.closeStream(); + + assertEquals("" + + "" + + "" + + "value" + + "" + + "", + getResultXml()); + } + @Test public void testShouldEncodeMarkedLiteralsAsAttributes() { simpleXmlEncoder.startRecord(""); From 66121486564cd8f34c4734864dd208e85f4393bd Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Mon, 27 Sep 2021 23:34:02 +0200 Subject: [PATCH 6/7] Treat empty literal name as default value tag name. Related to #394 (8819115). --- .../org/metafacture/xml/SimpleXmlEncoder.java | 4 ++-- .../metafacture/xml/SimpleXmlEncoderTest.java | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java index f2844c325..ba481ed0f 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java @@ -55,7 +55,7 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe" + + "" + + "" + + "value" + + "" + + "", + getResultXml()); + } + @Test public void testShouldNotEncodeLiteralsWithDifferentValueTagNameAsText() { simpleXmlEncoder.setValueTag("data"); From d6e68ff239066af136dcbade5c2bc241b4f4fd61 Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Mon, 27 Sep 2021 19:28:03 +0200 Subject: [PATCH 7/7] Reuse some public static variables --- .../org/metafacture/biblio/marc21/MarcXmlHandler.java | 2 -- .../metafacture/framework/helpers/DefaultXmlPipe.java | 5 +++++ .../java/org/metafacture/xml/GenericXmlHandler.java | 6 ------ .../java/org/metafacture/xml/SimpleXmlEncoder.java | 11 ++++------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java index 37fa25fa9..98d7d082e 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java @@ -38,8 +38,6 @@ @FluxCommand("handle-marcxml") public final class MarcXmlHandler extends DefaultXmlPipe { - public static final String DEFAULT_ATTRIBUTE_MARKER = ""; - private static final String SUBFIELD = "subfield"; private static final String DATAFIELD = "datafield"; private static final String CONTROLFIELD = "controlfield"; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java index 773bcdad4..a429fd094 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java @@ -38,6 +38,11 @@ */ public class DefaultXmlPipe extends DefaultSender implements XmlPipe { + public static final String DEFAULT_ATTRIBUTE_MARKER = ""; + public static final String DEFAULT_RECORD_TAG = "record"; + public static final String DEFAULT_ROOT_TAG = "records"; + public static final String DEFAULT_VALUE_TAG = "value"; + public DefaultXmlPipe() { } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java index ef7110070..a2813f6fa 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java @@ -40,12 +40,6 @@ @FluxCommand("handle-generic-xml") public final class GenericXmlHandler extends DefaultXmlPipe { - public static final String DEFAULT_ATTRIBUTE_MARKER = ""; - - public static final String DEFAULT_RECORD_TAG = "record"; - - public static final String DEFAULT_VALUE_TAG = "value"; - public static final boolean EMIT_NAMESPACE = false; private static final Pattern TABS = Pattern.compile("\t+"); diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java index ba481ed0f..cff74368e 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java @@ -26,6 +26,7 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import org.metafacture.framework.helpers.DefaultXmlPipe; import java.io.IOException; import java.net.URL; @@ -53,10 +54,6 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe namespaces = new HashMap(); private boolean writeRootTag = true; private boolean writeXmlHeader = true;