Search in sources :

Example 16 with JivePropertiesExtension

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

the class ChatRoom method addToTranscript.

/**
 * Adds a new message to the transcript history.
 *
 * @param to   who the message is to.
 * @param from who the message was from.
 * @param body the body of the message.
 * @param date when the message was received.
 */
public void addToTranscript(String to, String from, String body, Date date) {
    final Message newMessage = new Message();
    newMessage.setTo(to);
    newMessage.setFrom(from);
    newMessage.setBody(body);
    final Map<String, Object> properties = new HashMap<>();
    properties.put("date", new Date());
    newMessage.addExtension(new JivePropertiesExtension(properties));
    transcript.add(newMessage);
}
Also used : Message(org.jivesoftware.smack.packet.Message) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 17 with JivePropertiesExtension

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

the class CoBrowser method pushPage.

private void pushPage(String link) {
    updateLinkLabel(link);
    // If the disable box is not selected, update customer with
    // page push.
    final Message mes = new Message();
    final Map<String, Object> properties = new HashMap<>();
    properties.put("PUSH_URL", link);
    mes.addExtension(new JivePropertiesExtension(properties));
    mes.setBody(FpRes.getString("message.start.cobrowsing", link));
    chatRoom.getTranscriptWindow().insertNotificationMessage(FpRes.getString("message.send.cobrowsing.message", link), ChatManager.NOTIFICATION_COLOR);
    send(mes);
    pushField.setText("");
    load(link);
}
Also used : Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 18 with JivePropertiesExtension

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

the class CoBrowser method navigateUser.

private void navigateUser(String href) {
    if (followMeButton.isSelected() && hasLoaded) {
        final Message mes = new Message();
        final Map<String, Object> properties = new HashMap<>();
        properties.put("PUSH_URL", href);
        mes.addExtension(new JivePropertiesExtension(properties));
        mes.setBody("");
        send(mes);
        updateLinkLabel(href);
        hasLoaded = false;
    } else {
        updateLinkLabel(href);
    }
    hasLoaded = true;
}
Also used : Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 19 with JivePropertiesExtension

use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project spring-integration by spring-projects.

the class DefaultXmppHeaderMapper method extractUserDefinedHeaders.

@Override
protected Map<String, Object> extractUserDefinedHeaders(Message source) {
    Map<String, Object> headers = new HashMap<>();
    JivePropertiesExtension jpe = (JivePropertiesExtension) source.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe == null) {
        return headers;
    }
    for (String propertyName : jpe.getPropertyNames()) {
        headers.put(propertyName, JivePropertiesManager.getProperty(source, propertyName));
    }
    return headers;
}
Also used : HashMap(java.util.HashMap) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 20 with JivePropertiesExtension

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

the class JivePropertiesExtensionProvider method parse.

/**
 * Parse a properties sub-packet. If any errors occur while de-serializing Java object
 * properties, an exception will be printed and not thrown since a thrown exception will shut
 * down the entire connection. ClassCastExceptions will occur when both the sender and receiver
 * of the stanza don't have identical versions of the same class.
 * <p>
 * Note that you have to explicitly enabled Java object deserialization with @{link
 * {@link JivePropertiesManager#setJavaObjectEnabled(boolean)}
 *
 * @param parser the XML parser, positioned at the start of a properties sub-packet.
 * @return a map of the properties.
 * @throws IOException if an I/O error occurred.
 * @throws XmlPullParserException if an error in the XML parser occurred.
 */
@SuppressWarnings("BanSerializableRead")
@Override
public JivePropertiesExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    Map<String, Object> properties = new HashMap<>();
    while (true) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("property")) {
            // Parse a property
            boolean done = false;
            String name = null;
            String type = null;
            String valueText = null;
            Object value = null;
            while (!done) {
                eventType = parser.next();
                if (eventType == XmlPullParser.Event.START_ELEMENT) {
                    String elementName = parser.getName();
                    if (elementName.equals("name")) {
                        name = parser.nextText();
                    } else if (elementName.equals("value")) {
                        type = parser.getAttributeValue("", "type");
                        valueText = parser.nextText();
                    }
                } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
                    if (parser.getName().equals("property")) {
                        if ("integer".equals(type)) {
                            value = Integer.valueOf(valueText);
                        } else if ("long".equals(type)) {
                            value = Long.valueOf(valueText);
                        } else if ("float".equals(type)) {
                            value = Float.valueOf(valueText);
                        } else if ("double".equals(type)) {
                            value = Double.valueOf(valueText);
                        } else if ("boolean".equals(type)) {
                            // CHECKSTYLE:OFF
                            value = Boolean.valueOf(valueText);
                        // CHECKSTYLE:ON
                        } else if ("string".equals(type)) {
                            value = valueText;
                        } else if ("java-object".equals(type)) {
                            if (JivePropertiesManager.isJavaObjectEnabled()) {
                                try {
                                    byte[] bytes = Base64.decode(valueText);
                                    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
                                    value = in.readObject();
                                } catch (Exception e) {
                                    LOGGER.log(Level.SEVERE, "Error parsing java object", e);
                                }
                            } else {
                                LOG_OBJECT_NOT_ENABLED.once(() -> LOGGER.severe("JavaObject is not enabled. Enable with JivePropertiesManager.setJavaObjectEnabled(true)"));
                            }
                        }
                        if (name != null && value != null) {
                            properties.put(name, value);
                        }
                        done = true;
                    }
                }
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getName().equals(JivePropertiesExtension.ELEMENT)) {
                break;
            }
        }
    }
    return new JivePropertiesExtension(properties);
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) IOException(java.io.IOException) XmlPullParserException(org.jivesoftware.smack.xml.XmlPullParserException) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) ObjectInputStream(java.io.ObjectInputStream)

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