@Test public void modifyBodyWithReferences2() { Pair<String, String> result = ReferencesManager.modifyBodyWithReferences(message2, body2); assertEquals("hello", result.first); assertNull(result.second); }
public static Pair<String, String> modifyBodyWithReferences(Message message, String body) { if (body == null || body.isEmpty() || body.trim().isEmpty()) return new Pair<>(body, null); List<ExtensionElement> elements = message.getExtensions(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE); if (elements == null || elements.size() == 0) return new Pair<>(body, null); List<ReferenceElement> references = getReferences(elements); if (references.isEmpty()) return new Pair<>(body, null); String[] chars = stringToChars(Utils.xmlEncode(body)); for (ReferenceElement reference : references) { if (!(reference instanceof Markup) && !(reference instanceof Mention) && !(reference instanceof Quote)) chars = modifyBodyWithReferences(chars, reference); } String regularBody = Html.fromHtml(charsToString(chars).replace("\n", "<br/>")).toString(); String markupBody = null; for (ReferenceElement reference : references) { if (reference instanceof Markup || reference instanceof Mention || reference instanceof Quote) chars = modifyBodyWithReferences(chars, reference); } markupBody = charsToString(chars); if (regularBody.equals(markupBody)) markupBody = null; return new Pair<>(regularBody, markupBody); }
ReferencesManager { public static Pair<String, String> modifyBodyWithReferences(Message message, String body) { if (body == null || body.isEmpty() || body.trim().isEmpty()) return new Pair<>(body, null); List<ExtensionElement> elements = message.getExtensions(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE); if (elements == null || elements.size() == 0) return new Pair<>(body, null); List<ReferenceElement> references = getReferences(elements); if (references.isEmpty()) return new Pair<>(body, null); String[] chars = stringToChars(Utils.xmlEncode(body)); for (ReferenceElement reference : references) { if (!(reference instanceof Markup) && !(reference instanceof Mention) && !(reference instanceof Quote)) chars = modifyBodyWithReferences(chars, reference); } String regularBody = Html.fromHtml(charsToString(chars).replace("\n", "<br/>")).toString(); String markupBody = null; for (ReferenceElement reference : references) { if (reference instanceof Markup || reference instanceof Mention || reference instanceof Quote) chars = modifyBodyWithReferences(chars, reference); } markupBody = charsToString(chars); if (regularBody.equals(markupBody)) markupBody = null; return new Pair<>(regularBody, markupBody); } }
ReferencesManager { public static Pair<String, String> modifyBodyWithReferences(Message message, String body) { if (body == null || body.isEmpty() || body.trim().isEmpty()) return new Pair<>(body, null); List<ExtensionElement> elements = message.getExtensions(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE); if (elements == null || elements.size() == 0) return new Pair<>(body, null); List<ReferenceElement> references = getReferences(elements); if (references.isEmpty()) return new Pair<>(body, null); String[] chars = stringToChars(Utils.xmlEncode(body)); for (ReferenceElement reference : references) { if (!(reference instanceof Markup) && !(reference instanceof Mention) && !(reference instanceof Quote)) chars = modifyBodyWithReferences(chars, reference); } String regularBody = Html.fromHtml(charsToString(chars).replace("\n", "<br/>")).toString(); String markupBody = null; for (ReferenceElement reference : references) { if (reference instanceof Markup || reference instanceof Mention || reference instanceof Quote) chars = modifyBodyWithReferences(chars, reference); } markupBody = charsToString(chars); if (regularBody.equals(markupBody)) markupBody = null; return new Pair<>(regularBody, markupBody); }  }
ReferencesManager { public static Pair<String, String> modifyBodyWithReferences(Message message, String body) { if (body == null || body.isEmpty() || body.trim().isEmpty()) return new Pair<>(body, null); List<ExtensionElement> elements = message.getExtensions(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE); if (elements == null || elements.size() == 0) return new Pair<>(body, null); List<ReferenceElement> references = getReferences(elements); if (references.isEmpty()) return new Pair<>(body, null); String[] chars = stringToChars(Utils.xmlEncode(body)); for (ReferenceElement reference : references) { if (!(reference instanceof Markup) && !(reference instanceof Mention) && !(reference instanceof Quote)) chars = modifyBodyWithReferences(chars, reference); } String regularBody = Html.fromHtml(charsToString(chars).replace("\n", "<br/>")).toString(); String markupBody = null; for (ReferenceElement reference : references) { if (reference instanceof Markup || reference instanceof Mention || reference instanceof Quote) chars = modifyBodyWithReferences(chars, reference); } markupBody = charsToString(chars); if (regularBody.equals(markupBody)) markupBody = null; return new Pair<>(regularBody, markupBody); }  @NonNull static List<Forwarded> getForwardedFromReferences(Stanza packet); static Media createMediaReferences(Attachment attachment, int begin, int end); static Forward createForwardReference(MessageItem item, int begin, int end); @NonNull static List<RefMedia> getMediaFromReferences(Stanza packet); @Nullable static RefUser getGroupchatUserFromReferences(Stanza packet); static Pair<String, String> modifyBodyWithReferences(Message message, String body); }
ReferencesManager { public static Pair<String, String> modifyBodyWithReferences(Message message, String body) { if (body == null || body.isEmpty() || body.trim().isEmpty()) return new Pair<>(body, null); List<ExtensionElement> elements = message.getExtensions(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE); if (elements == null || elements.size() == 0) return new Pair<>(body, null); List<ReferenceElement> references = getReferences(elements); if (references.isEmpty()) return new Pair<>(body, null); String[] chars = stringToChars(Utils.xmlEncode(body)); for (ReferenceElement reference : references) { if (!(reference instanceof Markup) && !(reference instanceof Mention) && !(reference instanceof Quote)) chars = modifyBodyWithReferences(chars, reference); } String regularBody = Html.fromHtml(charsToString(chars).replace("\n", "<br/>")).toString(); String markupBody = null; for (ReferenceElement reference : references) { if (reference instanceof Markup || reference instanceof Mention || reference instanceof Quote) chars = modifyBodyWithReferences(chars, reference); } markupBody = charsToString(chars); if (regularBody.equals(markupBody)) markupBody = null; return new Pair<>(regularBody, markupBody); }  @NonNull static List<Forwarded> getForwardedFromReferences(Stanza packet); static Media createMediaReferences(Attachment attachment, int begin, int end); static Forward createForwardReference(MessageItem item, int begin, int end); @NonNull static List<RefMedia> getMediaFromReferences(Stanza packet); @Nullable static RefUser getGroupchatUserFromReferences(Stanza packet); static Pair<String, String> modifyBodyWithReferences(Message message, String body);  }