|
1 | 1 | /* |
2 | | - * Copyright 2015-2020 MarkLogic Corporation |
| 2 | + * Copyright 2020 MarkLogic Corporation |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -271,8 +271,8 @@ public BasicElementVisitor(String nsUri, String localName) { |
271 | 271 | nsUri = ""; |
272 | 272 | } |
273 | 273 |
|
274 | | - if (localName == null) { |
275 | | - localName = ""; |
| 274 | + if (localName == null || localName.equals("")) { |
| 275 | + throw new IllegalArgumentException("LocalName cannot be null"); |
276 | 276 | } |
277 | 277 |
|
278 | 278 | this.nsUri = nsUri; |
@@ -358,49 +358,62 @@ T getNextHandle() { |
358 | 358 | while (xmlStreamReader.hasNext()) { |
359 | 359 | int event = xmlStreamReader.next(); |
360 | 360 |
|
361 | | - if (event == XMLStreamReader.START_ELEMENT) { |
362 | | - StartElementReaderImpl startElementReader = new StartElementReaderImpl(xmlStreamReader); |
363 | | - NodeOperation nodeOperation = visitor.startElement(startElementReader); |
364 | | - |
365 | | - if (nodeOperation == null) { |
366 | | - throw new IllegalStateException("No NodeOperation returned."); |
367 | | - } |
368 | | - |
369 | | - switch (nodeOperation) { |
370 | | - case DESCEND: |
371 | | - break; |
372 | | - |
373 | | - case PROCESS: |
374 | | - T handle = visitor.makeBufferedHandle(xmlStreamReader); |
375 | | - if (handle != null) { |
376 | | - return handle; |
377 | | - } |
378 | | - break; |
379 | | - |
380 | | - case SKIP: |
381 | | - int count = 0; |
382 | | - while (xmlStreamReader.hasNext()) { |
383 | | - int next = xmlStreamReader.next(); |
384 | | - if (next == XMLStreamReader.START_ELEMENT) { |
385 | | - count++; |
386 | | - } |
| 361 | + checkForHandle: |
| 362 | + switch (event) { |
| 363 | + case XMLStreamReader.START_ELEMENT: |
| 364 | + StartElementReaderImpl startElementReader = new StartElementReaderImpl(xmlStreamReader); |
| 365 | + NodeOperation nodeOperation = visitor.startElement(startElementReader); |
| 366 | + |
| 367 | + if (nodeOperation == null) { |
| 368 | + throw new IllegalStateException("No NodeOperation returned."); |
| 369 | + } |
387 | 370 |
|
388 | | - if (next == XMLStreamReader.END_ELEMENT) { |
389 | | - if (count == 0) { |
390 | | - break; |
| 371 | + switch (nodeOperation) { |
| 372 | + case DESCEND: |
| 373 | + break checkForHandle; |
| 374 | + |
| 375 | + case PROCESS: |
| 376 | + T handle = visitor.makeBufferedHandle(xmlStreamReader); |
| 377 | + if (handle != null) { |
| 378 | + return handle; |
| 379 | + } |
| 380 | + break checkForHandle; |
| 381 | + |
| 382 | + case SKIP: |
| 383 | + int depth = 0; |
| 384 | + while (xmlStreamReader.hasNext()) { |
| 385 | + int next = xmlStreamReader.next(); |
| 386 | + skipCheck: |
| 387 | + switch (next) { |
| 388 | + case XMLStreamReader.START_ELEMENT: |
| 389 | + depth++; |
| 390 | + break skipCheck; |
| 391 | + |
| 392 | + case XMLStreamReader.END_ELEMENT: |
| 393 | + if (depth == 0) { |
| 394 | + break checkForHandle; |
| 395 | + } |
| 396 | + depth--; |
| 397 | + break skipCheck; |
| 398 | + |
| 399 | + default: |
| 400 | + break skipCheck; |
391 | 401 | } |
392 | | - count--; |
393 | 402 | } |
394 | | - } |
395 | | - break; |
396 | | - |
397 | | - default: |
398 | | - throw new IllegalStateException("Unknown state"); |
399 | | - } |
400 | | - }else if (event == XMLStreamReader.END_ELEMENT) { |
401 | | - visitor.endElement( |
402 | | - xmlStreamReader.getNamespaceURI(), |
403 | | - xmlStreamReader.getLocalName()); |
| 403 | + break checkForHandle; |
| 404 | + |
| 405 | + default: |
| 406 | + throw new IllegalStateException("Unknown state"); |
| 407 | + } |
| 408 | + |
| 409 | + case XMLStreamReader.END_ELEMENT: |
| 410 | + visitor.endElement( |
| 411 | + xmlStreamReader.getNamespaceURI(), |
| 412 | + xmlStreamReader.getLocalName()); |
| 413 | + break checkForHandle; |
| 414 | + |
| 415 | + default: |
| 416 | + break checkForHandle; |
404 | 417 | } |
405 | 418 | } |
406 | 419 |
|
|
0 commit comments