Search in sources :

Example 16 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class TranscriptManager method getTranscripts.

/**
 * Returns the transcripts of a given user. The answer will contain the complete history of
 * conversations that a user had.
 *
 * @param userID the id of the user to get his conversations.
 * @param workgroupJID the JID of the workgroup that will process the request.
 * @return the transcripts of a given user.
 * @throws XMPPException if an error occurs while getting the information.
 */
public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException {
    Transcripts request = new Transcripts(userID);
    request.setTo(workgroupJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);
    Transcripts response = (Transcripts) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response;
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) Transcripts(org.jivesoftware.smackx.workgroup.packet.Transcripts)

Example 17 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class TranscriptSearchManager method submitSearch.

/**
 * Submits the completed form and returns the result of the transcript search. The result
 * will include all the data returned from the server so be careful with the amount of
 * data that the search may return.
 *
 * @param serviceJID    the address of the workgroup service.
 * @param completedForm the filled out search form.
 * @return the result of the transcript search.
 * @throws XMPPException if an error occurs while submiting the search to the server.
 */
public ReportedData submitSearch(String serviceJID, Form completedForm) throws XMPPException {
    TranscriptSearch search = new TranscriptSearch();
    search.setType(IQ.Type.GET);
    search.setTo(serviceJID);
    search.addExtension(completedForm.getDataFormToSend());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID()));
    connection.sendPacket(search);
    TranscriptSearch response = (TranscriptSearch) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return ReportedData.getReportedDataFrom(response);
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) TranscriptSearch(org.jivesoftware.smackx.workgroup.packet.TranscriptSearch) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 18 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class PrivateDataManager method getPrivateData.

/**
 * Returns the private data specified by the given element name and namespace. Each chunk
 * of private data is uniquely identified by an element name and namespace pair.<p>
 *
 * If a PrivateDataProvider is registered for the specified element name/namespace pair then
 * that provider will determine the specific object type that is returned. If no provider
 * is registered, a {@link DefaultPrivateData} instance will be returned.
 *
 * @param elementName the element name.
 * @param namespace the namespace.
 * @return the private data.
 * @throws XMPPException if an error occurs getting the private data.
 */
public PrivateData getPrivateData(final String elementName, final String namespace) throws XMPPException {
    // Create an IQ packet to get the private data.
    IQ privateDataGet = new IQ() {

        public String getChildElementXML() {
            StringBuilder buf = new StringBuilder();
            buf.append("<query xmlns=\"jabber:iq:private\">");
            buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\"/>");
            buf.append("</query>");
            return buf.toString();
        }
    };
    privateDataGet.setType(IQ.Type.GET);
    // Address the packet to the other account if user has been set.
    if (user != null) {
        privateDataGet.setTo(user);
    }
    // Setup a listener for the reply to the set operation.
    String packetID = privateDataGet.getPacketID();
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));
    // Send the private data.
    connection.sendPacket(privateDataGet);
    // Wait up to five seconds for a response from the server.
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    } else // If the server replied with an error, throw an exception.
    if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
    return ((PrivateDataResult) response).getPrivateData();
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 19 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class PrivateDataManager method setPrivateData.

/**
 * Sets a private data value. Each chunk of private data is uniquely identified by an
 * element name and namespace pair. If private data has already been set with the
 * element name and namespace, then the new private data will overwrite the old value.
 *
 * @param privateData the private data.
 * @throws XMPPException if setting the private data fails.
 */
public void setPrivateData(final PrivateData privateData) throws XMPPException {
    // Create an IQ packet to set the private data.
    IQ privateDataSet = new IQ() {

        public String getChildElementXML() {
            StringBuilder buf = new StringBuilder();
            buf.append("<query xmlns=\"jabber:iq:private\">");
            buf.append(privateData.toXML());
            buf.append("</query>");
            return buf.toString();
        }
    };
    privateDataSet.setType(IQ.Type.SET);
    // Address the packet to the other account if user has been set.
    if (user != null) {
        privateDataSet.setTo(user);
    }
    // Setup a listener for the reply to the set operation.
    String packetID = privateDataSet.getPacketID();
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));
    // Send the private data.
    connection.sendPacket(privateDataSet);
    // Wait up to five seconds for a response from the server.
    IQ response = (IQ) collector.nextResult(5000);
    // Stop queuing results
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    } else // If the server replied with an error, throw an exception.
    if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 20 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class ServiceDiscoveryManager method discoverItems.

/**
 * Returns the discovered items of a given XMPP entity addressed by its JID and
 * note attribute. Use this message only when trying to query information which is not
 * directly addressable.
 *
 * @param entityID the address of the XMPP entity.
 * @param node the optional attribute that supplements the 'jid' attribute.
 * @return the discovered items.
 * @throws XMPPException if the operation failed for some reason.
 */
public DiscoverItems discoverItems(String entityID, String node) throws XMPPException {
    // Discover the entity's items
    DiscoverItems disco = new DiscoverItems();
    disco.setType(IQ.Type.GET);
    disco.setTo(entityID);
    disco.setNode(node);
    // Create a packet collector to listen for a response.
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
    connection.sendPacket(disco);
    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return (DiscoverItems) result;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)66 IQ (org.jivesoftware.smack.packet.IQ)38 PacketCollector (org.jivesoftware.smack.PacketCollector)36 XMPPException (org.jivesoftware.smack.XMPPException)34 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)22 Packet (org.jivesoftware.smack.packet.Packet)10 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 Registration (org.jivesoftware.smack.packet.Registration)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 RosterPacket (org.jivesoftware.smack.packet.RosterPacket)4 ArrayList (java.util.ArrayList)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Authentication (org.jivesoftware.smack.packet.Authentication)2