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