Package org.xmpp.packet

Examples of org.xmpp.packet.Presence


        ExternalizableUtil.getInstance().writeByteArray(out, nodeID.toByteArray());
    }

    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        serviceDomain = ExternalizableUtil.getInstance().readSafeUTF(in);
        presence = new Presence((Element)ExternalizableUtil.getInstance().readSerializable(in), true);
        role = Role.values()[ExternalizableUtil.getInstance().readInt(in)];
        affiliation = Affiliation.values()[ExternalizableUtil.getInstance().readInt(in)];
        nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
        voiceOnly = ExternalizableUtil.getInstance().readBoolean(in);
        roleAddress = (JID) ExternalizableUtil.getInstance().readSerializable(in);
View Full Code Here


                if (packet instanceof Presence) {
                    if (((Presence)packet).getType() == Presence.Type.error) {
                        // Skip Presence packets of type error
                        return;
                    }
                    Presence reply = new Presence();
                    reply.setID(packet.getID());
                    reply.setTo(packet.getFrom());
                    reply.setFrom(packet.getTo());
                    reply.setError(PacketError.Condition.not_authorized);
                    send(reply);
                }
                else if (packet instanceof IQ) {
                    if (((IQ)packet).getType() == IQ.Type.error) {
                        // Skip IQ packets of type error
                        return;
                    }
                    IQ reply = IQ.createResultIQ((IQ)packet);
                    reply.setChildElement(((IQ)packet).getChildElement().createCopy());
                    reply.setError(PacketError.Condition.not_authorized);
                    send(reply);
                }
                else {
                    if (((Message)packet).getType() == Message.Type.error) {
                        // Skip Message packets of type error
                        return;
                    }
                    Message reply = new Message();
                    reply.setID(packet.getID());
                    reply.setTo(packet.getFrom());
                    reply.setFrom(packet.getTo());
                    reply.setError(PacketError.Condition.not_authorized);
                    send(reply);
                }
            }
        }
        catch (Exception e) {
View Full Code Here

                }

                if (!isOnline) {
                    // Send offline presence to workgroup.
                    for (Workgroup wgroup : agentSession.getWorkgroups()) {
                        Presence presence = new Presence();
                        presence.setFrom(agentJID);
                        presence.setTo(wgroup.getJID());
                        presence.setType(Presence.Type.unavailable);
                        wgroup.getWorkgroupPresenceHandler().process(presence);
                    }
                }
            }
        }
View Full Code Here

    }
   
    public void testFilterAvailablePresence() throws Exception {
       
        // setup available presence
        Presence presence = new Presence();
        presence.setStatus("fox is now online!");
        System.out.println(presence.toXML());
       
        // filter on the word "fox" and "dog"
        filter.setPatterns("fox,dog");
        filter.setMask("**");
       
        boolean matched = filter.filter(presence);

        // matches should not be found
        assertTrue(matched);

        // content has changed
        assertEquals("** is now online!", presence.getStatus());
       
    }
View Full Code Here

            "</presence>";
       
       
        XPPReader packetReader = new XPPReader();
        Document doc = packetReader.read(new StringReader(presenceXML));
        Presence p = new Presence(doc.getRootElement());
       
        // filter on the word "fox" and "dog"
        filter.setPatterns("fox,dog,message");
        filter.setMask("**");
       
        String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
        // do filter
        boolean matched = filter.filter(p);       
        assertTrue(matched);
        assertEquals(expectedXML, expectedXML, p.toXML());
       
    }
View Full Code Here

    public AgentSession(JID address, Agent agent) {
        this.id = -1;
        this.agent = agent;
        this.address = address;
        maxChats = -1;
        presence = new Presence();
    }
View Full Code Here

     *
     * @param packet the new presence sent by the agent.
     */
    public void updatePresence(Presence packet) {
        // Create a copy of the received Presence to use as the presence of the AgentSession
        Presence sessionPresence = packet.createCopy();
        // Remove the "agent-status" element from the new AgentSession's presence
        Element child = sessionPresence.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
        sessionPresence.getElement().remove(child);
        // Set the new presence to the AgentSession
        presence = sessionPresence;

        // Set the new maximum number of chats and the number of current chats to the
        // AgentSession based on the values sent within the presence (if any)
View Full Code Here

     * @param workgroup the workgroup whose agents' presences will be sent to this agent.
     */
    private void sendStatusOfAllAgents(Workgroup workgroup) {
        for (AgentSession agentSession : workgroup.getAgentSessions()) {
            if (!agentSession.getJID().equals(address)) {
                Presence statusPacket = agentSession.getPresence().createCopy();
                statusPacket.setFrom(agentSession.getJID());
                statusPacket.setTo(address);
                // Add the agent-status element
                agentSession.getAgentStatus(statusPacket,workgroup);
                workgroup.send(statusPacket);
            }
        }
View Full Code Here

    private void sendStatusToAllAgents(Workgroup workgroup) {
        for (AgentSession agentSession : workgroup.getAgentSessions()) {
            // Only send presences to Agents that are available and had requested to
            // receive other agents' information
            if (agentSession.hasRequestedAgentInfo() && !agentSession.getJID().equals(address)) {
                Presence statusPacket = presence.createCopy();
                statusPacket.setFrom(address);
                statusPacket.setTo(agentSession.getJID());
                // Add the agent-status element
                getAgentStatus(statusPacket, workgroup);

                workgroup.send(statusPacket);
            }
View Full Code Here

    }

    public void processPacket(Packet packet) {
        // Check that we are getting an answer to a presence probe
        if (packet instanceof Presence) {
            Presence presence = (Presence) packet;
            if (presence.isAvailable() || presence.getType() == Presence.Type.unavailable ||
                    presence.getType() == Presence.Type.error) {
                // Store answer of presence probes
                probedPresence.put(presence.getFrom().toString(), presence);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.xmpp.packet.Presence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.