Java Code Examples for org.jivesoftware.smackx.xdata.packet.DataForm#from()

The following examples show how to use org.jivesoftware.smackx.xdata.packet.DataForm#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleUserSearch.java    From Smack with Apache License 2.0 6 votes vote down vote up
private String getItemsToSearch() {
    StringBuilder buf = new StringBuilder();

    if (form == null) {
        form = DataForm.from(this);
    }

    if (form == null) {
        return "";
    }

    for (FormField field : form.getFields()) {
        String name = field.getFieldName();
        String value = getSingleValue(field);
        if (value.trim().length() > 0) {
            buf.append('<').append(name).append('>').append(value).append("</").append(name).append('>');
        }
    }

    return buf.toString();
}
 
Example 2
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private MamPrefsResult queryMamPrefs(MamPrefsIQ mamPrefsIQ) throws NoResponseException, XMPPErrorException,
        NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();

    MamPrefsIQ mamPrefsResultIQ = connection.createStanzaCollectorAndSend(mamPrefsIQ).nextResultOrThrow();

    return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ));
}
 
Example 3
Source File: SoftwareInfoManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Get Software Information from the provided XMPP address. Returns <code>null</code> in case the queried entity does not announce that information.
 *
 * @param jid jid to get software information from
 * @return {@link SoftwareInfoForm} Form containing software information or <code>null</code>.
 * @throws NoResponseException if there was no response from the remote entity
 * @throws XMPPErrorException if there was an XMPP error returned
 * @throws NotConnectedException if the XMPP connection is not connected
 * @throws InterruptedException if the calling thread was interrupted
 */
public SoftwareInfoForm fromJid(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(jid);
    DataForm dataForm = DataForm.from(discoverInfo, SoftwareInfoForm.FORM_TYPE);
    if (dataForm == null) {
        return null;
    }
    return SoftwareInfoForm.getBuilder()
                           .setDataForm(dataForm)
                           .build();
}
 
Example 4
Source File: ReportedData.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new ReportedData if the stanza is used for reporting data and includes an
 * extension that matches the elementName and namespace "x","jabber:x:data".
 *
 * @param packet the stanza used for reporting data.
 * @return ReportedData from the packet if present, otherwise null.
 */
public static ReportedData getReportedDataFrom(Stanza packet) {
    // Check if the packet includes the DataForm extension
    DataForm dataForm = DataForm.from(packet);
    if (dataForm != null) {
        if (dataForm.getReportedData() != null)
            return new ReportedData(dataForm);
    }
    // Otherwise return null
    return null;
}
 
Example 5
Source File: Form.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static Form from(StanzaView stanzaView) {
    DataForm dataForm = DataForm.from(stanzaView);
    if (dataForm == null || dataForm.getType() != Type.form) {
        return null;
    }
    return new Form(dataForm);
}
 
Example 6
Source File: MamManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private MamQuery queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException,
                NotConnectedException, InterruptedException, NotLoggedInException {
    MamQueryPage mamQueryPage = queryArchivePage(mamQueryIq);
    return new MamQuery(mamQueryPage, mamQueryIq.getNode(), DataForm.from(mamQueryIq));
}
 
Example 7
Source File: MultiUserChat.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the room's configuration form that the room's owner can use or <code>null</code> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <code>null</code> if no configuration is possible.
 * @throws XMPPErrorException if an error occurs asking the configuration form for the room.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public Form getConfigurationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.get);

    IQ answer = connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
    DataForm dataForm = DataForm.from(answer, MucConfigFormManager.FORM_TYPE);
    return new Form(dataForm);
}
 
Example 8
Source File: MultiUserChat.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <code>null</code> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <code>null</code> if no registration is possible.
 * @throws XMPPErrorException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public Form getRegistrationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.get);
    reg.setTo(room);

    IQ result = connection.createStanzaCollectorAndSend(reg).nextResultOrThrow();
    DataForm dataForm = DataForm.from(result);
    return new Form(dataForm);
}
 
Example 9
Source File: UserSearch.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the form for all search fields supported by the search service.
 *
 * @param con           the current XMPPConnection.
 * @param searchService the search service to use. (ex. search.jivesoftware.com)
 * @return the search form received by the server.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public DataForm getSearchForm(XMPPConnection con, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.get);
    search.setTo(searchService);

    IQ response = con.createStanzaCollectorAndSend(search).nextResultOrThrow();
    return DataForm.from(response, NAMESPACE);
}
 
Example 10
Source File: OfflineMessageManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the number of offline messages for the user of the connection.
 *
 * @return the number of offline messages for the user of the connection.
 * @throws XMPPErrorException If the user is not allowed to make this request or the server does
 *                       not support offline message retrieval.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo info = serviceDiscoveryManager.discoverInfo(null, namespace);
    DataForm dataForm = DataForm.from(info, namespace);
    if (dataForm == null) {
        return 0;
    }
    String numberOfMessagesString = dataForm.getField("number_of_messages").getFirstValue();
    return Integer.parseInt(numberOfMessagesString);
}