38
38
@ FluxCommand ("handle-marcxml" )
39
39
public final class MarcXmlHandler extends DefaultXmlPipe <StreamReceiver > {
40
40
41
+ public static final String DEFAULT_ATTRIBUTE_MARKER = "" ;
42
+
41
43
private static final String SUBFIELD = "subfield" ;
42
44
private static final String DATAFIELD = "datafield" ;
43
45
private static final String CONTROLFIELD = "controlfield" ;
44
46
private static final String RECORD = "record" ;
45
47
private static final String NAMESPACE = "http://www.loc.gov/MARC21/slim" ;
46
48
private static final String LEADER = "leader" ;
47
49
private static final String TYPE = "type" ;
50
+
51
+ private String attributeMarker = DEFAULT_ATTRIBUTE_MARKER ;
48
52
private String currentTag = "" ;
49
53
private String namespace = NAMESPACE ;
50
54
private StringBuilder builder = new StringBuilder ();
@@ -60,6 +64,14 @@ private boolean checkNamespace(final String uri) {
60
64
return namespace == null || namespace .equals (uri );
61
65
}
62
66
67
+ public void setAttributeMarker (final String attributeMarker ) {
68
+ this .attributeMarker = attributeMarker ;
69
+ }
70
+
71
+ public String getAttributeMarker () {
72
+ return attributeMarker ;
73
+ }
74
+
63
75
@ Override
64
76
public void startElement (final String uri , final String localName , final String qName , final Attributes attributes ) throws SAXException {
65
77
if (SUBFIELD .equals (localName )) {
@@ -75,7 +87,7 @@ else if (CONTROLFIELD.equals(localName)) {
75
87
}
76
88
else if (RECORD .equals (localName ) && checkNamespace (uri )) {
77
89
getReceiver ().startRecord ("" );
78
- getReceiver ().literal (TYPE , attributes .getValue (TYPE ));
90
+ getReceiver ().literal (attributeMarker + TYPE , attributes .getValue (TYPE ));
79
91
}
80
92
else if (LEADER .equals (localName )) {
81
93
builder = new StringBuilder ();
@@ -87,18 +99,15 @@ else if (LEADER.equals(localName)) {
87
99
public void endElement (final String uri , final String localName , final String qName ) throws SAXException {
88
100
if (SUBFIELD .equals (localName )) {
89
101
getReceiver ().literal (currentTag , builder .toString ().trim ());
90
-
91
102
}
92
103
else if (DATAFIELD .equals (localName )) {
93
104
getReceiver ().endEntity ();
94
105
}
95
106
else if (CONTROLFIELD .equals (localName )) {
96
107
getReceiver ().literal (currentTag , builder .toString ().trim ());
97
-
98
108
}
99
109
else if (RECORD .equals (localName ) && checkNamespace (uri )) {
100
110
getReceiver ().endRecord ();
101
-
102
111
}
103
112
else if (LEADER .equals (localName )) {
104
113
getReceiver ().literal (currentTag , builder .toString ());
0 commit comments