Skip to content

Commit 8053b5f

Browse files
llingllinggit
authored andcommitted
Resolve review comments for DHFPROD-3136.
1 parent 5339f76 commit 8053b5f

File tree

4 files changed

+73
-45
lines changed

4 files changed

+73
-45
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/NodeOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2020 MarkLogic Corporation
2+
* Copyright 2020 MarkLogic Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/XMLSplitter.java

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2020 MarkLogic Corporation
2+
* Copyright 2020 MarkLogic Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -271,8 +271,8 @@ public BasicElementVisitor(String nsUri, String localName) {
271271
nsUri = "";
272272
}
273273

274-
if (localName == null) {
275-
localName = "";
274+
if (localName == null || localName.equals("")) {
275+
throw new IllegalArgumentException("LocalName cannot be null");
276276
}
277277

278278
this.nsUri = nsUri;
@@ -358,49 +358,62 @@ T getNextHandle() {
358358
while (xmlStreamReader.hasNext()) {
359359
int event = xmlStreamReader.next();
360360

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+
}
387370

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;
391401
}
392-
count--;
393402
}
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;
404417
}
405418
}
406419

marklogic-client-api/src/test/java/com/marklogic/client/test/datamovement/XMLSplitterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2020 MarkLogic Corporation
2+
* Copyright 2020 MarkLogic Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

marklogic-client-api/src/test/resources/data/people.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2020 MarkLogic Corporation
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
217
<people xmlns="http://www.marklogic.com/people/">
318
<person president="yes"><first>George</first><last>Washington</last></person>
419
<person president="no"><first>Betsy</first><last>Ross</last></person>

0 commit comments

Comments
 (0)