Skip to content

Commit

Permalink
Make "ignorenamespace" order-independent (#569)
Browse files Browse the repository at this point in the history
Even if a namespace is set after setting "ignorenamespace" to "true" the
namespace is ignored.
  • Loading branch information
dr0i committed Dec 2, 2024
1 parent 7513885 commit 57f6a71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class MarcXmlHandler extends DefaultXmlPipe<StreamReceiver> {
private String currentTag = "";
private String namespace = NAMESPACE;
private StringBuilder builder = new StringBuilder();
private boolean ignoreNamespace;

/**
* Creates an instance of {@link MarcXmlHandler}.
Expand Down Expand Up @@ -78,13 +79,11 @@ public void setNamespace(final String namespace) {
* @param ignoreNamespace true if the namespace should be ignored
*/
public void setIgnoreNamespace(final boolean ignoreNamespace) {
if (ignoreNamespace) {
this.namespace = null;
}
this.ignoreNamespace = ignoreNamespace;
}

private boolean checkNamespace(final String uri) {
return namespace == null || namespace.equals(uri);
return namespace == null || ignoreNamespace || namespace.equals(uri);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void shouldRecognizeRecordsWithoutNamespace()

verifyNoMoreInteractions(receiver);
}

@Test
public void shouldNotRecognizeRecordsWithNamespaceWhenOptionallyWithoutNamespace()
throws SAXException {
Expand Down Expand Up @@ -189,6 +190,23 @@ public void issue569ShouldRecognizeRecordsWithAndWithoutNamespace()
verifyNoMoreInteractions(receiver);
}

@Test
public void issue569ShouldRecognizeRecordsWithAndWithoutNamespaceOrderIndependently()
throws SAXException {
final AttributesImpl attributes = new AttributesImpl();

marcXmlHandler.setIgnoreNamespace(true);
marcXmlHandler.setNamespace("");
marcXmlHandler.startElement(null, RECORD, "", attributes);
marcXmlHandler.endElement(NAMESPACE, RECORD, "");

verify(receiver).startRecord("");
verify(receiver).literal(TYPE, null);
verify(receiver).endRecord();

verifyNoMoreInteractions(receiver);
}

@Test
public void issue569ShouldNotRecognizeRecordsWithAndWithoutNamespace()
throws SAXException {
Expand Down

0 comments on commit 57f6a71

Please sign in to comment.