Skip to content

Commit f7f0b12

Browse files
committed
Add setRecordTagName property to GenericXmlHandler
Setting the record tag name in the constructor is deprecated.
1 parent 3e7f486 commit f7f0b12

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,57 @@
4040
@FluxCommand("handle-generic-xml")
4141
public final class GenericXmlHandler extends DefaultXmlPipe<StreamReceiver> {
4242

43+
public static final String DEFAULT_RECORD_TAG = "record";
44+
4345
private static final Pattern TABS = Pattern.compile("\t+");
44-
private final String recordTagName;
46+
47+
private String recordTagName = DEFAULT_RECORD_TAG;
48+
4549
private boolean inRecord;
4650
private StringBuilder valueBuffer = new StringBuilder();
4751

4852
public GenericXmlHandler() {
4953
super();
50-
this.recordTagName = System.getProperty(
54+
final String recordTagNameProperty = System.getProperty(
5155
"org.culturegraph.metamorph.xml.recordtag");
52-
if (recordTagName == null) {
53-
throw new MetafactureException("Missing name for the tag marking a record.");
56+
if (recordTagNameProperty != null) {
57+
recordTagName = recordTagNameProperty;
5458
}
5559
}
5660

61+
/**
62+
* Creates a new {@ode GenericXmlReader} with the given tag name as
63+
* marker for records.
64+
*
65+
* @deprecated Use default constructor and set the tag name latter
66+
* with {@link #setRecordTagName(String)}.
67+
*
68+
* @param recordTagName tag name marking the start of a record.
69+
*/
70+
@Deprecated
5771
public GenericXmlHandler(final String recordTagName) {
5872
super();
5973
this.recordTagName = recordTagName;
6074
}
6175

76+
/**
77+
* Sets the tag name which marks the start of a record.
78+
* <p>
79+
* This value may only be changed between records. If it is changed
80+
* while processing a record the behaviour of this module is undefined.
81+
* <p>
82+
* <strong>Default value: {@value DEFAULT_RECORD_TAG}</strong>
83+
*
84+
* @param recordTagName the tag name which marks the start of a record.
85+
*/
86+
public void setRecordTagName(String recordTagName) {
87+
this.recordTagName = recordTagName;
88+
}
89+
90+
public String getRecordTagName() {
91+
return recordTagName;
92+
}
93+
6294
@Override
6395
public void startElement(final String uri, final String localName,
6496
final String qName, final Attributes attributes) {

0 commit comments

Comments
 (0)