use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class PrivacyListProvider method loadDefaultPrivacyList.
/**
* Loads the default privacy list of a given user from the database. Returns <tt>null</tt>
* if no list was found.
*
* @param username the username of the user to get his default privacy list.
* @return the default privacy list or <tt>null</tt> if no list was found.
*/
public PrivacyList loadDefaultPrivacyList(String username) {
// If there are no privacy lists stored, this method is a no-op.
if (!databaseContainsPrivacyLists.get()) {
return null;
}
String listName = null;
String listValue = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_DEFAULT_PRIVACY_LIST);
pstmt.setString(1, username);
rs = pstmt.executeQuery();
if (rs.next()) {
listName = rs.getString(1);
listValue = rs.getString(2);
} else {
return null;
}
} catch (Exception e) {
Log.error("Error loading default privacy list of username: " + username, e);
return null;
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
PrivacyList privacyList = null;
SAXReader xmlReader = null;
try {
// Get a sax reader from the pool
xmlReader = xmlReaders.take();
Element listElement = xmlReader.read(new StringReader(listValue)).getRootElement();
privacyList = new PrivacyList(username, listName, true, listElement);
} catch (Exception e) {
Log.error(e.getMessage(), e);
} finally {
// Return the sax reader to the pool
if (xmlReader != null) {
xmlReaders.add(xmlReader);
}
}
return privacyList;
}
use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class PublishedItem method getPayload.
/**
* Returns the payload included when publishing the item. A published item may or may not
* have a payload. Transient nodes that are configured to not broadcast payloads may allow
* published items to have no payload.
*
* @return the payload included when publishing the item or <tt>null</tt> if none was found.
*/
public Element getPayload() {
if (payload == null && payloadXML != null) {
synchronized (this) {
if (payload == null) {
// payload initialized as XML string from DB
SAXReader xmlReader = null;
try {
xmlReader = xmlReaders.take();
payload = xmlReader.read(new StringReader(payloadXML)).getRootElement();
} catch (Exception ex) {
log.error("Failed to parse payload XML", ex);
} finally {
if (xmlReader != null) {
xmlReaders.add(xmlReader);
}
}
}
}
}
return payload;
}
use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class AdminConsole method addModel.
/**
* Adds XML stream to the tabs/sidebar model.
*
* @param name the name.
* @param in the XML input stream.
* @throws Exception if an error occurs when parsing the XML or adding it to the model.
*/
public static void addModel(String name, InputStream in) throws Exception {
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(in);
addModel(name, (Element) doc.selectSingleNode("/adminconsole"));
}
use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class AdminConsole method load.
private static void load() {
// Load the core model as the admin-sidebar.xml file from the classpath.
InputStream in = ClassUtils.getResourceAsStream("/admin-sidebar.xml");
if (in == null) {
Log.error("Failed to load admin-sidebar.xml file from Openfire classes - admin " + "console will not work correctly.");
return;
}
try {
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(in);
coreModel = (Element) doc.selectSingleNode("/adminconsole");
} catch (Exception e) {
Log.error("Failure when parsing main admin-sidebar.xml file", e);
}
try {
in.close();
} catch (Exception ignored) {
// Ignore.
}
// Load other admin-sidebar.xml files from the classpath
ClassLoader[] classLoaders = getClassLoaders();
for (ClassLoader classLoader : classLoaders) {
URL url = null;
try {
if (classLoader != null) {
Enumeration e = classLoader.getResources("/META-INF/admin-sidebar.xml");
while (e.hasMoreElements()) {
url = (URL) e.nextElement();
try {
in = url.openStream();
addModel("admin", in);
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception ignored) {
// Ignore.
}
}
}
}
} catch (Exception e) {
String msg = "Failed to load admin-sidebar.xml";
if (url != null) {
msg += " from resource: " + url.toString();
}
Log.warn(msg, e);
}
}
rebuildModel();
}
use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class OfflineMessageStore method start.
@Override
public void start() throws IllegalStateException {
super.start();
// Initialize the pool of sax readers
for (int i = 0; i < POOL_SIZE; i++) {
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlReaders.add(xmlReader);
}
// Add this module as a user event listener so we can delete
// all offline messages when a user is deleted
UserEventDispatcher.addListener(this);
}
Aggregations