11
11
import org .metafacture .framework .annotations .Out ;
12
12
import org .metafacture .framework .helpers .DefaultObjectPipe ;
13
13
import org .w3c .dom .Document ;
14
- import org .w3c .dom .Element ;
14
+ import org .w3c .dom .Node ;
15
15
import org .xml .sax .SAXException ;
16
16
17
- import java .io .*;
17
+ import java .io .BufferedReader ;
18
+ import java .io .ByteArrayInputStream ;
19
+ import java .io .ByteArrayOutputStream ;
20
+ import java .io .IOException ;
21
+ import java .io .InputStream ;
22
+ import java .io .InputStreamReader ;
23
+ import java .io .Reader ;
18
24
import java .net .HttpURLConnection ;
19
25
import java .net .URL ;
20
26
import javax .xml .parsers .DocumentBuilder ;
21
27
import javax .xml .parsers .DocumentBuilderFactory ;
22
28
import javax .xml .parsers .ParserConfigurationException ;
23
- import javax .xml .transform .*;
29
+ import javax .xml .transform .Result ;
30
+ import javax .xml .transform .Transformer ;
31
+ import javax .xml .transform .TransformerException ;
32
+ import javax .xml .transform .TransformerFactory ;
24
33
import javax .xml .transform .dom .DOMSource ;
25
34
import javax .xml .transform .stream .StreamResult ;
26
35
34
43
"to be retrieved from. Mandatory argument is: QUERY.\n " +
35
44
"The output is an XML document holding the user defined \" maximumRecords\" as documents. If there are" +
36
45
"more documents than defined by MAXIMUM_RECORDS and there are more documents wanted (defined by " +
37
- "\" totalRecords\" ) there will be consecutives XML documents output." )
46
+ "\" totalRecords\" ) there will be consecutive XML documents output." )
38
47
@ In (String .class )
39
48
@ Out (java .io .Reader .class )
40
49
@ FluxCommand ("open-sru" )
@@ -173,16 +182,21 @@ private InputStream getXmlDocsViaSru(final StringBuilder srUrl) {
173
182
DocumentBuilder docBuilder = factory .newDocumentBuilder ();
174
183
Document xmldoc = docBuilder .parse (byteArrayInputStream );
175
184
176
- numberOfRecords =
177
- Integer .parseInt (
178
- ((Element ) xmldoc .getElementsByTagName ("numberOfRecords" ).item (0 )).getTextContent ());
179
- int recordPosition =
180
- Integer .parseInt (
181
- ((Element ) xmldoc .getElementsByTagName ("recordPosition" ).item (0 )).getTextContent ());
182
- int nextRecordPosition =
183
- Integer .parseInt (
184
- ((Element ) xmldoc .getElementsByTagName ("nextRecordPosition" ).item (0 )).getTextContent ());
185
+ Node node = xmldoc .getElementsByTagName ("numberOfRecords" ).item (0 );
186
+ if (node != null ) {
187
+ numberOfRecords = Integer .parseInt (node .getTextContent ());
188
+ }
185
189
190
+ int recordPosition =0 ;
191
+ node = xmldoc .getElementsByTagName ("recordPosition" ).item (0 );
192
+ if (node != null ) {
193
+ recordPosition = Integer .parseInt (node .getTextContent ());
194
+ }
195
+ int nextRecordPosition =recordPosition +1 ;
196
+ node = xmldoc .getElementsByTagName ("nextRecordPosition" ).item (0 );
197
+ if (node != null ) {
198
+ nextRecordPosition = Integer .parseInt (node .getTextContent ());
199
+ }
186
200
String xmlEncoding = xmldoc .getXmlEncoding ();
187
201
String xmlVersion = xmldoc .getXmlVersion ();
188
202
xmlDeclaration = String .format (xmlDeclarationTemplate , xmldoc .getXmlVersion (), xmldoc .getXmlEncoding ());
@@ -209,7 +223,7 @@ private InputStream getXmlDocsViaSru(final StringBuilder srUrl) {
209
223
return new ByteArrayInputStream (stringBuilder .toString ().getBytes ());
210
224
211
225
}
212
- catch (final IOException | TransformerException | SAXException | ParserConfigurationException e ) {
226
+ catch (final IOException | TransformerException | SAXException | ParserConfigurationException e ) {
213
227
stopRetrieving = true ;
214
228
throw new MetafactureException (e );
215
229
}
0 commit comments