|
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 | 15 | import org.xml.sax.SAXException;
|
15 | 16 |
|
16 | 17 | import java.io.ByteArrayInputStream;
|
@@ -59,7 +60,7 @@ public final class SruOpener extends DefaultObjectPipe<String, ObjectReceiver<Re
|
59 | 60 |
|
60 | 61 | private int maximumRecords = MAXIMUM_RECORDS;
|
61 | 62 | private int startRecord = START_RECORD;
|
62 |
| - private int totalRecords; |
| 63 | + private int totalRecords = Integer.MAX_VALUE; |
63 | 64 |
|
64 | 65 | private boolean stopRetrieving;
|
65 | 66 |
|
@@ -157,34 +158,37 @@ public void process(final String baseUrl) {
|
157 | 158 | else {
|
158 | 159 | throw new IllegalArgumentException("Missing mandatory parameter 'query'");
|
159 | 160 | }
|
160 |
| - int retrievedRecords = 0; |
161 |
| - while (!stopRetrieving && (retrievedRecords < totalRecords)) { |
162 |
| - if (totalRecords >0) { |
163 |
| - int yetToRetrieveRecords = totalRecords - retrievedRecords; |
| 161 | + int numberOfRecords = Integer.MAX_VALUE; |
| 162 | + TransformerFactory tf = TransformerFactory.newInstance(); |
| 163 | + Transformer t = tf.newTransformer(); |
| 164 | + while (!stopRetrieving && (startRecord < numberOfRecords)) { |
| 165 | + /* if (totalRecords >0) { |
| 166 | + yetToRetrieveRecords = totalRecords - retrievedRecords; |
164 | 167 | if (yetToRetrieveRecords < maximumRecords) {
|
165 | 168 | maximumRecords = yetToRetrieveRecords;
|
166 | 169 | }
|
167 |
| - } |
| 170 | + }*/ |
168 | 171 | ByteArrayInputStream byteArrayInputStream = retrieve(srUrl, startRecord, maximumRecords);
|
169 | 172 |
|
170 |
| - TransformerFactory tf = TransformerFactory.newInstance(); |
171 |
| - Transformer t = tf.newTransformer(); |
| 173 | + |
172 | 174 | DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
|
173 | 175 | DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
174 | 176 | Document xmldoc = docBuilder.parse(byteArrayInputStream);
|
175 | 177 |
|
176 |
| - ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| 178 | + Element element = (Element)xmldoc.getElementsByTagName("numberOfRecords").item(0); |
| 179 | + numberOfRecords=Integer.parseInt(element.getTextContent()); |
| 180 | + |
| 181 | + ByteArrayOutputStream os = new ByteArrayOutputStream(); |
177 | 182 | Result result = new StreamResult(os);
|
178 | 183 | t.transform(new DOMSource(xmldoc), result);
|
179 |
| - |
180 | 184 | ByteArrayInputStream inputStream = new ByteArrayInputStream(os.toByteArray());
|
181 | 185 |
|
182 | 186 | getReceiver().process(
|
183 | 187 | new InputStreamReader(inputStream));
|
| 188 | + tf = TransformerFactory.newInstance(); |
| 189 | + t = tf.newTransformer(); |
184 | 190 | t.setOutputProperty("omit-xml-declaration", "yes");
|
185 |
| - //todo: bis max lookup zuviel (bis der nämlich sehr klein ist => keine Ergebnisse mehr) |
186 | 191 | startRecord = startRecord + maximumRecords;
|
187 |
| - retrievedRecords = retrievedRecords + maximumRecords; |
188 | 192 | }
|
189 | 193 | }
|
190 | 194 | catch (final IOException | TransformerException | SAXException | ParserConfigurationException e) {
|
|
0 commit comments