Search in sources :

Example 6 with FasteningElement

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);
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with FasteningElement

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();
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) XmlElement(org.jivesoftware.smack.packet.XmlElement) ExternalElement(org.jivesoftware.smackx.message_fastening.element.ExternalElement)

Example 8 with FasteningElement

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);
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) RetractElement(org.jivesoftware.smackx.message_retraction.element.RetractElement)

Example 9 with FasteningElement

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());
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FasteningElement (org.jivesoftware.smackx.message_fastening.element.FasteningElement)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Test (org.junit.jupiter.api.Test)6 ExternalElement (org.jivesoftware.smackx.message_fastening.element.ExternalElement)3 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)2 OriginIdElement (org.jivesoftware.smackx.sid.element.OriginIdElement)2 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 XmlElement (org.jivesoftware.smack.packet.XmlElement)1 RetractElement (org.jivesoftware.smackx.message_retraction.element.RetractElement)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1