Search in sources :

Example 6 with JivePropertiesExtension

use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Spark by igniterealtime.

the class Workspace method loadPlugins.

/**
 * Starts the Loading of all Spark Plugins.
 */
public void loadPlugins() {
    // Send Available status
    SparkManager.getSessionManager().changePresence(statusBox.getPresence());
    // Add presence and message listeners
    // we listen for these to force open a 1-1 peer chat window from other operators if
    // one isn't already open
    StanzaFilter workspaceMessageFilter = new StanzaTypeFilter(Message.class);
    // Add the packetListener to this instance
    SparkManager.getSessionManager().getConnection().addAsyncStanzaListener(this, workspaceMessageFilter);
    // Make presence available to anonymous requests, if from anonymous user in the system.
    StanzaListener workspacePresenceListener = stanza -> {
        Presence presence = (Presence) stanza;
        JivePropertiesExtension extension = (JivePropertiesExtension) presence.getExtension(JivePropertiesExtension.NAMESPACE);
        if (extension != null && extension.getProperty("anonymous") != null) {
            boolean isAvailable = statusBox.getPresence().getMode() == Presence.Mode.available;
            Presence reply = new Presence(Presence.Type.available);
            if (!isAvailable) {
                reply.setType(Presence.Type.unavailable);
            }
            reply.setTo(presence.getFrom());
            try {
                SparkManager.getSessionManager().getConnection().sendStanza(reply);
            } catch (SmackException.NotConnectedException e) {
                Log.warning("Unable to send presence reply to " + reply.getTo(), e);
            }
        }
    };
    SparkManager.getSessionManager().getConnection().addAsyncStanzaListener(workspacePresenceListener, new StanzaTypeFilter(Presence.class));
    // Until we have better plugin management, will init after presence updates.
    gatewayPlugin = new GatewayPlugin();
    gatewayPlugin.initialize();
    // Load all non-presence related items.
    conferences.loadConferenceBookmarks();
    SearchManager.getInstance();
    transcriptPlugin = new ChatTranscriptPlugin();
    // Load Broadcast Plugin
    broadcastPlugin = new BroadcastPlugin();
    broadcastPlugin.initialize();
    // Load BookmarkPlugin
    bookmarkPlugin = new BookmarkPlugin();
    bookmarkPlugin.initialize();
    // Schedule loading of the plugins after two seconds.
    TaskEngine.getInstance().schedule(new TimerTask() {

        public void run() {
            final PluginManager pluginManager = PluginManager.getInstance();
            SparkManager.getMainWindow().addMainWindowListener(pluginManager);
            pluginManager.initializePlugins();
            // Subscriptions are always manual
            Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
            roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
        }
    }, 2000);
    // Check URI Mappings
    SparkManager.getChatManager().handleURIMapping(Spark.ARGUMENTS);
}
Also used : Color(java.awt.Color) SmackException(org.jivesoftware.smack.SmackException) CommandPanel(org.jivesoftware.spark.ui.CommandPanel) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) Log(org.jivesoftware.spark.util.log.Log) ContactItem(org.jivesoftware.spark.ui.ContactItem) MainWindow(org.jivesoftware.MainWindow) TimerTask(java.util.TimerTask) Enterprise(org.jivesoftware.sparkimpl.plugin.manager.Enterprise) KeyStroke(javax.swing.KeyStroke) TaskEngine(org.jivesoftware.spark.util.TaskEngine) ModelUtil(org.jivesoftware.spark.util.ModelUtil) BorderFactory(javax.swing.BorderFactory) SparkTabbedPane(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane) GridBagConstraints(java.awt.GridBagConstraints) Spark(org.jivesoftware.Spark) GatewayPlugin(org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin) AbstractAction(javax.swing.AbstractAction) Roster(org.jivesoftware.smack.roster.Roster) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) StanzaListener(org.jivesoftware.smack.StanzaListener) Stanza(org.jivesoftware.smack.packet.Stanza) BroadcastPlugin(org.jivesoftware.sparkimpl.plugin.alerts.BroadcastPlugin) Insets(java.awt.Insets) CardLayout(java.awt.CardLayout) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) UIComponentRegistry(org.jivesoftware.spark.util.UIComponentRegistry) MainWindowListener(org.jivesoftware.MainWindowListener) SwingUtilities(javax.swing.SwingUtilities) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) Default(org.jivesoftware.resource.Default) JTabbedPane(javax.swing.JTabbedPane) StatusBar(org.jivesoftware.spark.ui.status.StatusBar) EnhancedDebuggerWindow(org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow) BookmarkPlugin(org.jivesoftware.sparkimpl.plugin.bookmarks.BookmarkPlugin) ChatContainer(org.jivesoftware.spark.ui.ChatContainer) JComponent(javax.swing.JComponent) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) Presence(org.jivesoftware.smack.packet.Presence) SearchManager(org.jivesoftware.spark.search.SearchManager) SparkTransferManager(org.jivesoftware.spark.filetransfer.SparkTransferManager) ActionEvent(java.awt.event.ActionEvent) ConferenceServices(org.jivesoftware.spark.ui.conferences.ConferenceServices) XmppStringUtils(org.jxmpp.util.XmppStringUtils) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) ContactList(org.jivesoftware.spark.ui.ContactList) Message(org.jivesoftware.smack.packet.Message) ChatTranscriptPlugin(org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscriptPlugin) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) ChatTranscriptPlugin(org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscriptPlugin) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) StanzaListener(org.jivesoftware.smack.StanzaListener) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) BroadcastPlugin(org.jivesoftware.sparkimpl.plugin.alerts.BroadcastPlugin) BookmarkPlugin(org.jivesoftware.sparkimpl.plugin.bookmarks.BookmarkPlugin) TimerTask(java.util.TimerTask) Roster(org.jivesoftware.smack.roster.Roster) GatewayPlugin(org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin) Presence(org.jivesoftware.smack.packet.Presence)

