Skip to content

Commit 57f6a71

Browse files
committed
Make "ignorenamespace" order-independent (#569)
Even if a namespace is set after setting "ignorenamespace" to "true" the namespace is ignored.
1 parent 7513885 commit 57f6a71

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public final class MarcXmlHandler extends DefaultXmlPipe<StreamReceiver> {
5151
private String currentTag = "";
5252
private String namespace = NAMESPACE;
5353
private StringBuilder builder = new StringBuilder();
54+
private boolean ignoreNamespace;
5455

5556
/**
5657
* Creates an instance of {@link MarcXmlHandler}.
@@ -78,13 +79,11 @@ public void setNamespace(final String namespace) {
7879
* @param ignoreNamespace true if the namespace should be ignored
7980
*/
8081
public void setIgnoreNamespace(final boolean ignoreNamespace) {
81-
if (ignoreNamespace) {
82-
this.namespace = null;
83-
}
82+
this.ignoreNamespace = ignoreNamespace;
8483
}
8584

8685
private boolean checkNamespace(final String uri) {
87-
return namespace == null || namespace.equals(uri);
86+
return namespace == null || ignoreNamespace || namespace.equals(uri);
8887
}
8988

9089
/**

metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void shouldRecognizeRecordsWithoutNamespace()
161161

162162
verifyNoMoreInteractions(receiver);
163163
}
164+
164165
@Test
165166
public void shouldNotRecognizeRecordsWithNamespaceWhenOptionallyWithoutNamespace()
166167
throws SAXException {
@@ -189,6 +190,23 @@ public void issue569ShouldRecognizeRecordsWithAndWithoutNamespace()
189190
verifyNoMoreInteractions(receiver);
190191
}
191192

193+
@Test
194+
public void issue569ShouldRecognizeRecordsWithAndWithoutNamespaceOrderIndependently()
195+
throws SAXException {
196+
final AttributesImpl attributes = new AttributesImpl();
197+
198+
marcXmlHandler.setIgnoreNamespace(true);
199+
marcXmlHandler.setNamespace("");
200+
marcXmlHandler.startElement(null, RECORD, "", attributes);
201+
marcXmlHandler.endElement(NAMESPACE, RECORD, "");
202+
203+
verify(receiver).startRecord("");
204+
verify(receiver).literal(TYPE, null);
205+
verify(receiver).endRecord();
206+
207+
verifyNoMoreInteractions(receiver);
208+
}
209+
192210
@Test
193211
public void issue569ShouldNotRecognizeRecordsWithAndWithoutNamespace()
194212
throws SAXException {

0 commit comments

Comments
 (0)