Search in sources :

Example 51 with Element

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;
}
Also used : Element(org.dom4j.Element)

Example 52 with Element

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();
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) ParseException(java.text.ParseException) Date(java.util.Date) DocumentException(org.dom4j.DocumentException) ResultSet(java.sql.ResultSet) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with Element

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);
}
Also used : Message(org.xmpp.packet.Message) Element(org.dom4j.Element)

Example 54 with Element

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);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 55 with Element

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);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) File(java.io.File)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64