mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Merge branch '4.4'
This commit is contained in:
commit
b857f33ac3
10 changed files with 82 additions and 14 deletions
|
@ -590,7 +590,7 @@ public final class Message extends MessageOrPresence<MessageBuilder>
|
|||
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
|
||||
xml.rightAngleBracket();
|
||||
xml.escape(message);
|
||||
xml.text(message);
|
||||
xml.closeElement(getElementName());
|
||||
return xml;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2019 Florian Schmaus.
|
||||
* Copyright 2015-2020 Florian Schmaus.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -142,7 +142,9 @@ public final class StandardExtensionElement implements ExtensionElement {
|
|||
}
|
||||
xml.rightAngleBracket();
|
||||
|
||||
xml.optEscape(text);
|
||||
if (text != null) {
|
||||
xml.text(text);
|
||||
}
|
||||
|
||||
if (elements != null) {
|
||||
for (Map.Entry<QName, StandardExtensionElement> entry : elements.entrySet()) {
|
||||
|
|
|
@ -293,6 +293,30 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put if the queue has not been shutdown yet.
|
||||
*
|
||||
* @param e the element to put into the queue.
|
||||
* @return <code>true</code> if the element has been put into the queue, <code>false</code> if the queue was shutdown.
|
||||
* @throws InterruptedException if the calling thread was interrupted.
|
||||
* @since 4.4
|
||||
*/
|
||||
public boolean putIfNotShutdown(E e) throws InterruptedException {
|
||||
checkNotNull(e);
|
||||
lock.lockInterruptibly();
|
||||
|
||||
try {
|
||||
if (isShutdown) {
|
||||
return false;
|
||||
}
|
||||
|
||||
putInternal(e, true);
|
||||
return true;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void putAll(Collection<? extends E> elements) throws InterruptedException {
|
||||
checkNotNull(elements);
|
||||
lock.lockInterruptibly();
|
||||
|
|
|
@ -456,6 +456,13 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
|||
return this;
|
||||
}
|
||||
|
||||
public XmlStringBuilder text(CharSequence text) {
|
||||
assert text != null;
|
||||
CharSequence escapedText = StringUtils.escapeForXmlText(text);
|
||||
sb.append(escapedText);
|
||||
return this;
|
||||
}
|
||||
|
||||
public XmlStringBuilder escape(String text) {
|
||||
assert text != null;
|
||||
sb.append(StringUtils.escapeForXml(text));
|
||||
|
|
|
@ -206,4 +206,17 @@ public class MessageTest {
|
|||
|
||||
assertXmlSimilar(control, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that only required characters are XML escaped in body.
|
||||
*
|
||||
* @see <a href="https://issues.igniterealtime.org/browse/SMACK-892">SMACK-892</a>
|
||||
*/
|
||||
@Test
|
||||
public void escapeInBodyTest() {
|
||||
String theFive = "\"'<>&";
|
||||
Message.Body body = new Message.Body(null, theFive);
|
||||
|
||||
assertEquals("<body xmlns='jabber:client'>\"'<>&</body>", body.toXML().toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue