void (final String str) { // Overrides Text.append(String) because this needs to check that CDATA // rules are enforced. We could have a separate Verifier check for CDATA // beyond Text and call that alone before super.setText(). if (str == null || str.isEmpty()) { return; } // we need a temp value to ensure that the value is changed _after_ // validation final String tmpValue; //noinspection StringEquality if (value == EMPTY_STRING) { tmpValue = str; } else { tmpValue = value + str; } // we have to do late checking since the end of a CDATA section could // have been created by concatenating both strings: // "]" + "]>" // or // "]]" + ">" // TODO: maybe this could be optimized for this two cases final String reason = Verifier.checkCDATASection(tmpValue); if (reason != null) { throw new IllegalDataException(str, "CDATA section", reason); } value = tmpValue; }