1111import org .metafacture .framework .annotations .Out ;
1212import org .metafacture .framework .helpers .DefaultObjectPipe ;
1313import org .w3c .dom .Document ;
14- import org .w3c .dom .Element ;
14+ import org .w3c .dom .Node ;
1515import org .xml .sax .SAXException ;
1616
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 ;
1824import java .net .HttpURLConnection ;
1925import java .net .URL ;
2026import javax .xml .parsers .DocumentBuilder ;
2127import javax .xml .parsers .DocumentBuilderFactory ;
2228import 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 ;
2433import javax .xml .transform .dom .DOMSource ;
2534import javax .xml .transform .stream .StreamResult ;
2635
3443 "to be retrieved from. Mandatory argument is: QUERY.\n " +
3544 "The output is an XML document holding the user defined \" maximumRecords\" as documents. If there are" +
3645 "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." )
3847@ In (String .class )
3948@ Out (java .io .Reader .class )
4049@ FluxCommand ("open-sru" )
@@ -173,16 +182,21 @@ private InputStream getXmlDocsViaSru(final StringBuilder srUrl) {
173182 DocumentBuilder docBuilder = factory .newDocumentBuilder ();
174183 Document xmldoc = docBuilder .parse (byteArrayInputStream );
175184
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+ }
185189
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+ }
186200 String xmlEncoding = xmldoc .getXmlEncoding ();
187201 String xmlVersion = xmldoc .getXmlVersion ();
188202 xmlDeclaration = String .format (xmlDeclarationTemplate , xmldoc .getXmlVersion (), xmldoc .getXmlEncoding ());
@@ -209,7 +223,7 @@ private InputStream getXmlDocsViaSru(final StringBuilder srUrl) {
209223 return new ByteArrayInputStream (stringBuilder .toString ().getBytes ());
210224
211225 }
212- catch (final IOException | TransformerException | SAXException | ParserConfigurationException e ) {
226+ catch (final IOException | TransformerException | SAXException | ParserConfigurationException e ) {
213227 stopRetrieving = true ;
214228 throw new MetafactureException (e );
215229 }
0 commit comments