use of org.dom4j.Element in project Openfire by igniterealtime.
the class WorkgroupFormProvider method handleGet.
public boolean handleGet(IQ packet) {
Element iq = packet.getChildElement();
String name = iq.getName();
if ("workgroup-form".equals(name)) {
return true;
}
return false;
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class ChatTranscriptManager method getTextTranscriptFromSessionID.
/**
* Return the plain text version of a chat transcript.
*
* @param sessionID the sessionID of the <code>ChatSession</code>
* @return the plain text version of a chat transcript.
*/
public static String getTextTranscriptFromSessionID(String sessionID) {
String transcript = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_SESSION_TRANSCRIPT);
pstmt.setString(1, sessionID);
rs = pstmt.executeQuery();
if (rs.next()) {
transcript = DbConnectionManager.getLargeTextField(rs, 1);
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
if (transcript == null || "".equals(transcript)) {
return "";
}
// Define time zone used in the transcript.
SimpleDateFormat UTC_FORMAT = new SimpleDateFormat(XMPPDateTimeFormat.XMPP_DELAY_DATETIME_FORMAT);
UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
Document element = null;
try {
element = DocumentHelper.parseText(transcript);
} catch (DocumentException e) {
Log.error(e.getMessage(), e);
}
StringBuilder buf = new StringBuilder();
// Add the Messages and Presences contained in the retrieved transcript element
for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext(); ) {
Element packet = it.next();
String name = packet.getName();
String message = "";
String from = "";
if ("presence".equals(name)) {
String type = packet.attributeValue("type");
from = new JID(packet.attributeValue("from")).getResource();
if (type == null) {
message = from + " has joined the room";
} else {
message = from + " has left the room";
}
} else if ("message".equals(name)) {
from = new JID(packet.attributeValue("from")).getResource();
message = packet.elementText("body");
message = StringUtils.escapeHTMLTags(message);
}
List<Element> el = packet.elements("x");
for (Element ele : el) {
if ("jabber:x:delay".equals(ele.getNamespaceURI())) {
String stamp = ele.attributeValue("stamp");
try {
String formattedDate;
synchronized (UTC_FORMAT) {
Date d = UTC_FORMAT.parse(stamp);
formattedDate = formatter.format(d);
}
if ("presence".equals(name)) {
buf.append("[").append(formattedDate).append("] ").append(message).append("\n");
} else {
buf.append("[").append(formattedDate).append("] ").append(from).append(": ").append(message).append("\n");
}
} catch (ParseException e) {
Log.error(e.getMessage(), e);
}
}
}
}
return buf.toString();
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class SparkManager method notifyDiscoInfoChanged.
/**
* Notify all users who have requested disco information from this component that settings have been changed.
* Clients should perform a new service discovery to see what has changed.
*/
public void notifyDiscoInfoChanged() {
final Message message = new Message();
message.setFrom(serviceName + "." + componentManager.getServerName());
Element child = message.addChildElement("event", "http://jabber.org/protocol/disco#info");
buildFeatureSet(child);
sessionManager.broadcast(message);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class SparkManager method handleDiscoInfo.
/**
* Send a reply back to the client to inform the client that this server has
* a Spark Manager.
*
* @param packet the IQ packet.
*/
private void handleDiscoInfo(IQ packet) {
IQ replyPacket = IQ.createResultIQ(packet);
Element responseElement = replyPacket.setChildElement("query", "http://jabber.org/protocol/disco#info");
Element identity = responseElement.addElement("identity");
identity.addAttribute("category", "manager");
identity.addAttribute("type", "text");
identity.addAttribute("name", "Client Control Manager");
// Add features set
buildFeatureSet(responseElement);
// Send reply
sendPacket(replyPacket);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class SparkVersionManager method handleSparkIQ.
private void handleSparkIQ(IQ packet) {
IQ reply;
Element iq = packet.getChildElement();
// Define default values
String os = iq.element("os").getText();
reply = IQ.createResultIQ(packet);
// Handle Invalid Requests
if (os == null || (!os.equals("windows") && !os.equals("mac") && !os.equals("linux"))) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_acceptable));
sendPacket(reply);
return;
}
Element sparkElement = reply.setChildElement("query", "jabber:iq:spark");
String client = null;
// Handle Windows clients
if (os.equals("windows")) {
client = JiveGlobals.getProperty("spark.windows.client");
} else // Handle Mac clients.
if (os.equals("mac")) {
client = JiveGlobals.getProperty("spark.mac.client");
} else // Handle Linux Client.
if (os.equals("linux")) {
client = JiveGlobals.getProperty("spark.linux.client");
}
if (client != null) {
int index = client.indexOf("_");
// Add version number
String versionNumber = client.substring(index + 1);
int indexOfPeriod = versionNumber.indexOf(".");
versionNumber = versionNumber.substring(0, indexOfPeriod);
versionNumber = versionNumber.replaceAll("_", ".");
sparkElement.addElement("version").setText(versionNumber);
// Add updated time.
File clientFile = new File(JiveGlobals.getHomeDirectory(), "enterprise/spark/" + client);
if (!clientFile.exists()) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
sendPacket(reply);
return;
}
long updatedTime = clientFile.lastModified();
sparkElement.addElement("updatedTime").setText(Long.toString(updatedTime));
// Add download url
String downloadURL = JiveGlobals.getProperty("spark.client.downloadURL");
String server = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
downloadURL = downloadURL.replace("127.0.0.1", server);
sparkElement.addElement("downloadURL").setText(downloadURL + "?client=" + client);
String displayMessage = JiveGlobals.getProperty("spark.client.displayMessage");
if (displayMessage != null && displayMessage.trim().length() > 0) {
sparkElement.addElement("displayMessage").setText(displayMessage);
}
} else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
sendPacket(reply);
return;
}
sendPacket(reply);
}
Aggregations