Skip to content

Commit 4130c8b

Browse files
committed
[refactor] clean up Indexer processText()
It just needed a bit of simplification.
1 parent c62576f commit 4130c8b

1 file changed

Lines changed: 46 additions & 69 deletions

File tree

exist-core/src/main/java/org/exist/Indexer.java

Lines changed: 46 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -319,84 +319,61 @@ public void endDocument() {
319319
//LOG.debug("elementCnt = " + childCnt.length);
320320
}
321321

322-
private void processText(ElementImpl last, ProcessTextParent ptp) {
323-
// if (charBuf != null && charBuf.length() > 0) {
324-
// // remove whitespace if the node has just a single text child,
325-
// // keep whitespace for mixed content.
326-
// final XMLString normalized;
327-
// if ((charBuf.isWhitespaceOnly() && preserveWSmixed) || last.preserveSpace()) {
328-
// normalized = charBuf;
329-
// } else {
330-
// if (last.getChildCount() == 0) {
331-
// normalized = charBuf.normalize(normalize);
332-
// } else {
333-
// normalized = charBuf.isWhitespaceOnly() ? null : charBuf;
334-
// }
335-
// }
336-
// if (normalized != null && normalized.length() > 0) {
337-
// text.setData(normalized);
338-
// text.setOwnerDocument(document);
339-
// last.appendChildInternal(prevNode, text);
340-
// if (!validate) storeText();
341-
// setPrevious(text);
342-
// }
343-
// charBuf.reset();
344-
// }
345-
346-
//from startElement method
347-
if (charBuf != null && charBuf.length() > 0) {
348-
XMLString normalized = null;
349-
switch (ptp) {
350-
case COMMENT:
351-
case PI:
352-
case CDATA_START:
353-
normalized = charBuf;
354-
break;
355-
default:
356-
if (charBuf.isWhitespaceOnly()) {
357-
if (last.preserveSpace() || last.getChildCount() == 0) {
358-
normalized = charBuf;
359-
} else if (preserveWSmixed) {
360-
if (!(last.getChildCount() == 0 && (normalize & XMLString.SUPPRESS_LEADING_WS) != 0)) {
361-
normalized = charBuf;
362-
}
322+
private XMLString normalizeLast(final ElementImpl last) {
323+
if (charBuf.isWhitespaceOnly()) {
324+
if (last.preserveSpace() || last.getChildCount() == 0) {
325+
return charBuf;
326+
} else if (preserveWSmixed) {
327+
if (!(last.getChildCount() == 0 && (normalize & XMLString.SUPPRESS_LEADING_WS) != 0)) {
328+
return charBuf;
363329
} else {
364-
normalized = charBuf.normalize(normalize);
330+
return null;
365331
}
366-
} else {
367-
//normalized = charBuf;
368-
if (last.preserveSpace()) {
369-
normalized = charBuf;
370-
} else if (last.getChildCount() == 0) {
371-
normalized = charBuf.normalize(normalize);
332+
} else {
333+
return charBuf.normalize(normalize);
334+
}
335+
} else {
336+
//normalized = charBuf;
337+
if (last.preserveSpace()) {
338+
return charBuf;
339+
} else if (last.getChildCount() == 0) {
340+
return charBuf.normalize(normalize);
341+
} else {
342+
// mixed element content: don't normalize the text node,
343+
// just check if there is any text at all
344+
if (preserveWSmixed) {
345+
return charBuf;
372346
} else {
373-
// mixed element content: don't normalize the text node,
374-
// just check if there is any text at all
375-
if (preserveWSmixed) {
376-
normalized = charBuf;
347+
if ((normalize & XMLString.SUPPRESS_LEADING_WS) != 0) {
348+
return charBuf.normalize(XMLString.SUPPRESS_LEADING_WS | XMLString.COLLAPSE_WS);
349+
} else if ((normalize & XMLString.SUPPRESS_TRAILING_WS) != 0) {
350+
return charBuf.normalize(XMLString.SUPPRESS_TRAILING_WS | XMLString.COLLAPSE_WS);
377351
} else {
378-
if ((normalize & XMLString.SUPPRESS_LEADING_WS) != 0) {
379-
normalized = charBuf.normalize(XMLString.SUPPRESS_LEADING_WS | XMLString.COLLAPSE_WS);
380-
} else if ((normalize & XMLString.SUPPRESS_TRAILING_WS) != 0) {
381-
normalized = charBuf.normalize(XMLString.SUPPRESS_TRAILING_WS | XMLString.COLLAPSE_WS);
382-
} else {
383-
//normalized = charBuf.normalize(XMLString.COLLAPSE_WS);
384-
normalized = charBuf.normalize(normalize);
385-
}
352+
//normalized = charBuf.normalize(XMLString.COLLAPSE_WS);
353+
return charBuf.normalize(normalize);
386354
}
387355
}
356+
}
357+
}
358+
}
388359

360+
private void processText(ElementImpl last, ProcessTextParent ptp) {
361+
362+
//from startElement method
363+
if (charBuf != null && !charBuf.isEmpty()) {
364+
XMLString normalized = switch (ptp) {
365+
case COMMENT, PI, CDATA_START -> charBuf;
366+
default -> normalizeLast(last);
367+
};
368+
if (normalized != null) {
369+
text.setData(normalized);
370+
text.setOwnerDocument(document);
371+
last.appendChildInternal(prevNode, text);
372+
if (!validate) storeText();
373+
setPrevious(text);
389374
}
375+
charBuf.reset();
390376
}
391-
if (normalized != null) {
392-
text.setData(normalized);
393-
text.setOwnerDocument(document);
394-
last.appendChildInternal(prevNode, text);
395-
if (!validate) storeText();
396-
setPrevious(text);
397-
}
398-
charBuf.reset();
399-
}
400377
}
401378

402379
@Override

0 commit comments

Comments
 (0)