Search in sources :

Example 31 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class NodeUtils method getFormFromPacket.

/**
 * Get a {@link ConfigureForm} from a packet.
 *
 * @param packet TODO javadoc me please
 * @param elem TODO javadoc me please
 * @return The configuration form
 */
public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem) {
    FormNode config = (FormNode) packet.getExtensionElement(elem.getElementName(), elem.getNamespace().getXmlns());
    DataForm dataForm = config.getForm();
    return new ConfigureForm(dataForm);
}
Also used : FormNode(org.jivesoftware.smackx.pubsub.FormNode) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ConfigureForm(org.jivesoftware.smackx.pubsub.form.ConfigureForm)

Example 32 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class DataFormProvider method parse.

@Override
public DataForm parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    DataForm.Type dataFormType = DataForm.Type.fromString(parser.getAttributeValue("", "type"));
    DataForm.Builder dataForm = DataForm.builder(dataFormType);
    String formType = null;
    DataForm.ReportedData reportedData = null;
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch(eventType) {
            case START_ELEMENT:
                String name = parser.getName();
                String namespace = parser.getNamespace();
                XmlEnvironment elementXmlEnvironment = XmlEnvironment.from(parser, xmlEnvironment);
                switch(name) {
                    case "instructions":
                        dataForm.addInstruction(parser.nextText());
                        break;
                    case "title":
                        dataForm.setTitle(parser.nextText());
                        break;
                    case "field":
                        // Note that we parse this form field without any potential reportedData. We only use reportedData
                        // to lookup form field types of fields under <item/>.
                        FormField formField = parseField(parser, elementXmlEnvironment, formType);
                        TextSingleFormField hiddenFormTypeField = formField.asHiddenFormTypeFieldIfPossible();
                        if (hiddenFormTypeField != null) {
                            if (formType != null) {
                                throw new SmackParsingException("Multiple hidden form type fields");
                            }
                            formType = hiddenFormTypeField.getValue();
                        }
                        dataForm.addField(formField);
                        break;
                    case "item":
                        DataForm.Item item = parseItem(parser, elementXmlEnvironment, formType, reportedData);
                        dataForm.addItem(item);
                        break;
                    case "reported":
                        if (reportedData != null) {
                            throw new SmackParsingException("Data form with multiple <reported/> elements");
                        }
                        reportedData = parseReported(parser, elementXmlEnvironment, formType);
                        dataForm.setReportedData(reportedData);
                        break;
                    // See XEP-133 Example 32 for a corner case where the data form contains this extension.
                    case RosterPacket.ELEMENT:
                        if (namespace.equals(RosterPacket.NAMESPACE)) {
                            dataForm.addExtensionElement(RosterPacketProvider.INSTANCE.parse(parser));
                        }
                        break;
                    // See XEP-141 Data Forms Layout
                    case DataLayout.ELEMENT:
                        if (namespace.equals(DataLayout.NAMESPACE)) {
                            dataForm.addExtensionElement(DataLayoutProvider.parse(parser));
                        }
                        break;
                }
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
    return dataForm.build();
}
Also used : TextSingleFormField(org.jivesoftware.smackx.xdata.TextSingleFormField) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ListMultiFormField(org.jivesoftware.smackx.xdata.ListMultiFormField) AbstractSingleStringValueFormField(org.jivesoftware.smackx.xdata.AbstractSingleStringValueFormField) BooleanFormField(org.jivesoftware.smackx.xdata.BooleanFormField) FormField(org.jivesoftware.smackx.xdata.FormField) ListSingleFormField(org.jivesoftware.smackx.xdata.ListSingleFormField) JidMultiFormField(org.jivesoftware.smackx.xdata.JidMultiFormField) TextSingleFormField(org.jivesoftware.smackx.xdata.TextSingleFormField) AbstractMultiFormField(org.jivesoftware.smackx.xdata.AbstractMultiFormField) JidSingleFormField(org.jivesoftware.smackx.xdata.JidSingleFormField) XmlEnvironment(org.jivesoftware.smack.packet.XmlEnvironment) SmackParsingException(org.jivesoftware.smack.parsing.SmackParsingException)

Example 33 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class RoomInfoTest method validateRoomWithEmptyForm.

@Test
public void validateRoomWithEmptyForm() {
    DataForm dataForm = DataForm.builder(DataForm.Type.result).build();
    DiscoverInfo discoInfo = DiscoverInfo.builder("disco1").addExtension(dataForm).build();
    RoomInfo roomInfo = new RoomInfo(discoInfo);
    assertTrue(roomInfo.getDescription().isEmpty());
    assertTrue(roomInfo.getSubject().isEmpty());
    assertEquals(-1, roomInfo.getOccupantsCount());
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Test(org.junit.jupiter.api.Test)

Example 34 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class EntityCapsManagerTest method createComplexSamplePacket.

private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException {
    DiscoverInfoBuilder di = DiscoverInfo.builder("disco1");
    di.from(JidCreate.from("benvolio@capulet.lit/230193"));
    di.to(JidCreate.from("juliet@capulet.lit/chamber"));
    di.ofType(IQ.Type.result);
    Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
    DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
    identities.add(i);
    i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
    identities.add(i);
    di.addIdentities(identities);
    di.addFeature("http://jabber.org/protocol/disco#items");
    di.addFeature(EntityCapsManager.NAMESPACE);
    di.addFeature("http://jabber.org/protocol/muc");
    di.addFeature("http://jabber.org/protocol/disco#info");
    DataForm softwareInfoDataForm = createSampleSoftwareInfoDataForm();
    di.addExtension(softwareInfoDataForm);
    return di.build();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DiscoverInfoBuilder(org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) LinkedList(java.util.LinkedList)

Example 35 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class EntityCapsManagerTest method createMalformedDiscoverInfo.

private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException {
    DiscoverInfoBuilder di = DiscoverInfo.builder("disco1");
    di.from("benvolio@capulet.lit/230193");
    di.to(")juliet@capulet.lit/chamber");
    di.ofType(IQ.Type.result);
    Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
    DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
    identities.add(i);
    i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
    identities.add(i);
    di.addIdentities(identities);
    // Failure 1: Duplicate identities
    i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
    identities.add(i);
    di.addIdentities(identities);
    di.addFeature("http://jabber.org/protocol/disco#items");
    di.addFeature(EntityCapsManager.NAMESPACE);
    di.addFeature("http://jabber.org/protocol/muc");
    di.addFeature("http://jabber.org/protocol/disco#info");
    // Failure 2: Duplicate features
    di.addFeature("http://jabber.org/protocol/disco#info");
    DataForm softwareInfoDataForm = createSampleSoftwareInfoDataForm();
    di.addExtension(softwareInfoDataForm);
    DiscoverInfo discoverInfo = di.buildWithoutValidiation();
    return discoverInfo;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DiscoverInfoBuilder(org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) LinkedList(java.util.LinkedList)

Aggregations

DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)65 FormField (org.jivesoftware.smackx.xdata.FormField)23 Test (org.junit.jupiter.api.Test)13 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 Feature (com.xabber.xmpp.ssn.Feature)7 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)7 Date (java.util.Date)5 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)5 OtrMode (com.xabber.xmpp.archive.OtrMode)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 LinkedList (java.util.LinkedList)3 IQ (org.jivesoftware.smack.packet.IQ)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)3 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)3 Form (org.jivesoftware.smackx.xdata.form.Form)3 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2