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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations