use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.
the class MessageFasteningElementsTest method ensureAddFasteningElementToStanzaWorks.
@Test
public void ensureAddFasteningElementToStanzaWorks() {
MessageBuilder message = stanzaFactory.buildMessageStanza();
FasteningElement fasteningElement = FasteningElement.builder().setOriginId("another-apply-to").build();
// Adding only one element is allowed
fasteningElement.applyTo(message);
}
use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.
the class FasteningElementProvider method parse.
@Override
public FasteningElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
FasteningElement.Builder builder = FasteningElement.builder();
builder.setOriginId(parser.getAttributeValue("", FasteningElement.ATTR_ID));
if (ParserUtils.getBooleanAttribute(parser, FasteningElement.ATTR_CLEAR, false)) {
builder.setClear();
}
if (ParserUtils.getBooleanAttribute(parser, FasteningElement.ATTR_SHELL, false)) {
builder.setShell();
}
outerloop: while (true) {
XmlPullParser.Event tag = parser.next();
switch(tag) {
case START_ELEMENT:
String name = parser.getName();
String namespace = parser.getNamespace();
// Parse external payload
if (MessageFasteningManager.NAMESPACE.equals(namespace) && ExternalElement.ELEMENT.equals(name)) {
ExternalElement external = new ExternalElement(parser.getAttributeValue("", ExternalElement.ATTR_NAME), parser.getAttributeValue("", ExternalElement.ATTR_ELEMENT_NAMESPACE));
builder.addExternalPayload(external);
continue;
}
// Parse wrapped payload
XmlElement wrappedPayload = PacketParserUtils.parseExtensionElement(name, namespace, parser, xmlEnvironment);
builder.addWrappedPayload(wrappedPayload);
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
break;
}
}
return builder.build();
}
use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.
the class MessageRetractionManager method addRetractionElementToMessage.
/**
* Append a {@link RetractElement} wrapped inside a {@link FasteningElement} which contains
* the {@link OriginIdElement Origin-ID} of the message that will be retracted to the given {@link MessageBuilder}.
*
* @param retractedMessageId {@link OriginIdElement OriginID} of the message that the user wants to retract
* @param carrierMessageBuilder message used to transmit the message retraction to the recipient
*/
public static void addRetractionElementToMessage(OriginIdElement retractedMessageId, MessageBuilder carrierMessageBuilder) {
FasteningElement fasteningElement = FasteningElement.builder().setOriginId(retractedMessageId).addWrappedPayload(new RetractElement()).build();
fasteningElement.applyTo(carrierMessageBuilder);
}
use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.
the class MessageFasteningElementsTest method fasteningDeserializationClearTest.
@Test
public void fasteningDeserializationClearTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<apply-to xmlns='urn:xmpp:fasten:0' id='origin-id-1' clear='true'>" + " <i-like-this xmlns='urn:example:like'/>" + "</apply-to>";
FasteningElement parsed = FasteningElementProvider.TEST_INSTANCE.parse(TestUtils.getParser(xml));
assertTrue(parsed.isRemovingElement());
}
Aggregations