Skip to content

Commit

Permalink
Add option "ignorenamespace" (#569)
Browse files Browse the repository at this point in the history
Setting "ignorenamespace" to "true" ignores checking the namespace.
  • Loading branch information
dr0i committed Nov 21, 2024
1 parent 05c8dae commit 7513885
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @author Markus Michael Geipel
*
*/
@Description("A MARC XML reader. To read marc data without namespace specification set option `namespace=\"\"`")
@Description("A MARC XML reader. To read marc data without namespace specification set option `namespace=\"\"`. To ignore namespace specification set option `ignorenamespace=\"true\".")
@In(XmlReceiver.class)
@Out(StreamReceiver.class)
@FluxCommand("handle-marcxml")
Expand Down Expand Up @@ -70,6 +70,19 @@ public void setNamespace(final String namespace) {
this.namespace = namespace;
}

/**
* Sets whether to ignore the namespace.
*
* <strong>Default value: false</strong>
*
* @param ignoreNamespace true if the namespace should be ignored
*/
public void setIgnoreNamespace(final boolean ignoreNamespace) {
if (ignoreNamespace) {
this.namespace = null;
}
}

private boolean checkNamespace(final String uri) {
return namespace == null || namespace.equals(uri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,63 @@ public void issue330ShouldOptionallyRecognizeRecordsWithoutNamespace()
verifyNoMoreInteractions(receiver);
}

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

marcXmlHandler.setNamespace("");
marcXmlHandler.startElement("", RECORD, "", attributes);
marcXmlHandler.endElement("", RECORD, "");

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

verifyNoMoreInteractions(receiver);
}
@Test
public void shouldNotRecognizeRecordsWithNamespaceWhenOptionallyWithoutNamespace()
throws SAXException {
final AttributesImpl attributes = new AttributesImpl();

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

verifyNoMoreInteractions(receiver);
}

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

marcXmlHandler.setIgnoreNamespace(true);
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 {
final AttributesImpl attributes = new AttributesImpl();

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

verify(receiver).endRecord();

verifyNoMoreInteractions(receiver);
}

@Test
public void shouldNotEncodeTypeAttributeAsMarkedLiteral() throws SAXException {
final AttributesImpl attributes = new AttributesImpl();
Expand Down

0 comments on commit 7513885

Please sign in to comment.