Skip to content

Commit 7513885

Browse files
committed
Add option "ignorenamespace" (#569)
Setting "ignorenamespace" to "true" ignores checking the namespace.
1 parent 05c8dae commit 7513885

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author Markus Michael Geipel
3333
*
3434
*/
35-
@Description("A MARC XML reader. To read marc data without namespace specification set option `namespace=\"\"`")
35+
@Description("A MARC XML reader. To read marc data without namespace specification set option `namespace=\"\"`. To ignore namespace specification set option `ignorenamespace=\"true\".")
3636
@In(XmlReceiver.class)
3737
@Out(StreamReceiver.class)
3838
@FluxCommand("handle-marcxml")
@@ -70,6 +70,19 @@ public void setNamespace(final String namespace) {
7070
this.namespace = namespace;
7171
}
7272

73+
/**
74+
* Sets whether to ignore the namespace.
75+
*
76+
* <strong>Default value: false</strong>
77+
*
78+
* @param ignoreNamespace true if the namespace should be ignored
79+
*/
80+
public void setIgnoreNamespace(final boolean ignoreNamespace) {
81+
if (ignoreNamespace) {
82+
this.namespace = null;
83+
}
84+
}
85+
7386
private boolean checkNamespace(final String uri) {
7487
return namespace == null || namespace.equals(uri);
7588
}

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,63 @@ public void issue330ShouldOptionallyRecognizeRecordsWithoutNamespace()
146146
verifyNoMoreInteractions(receiver);
147147
}
148148

149+
@Test
150+
public void shouldRecognizeRecordsWithoutNamespace()
151+
throws SAXException {
152+
final AttributesImpl attributes = new AttributesImpl();
153+
154+
marcXmlHandler.setNamespace("");
155+
marcXmlHandler.startElement("", RECORD, "", attributes);
156+
marcXmlHandler.endElement("", RECORD, "");
157+
158+
verify(receiver).startRecord("");
159+
verify(receiver).literal(TYPE, null);
160+
verify(receiver).endRecord();
161+
162+
verifyNoMoreInteractions(receiver);
163+
}
164+
@Test
165+
public void shouldNotRecognizeRecordsWithNamespaceWhenOptionallyWithoutNamespace()
166+
throws SAXException {
167+
final AttributesImpl attributes = new AttributesImpl();
168+
169+
marcXmlHandler.setNamespace("");
170+
marcXmlHandler.startElement(NAMESPACE, RECORD, "", attributes);
171+
marcXmlHandler.endElement(NAMESPACE, RECORD, "");
172+
173+
verifyNoMoreInteractions(receiver);
174+
}
175+
176+
@Test
177+
public void issue569ShouldRecognizeRecordsWithAndWithoutNamespace()
178+
throws SAXException {
179+
final AttributesImpl attributes = new AttributesImpl();
180+
181+
marcXmlHandler.setIgnoreNamespace(true);
182+
marcXmlHandler.startElement(null, RECORD, "", attributes);
183+
marcXmlHandler.endElement(NAMESPACE, RECORD, "");
184+
185+
verify(receiver).startRecord("");
186+
verify(receiver).literal(TYPE, null);
187+
verify(receiver).endRecord();
188+
189+
verifyNoMoreInteractions(receiver);
190+
}
191+
192+
@Test
193+
public void issue569ShouldNotRecognizeRecordsWithAndWithoutNamespace()
194+
throws SAXException {
195+
final AttributesImpl attributes = new AttributesImpl();
196+
197+
marcXmlHandler.setIgnoreNamespace(false);
198+
marcXmlHandler.startElement(null, RECORD, "", attributes);
199+
marcXmlHandler.endElement(NAMESPACE, RECORD, "");
200+
201+
verify(receiver).endRecord();
202+
203+
verifyNoMoreInteractions(receiver);
204+
}
205+
149206
@Test
150207
public void shouldNotEncodeTypeAttributeAsMarkedLiteral() throws SAXException {
151208
final AttributesImpl attributes = new AttributesImpl();

0 commit comments

Comments
 (0)