Search in sources :

Example 6 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class PluginCacheConfigurator method configure.

public void configure(String pluginName) {
    try {
        SAXReader saxReader = new SAXReader();
        saxReader.setEncoding("UTF-8");
        Document cacheXml = saxReader.read(configDataStream);
        List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping");
        for (Node mapping : mappings) {
            registerCache(pluginName, mapping);
        }
    } catch (DocumentException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Node(org.dom4j.Node) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document)

Example 7 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class DefaultVCardProvider method loadVCard.

@Override
public Element loadVCard(String username) {
    synchronized (username.intern()) {
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Element vCardElement = null;
        SAXReader xmlReader = null;
        try {
            // Get a sax reader from the pool
            xmlReader = xmlReaders.take();
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(LOAD_PROPERTIES);
            pstmt.setString(1, username);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                vCardElement = xmlReader.read(new StringReader(rs.getString(1))).getRootElement();
            }
        } catch (Exception e) {
            Log.error("Error loading vCard of username: " + username, e);
        } finally {
            // Return the sax reader to the pool
            if (xmlReader != null) {
                xmlReaders.add(xmlReader);
            }
            DbConnectionManager.closeConnection(rs, pstmt, con);
        }
        return vCardElement;
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) StringReader(java.io.StringReader) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) AlreadyExistsException(org.jivesoftware.util.AlreadyExistsException)

Example 8 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class UpdateManager method processAvailablePluginsResponse.

private void processAvailablePluginsResponse(String response, boolean notificationsEnabled) throws DocumentException {
    // Reset last known list of available plugins
    availablePlugins = new HashMap<>();
    // Parse response and keep info as AvailablePlugin objects
    SAXReader xmlReader = new SAXReader();
    xmlReader.setEncoding("UTF-8");
    Element xmlResponse = xmlReader.read(new StringReader(response)).getRootElement();
    Iterator plugins = xmlResponse.elementIterator("plugin");
    while (plugins.hasNext()) {
        Element plugin = (Element) plugins.next();
        String pluginName = plugin.attributeValue("name");
        String latestVersion = plugin.attributeValue("latest");
        String icon = plugin.attributeValue("icon");
        String readme = plugin.attributeValue("readme");
        String changelog = plugin.attributeValue("changelog");
        String url = plugin.attributeValue("url");
        String licenseType = plugin.attributeValue("licenseType");
        String description = plugin.attributeValue("description");
        String author = plugin.attributeValue("author");
        String minServerVersion = plugin.attributeValue("minServerVersion");
        String fileSize = plugin.attributeValue("fileSize");
        AvailablePlugin available = new AvailablePlugin(pluginName, description, latestVersion, author, icon, changelog, readme, licenseType, minServerVersion, url, fileSize);
        // Add plugin to the list of available plugins at js.org
        availablePlugins.put(pluginName, available);
    }
    // Figure out local plugins that need to be updated
    buildPluginsUpdateList();
    // Check if we need to send notifications to admins
    if (notificationsEnabled && isNotificationEnabled() && !pluginUpdates.isEmpty()) {
        Collection<JID> admins = XMPPServer.getInstance().getAdmins();
        for (Update update : pluginUpdates) {
            Message notification = new Message();
            notification.setFrom(serverName);
            notification.setBody(getNotificationMessage() + " " + update.getComponentName() + " " + update.getLatestVersion());
            for (JID jid : admins) {
                notification.setTo(jid);
                router.route(notification);
            }
        }
    }
    // Save information of available plugins
    saveAvailablePluginsInfo();
}
Also used : JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Iterator(java.util.Iterator)

Example 9 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class UpdateManager method loadLatestServerInfo.

private void loadLatestServerInfo() {
    Document xmlResponse;
    File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf", "server-update.xml");
    if (!file.exists()) {
        return;
    }
    // Check read privs.
    if (!file.canRead()) {
        Log.warn("Cannot retrieve server updates. File must be readable: " + file.getName());
        return;
    }
    try (FileReader reader = new FileReader(file)) {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        xmlResponse = xmlReader.read(reader);
    } catch (Exception e) {
        Log.error("Error reading server-update.xml", e);
        return;
    }
    // Parse info and recreate update information (if still required)
    Element openfire = xmlResponse.getRootElement().element("openfire");
    if (openfire != null) {
        Version latestVersion = new Version(openfire.attributeValue("latest"));
        String changelog = openfire.attributeValue("changelog");
        String url = openfire.attributeValue("url");
        // Check if current server version is correct
        Version currentServerVersion = XMPPServer.getInstance().getServerInfo().getVersion();
        if (latestVersion.isNewerThan(currentServerVersion)) {
            serverUpdate = new Update("Openfire", latestVersion.getVersionString(), changelog, url);
        }
    }
}
Also used : Version(org.jivesoftware.util.Version) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) FileReader(java.io.FileReader) Document(org.dom4j.Document) File(java.io.File) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException)

Example 10 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class XMLProperties method buildDoc.

/**
     * Builds the document XML model up based the given reader of XML data.
     * @param in the input stream used to build the xml document
     * @throws java.io.IOException thrown when an error occurs reading the input stream.
     */
private void buildDoc(Reader in) throws IOException {
    try {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        document = xmlReader.read(in);
    } catch (Exception e) {
        Log.error("Error reading XML properties", e);
        throw new IOException(e.getMessage());
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Aggregations

SAXReader (org.dom4j.io.SAXReader)172 Document (org.dom4j.Document)143 Element (org.dom4j.Element)128 StringReader (java.io.StringReader)98 Test (org.junit.Test)78 ArrayList (java.util.ArrayList)35 List (java.util.List)35 File (java.io.File)28 DocumentException (org.dom4j.DocumentException)21 IOException (java.io.IOException)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 LinkedList (java.util.LinkedList)16 Node (org.dom4j.Node)14 HashMap (java.util.HashMap)12 Map (java.util.Map)10 Attribute (org.dom4j.Attribute)10 InputStream (java.io.InputStream)9 XMLWriter (org.dom4j.io.XMLWriter)9 OutputFormat (org.dom4j.io.OutputFormat)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6