Example 7 with JivePropertiesExtension

use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Smack by igniterealtime.

the class JivePropertiesManager method getProperty.

/**
 * Convenience method to get a property from a packet. Will return null if the stanza contains
 * not property with the given name.
 *
 * @param packet TODO javadoc me please
 * @param name TODO javadoc me please
 * @return the property or <code>null</code> if none found.
 */
public static Object getProperty(StanzaView packet, String name) {
    Object res = null;
    JivePropertiesExtension jpe = packet.getExtension(JivePropertiesExtension.class);
    if (jpe != null) {
        res = jpe.getProperty(name);
    }
    return res;
}
Also used : JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 8 with JivePropertiesExtension

use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Smack by igniterealtime.

the class JivePropertiesManager method addProperty.

/**
 * Convenience method to add a property to a stanza.
 *
 * @param stanzaBuilder the stanza to add the property to.
 * @param name the name of the property to add.
 * @param value the value of the property to add.
 */
public static void addProperty(StanzaBuilder<?> stanzaBuilder, String name, Object value) {
    JivePropertiesExtension jpe = (JivePropertiesExtension) stanzaBuilder.getExtension(JivePropertiesExtension.QNAME);
    if (jpe == null) {
        jpe = new JivePropertiesExtension();
        stanzaBuilder.addExtension(jpe);
    }
    jpe.setProperty(name, value);
}
Also used : JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 9 with JivePropertiesExtension

use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Smack by igniterealtime.

the class JivePropertiesExtensionTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String properties = "<message xmlns='jabber:client' from='romeo@example.net/orchard' to='juliet@example.com/balcony'>" + "<body>Neither, fair saint, if either thee dislike.</body>" + "<properties xmlns='http://www.jivesoftware.com/xmlns/xmpp/properties'>" + "<property>" + "<name>FooBar</name>" + "<value type='integer'>42</value>" + "</property>" + "</properties>" + "</message>";
    // @formatter:on
    Message message = PacketParserUtils.parseStanza(properties);
    JivePropertiesExtension jpe = JivePropertiesExtension.from(message);
    assertNotNull(jpe);
    Integer integer = (Integer) jpe.getProperty("FooBar");
    assertNotNull(integer);
    int fourtytwo = integer;
    assertEquals(42, fourtytwo);
}
Also used : Message(org.jivesoftware.smack.packet.Message) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) Test(org.junit.jupiter.api.Test)

Example 10 with JivePropertiesExtension

use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project camel by apache.

the class XmppBinding method extractHeadersFromXmpp.

public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
    Map<String, Object> answer = new HashMap<String, Object>();
    PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null && jpe instanceof JivePropertiesExtension) {
        extractHeadersFrom((JivePropertiesExtension) jpe, exchange, answer);
    }
    if (jpe != null && jpe instanceof DefaultPacketExtension) {
        extractHeadersFrom((DefaultPacketExtension) jpe, exchange, answer);
    }
    if (xmppPacket instanceof Message) {
        Message xmppMessage = (Message) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
        answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
        answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
    } else if (xmppPacket instanceof PubSub) {
        PubSub pubsubPacket = (PubSub) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
    }
    answer.put(XmppConstants.FROM, xmppPacket.getFrom());
    answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
    answer.put(XmppConstants.TO, xmppPacket.getTo());
    return answer;
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Aggregations

JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)22 Message (org.jivesoftware.smack.packet.Message)13 HashMap (java.util.HashMap)7 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 Date (java.util.Date)2 SmackException (org.jivesoftware.smack.SmackException)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Stanza (org.jivesoftware.smack.packet.Stanza)2 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)2 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 CardLayout (java.awt.CardLayout)1 Color (java.awt.Color)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 BufferedWriter (java.io.BufferedWriter)1