use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class MUCRoomHistory method addOldMessage.
/**
* Creates a new message and adds it to the history. The new message will be created based on
* the provided information. This information will likely come from the database when loading
* the room history from the database.
*
* @param senderJID the sender's JID of the message to add to the history.
* @param nickname the sender's nickname of the message to add to the history.
* @param sentDate the date when the message was sent to the room.
* @param subject the subject included in the message.
* @param body the body of the message.
*/
public void addOldMessage(String senderJID, String nickname, Date sentDate, String subject, String body, String stanza) {
Message message = new Message();
message.setType(Message.Type.groupchat);
if (stanza != null) {
// payload initialized as XML string from DB
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
try {
Element element = xmlReader.read(new StringReader(stanza)).getRootElement();
for (Element child : (List<Element>) element.elements()) {
Namespace ns = child.getNamespace();
if (ns == null || ns.getURI().equals("jabber:client") || ns.getURI().equals("jabber:server")) {
continue;
}
Element added = message.addChildElement(child.getName(), child.getNamespaceURI());
if (!child.getText().isEmpty()) {
added.setText(child.getText());
}
for (Attribute attr : (List<Attribute>) child.attributes()) {
added.addAttribute(attr.getQName(), attr.getValue());
}
for (Element el : (List<Element>) child.elements()) {
added.add(el.createCopy());
}
}
if (element.attribute("id") != null) {
message.setID(element.attributeValue("id"));
}
} catch (Exception ex) {
Log.error("Failed to parse payload XML", ex);
}
}
message.setSubject(subject);
message.setBody(body);
// Set the sender of the message
if (nickname != null && nickname.trim().length() > 0) {
JID roomJID = room.getRole().getRoleAddress();
// Recreate the sender address based on the nickname and room's JID
message.setFrom(new JID(roomJID.getNode(), roomJID.getDomain(), nickname, true));
} else {
// Set the room as the sender of the message
message.setFrom(room.getRole().getRoleAddress());
}
// Add the delay information to the message
Element delayInformation = message.addChildElement("delay", "urn:xmpp:delay");
delayInformation.addAttribute("stamp", XMPPDateTimeFormat.format(sentDate));
if (room.canAnyoneDiscoverJID()) {
// Set the Full JID as the "from" attribute
delayInformation.addAttribute("from", senderJID);
} else {
// Set the Room JID as the "from" attribute
delayInformation.addAttribute("from", room.getRole().getRoleAddress().toString());
}
historyStrategy.addMessage(message);
}
use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class UpdateManager method loadAvailablePluginsInfo.
private void loadAvailablePluginsInfo() {
Document xmlResponse;
File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf", "available-plugins.xml");
if (!file.exists()) {
return;
}
// Check read privs.
if (!file.canRead()) {
Log.warn("Cannot retrieve available plugins. 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 available-plugins.xml", e);
return;
}
// Parse info and recreate available plugins
Iterator it = xmlResponse.getRootElement().elementIterator("plugin");
while (it.hasNext()) {
Element plugin = (Element) it.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);
}
}
use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.
the class KrakenPlugin method getOptionsConfig.
/**
* Returns the web options config for the given transport, if it exists.
*
* @param type type of the transport we want the options config for.
* @return XML document with the options config.
*/
public Document getOptionsConfig(TransportType type) {
// Load any custom-defined servlets.
File optConf = new File(this.pluginDirectory, "web" + File.separator + "WEB-INF" + File.separator + "options" + File.separator + type.toString() + ".xml");
Document optConfXML;
try {
FileReader reader = new FileReader(optConf);
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
optConfXML = xmlReader.read(reader);
} catch (FileNotFoundException e) {
// Non-existent: Return empty config
optConfXML = DocumentHelper.createDocument();
optConfXML.addElement("optionsconfig");
} catch (DocumentException e) {
// Bad config: Return empty config
optConfXML = DocumentHelper.createDocument();
optConfXML.addElement("optionsconfig");
}
return optConfXML;
}
use of org.dom4j.io.SAXReader in project hudson-2.x by hudson.
the class SuiteResult method parse.
/**
* Parses the JUnit XML file into {@link SuiteResult}s.
* This method returns a collection, as a single XML may have multiple <testsuite>
* elements wrapped into the top-level <testsuites>.
*/
static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException {
List<SuiteResult> r = new ArrayList<SuiteResult>();
// parse into DOM
SAXReader saxReader = new SAXReader();
// install EntityResolver for resolving DTDs, which are in files created by TestNG.
XMLEntityResolver resolver = new XMLEntityResolver();
saxReader.setEntityResolver(resolver);
Document result = saxReader.read(xmlReport);
Element root = result.getRootElement();
getTestSuites(root, r, xmlReport, keepLongStdio);
return r;
}
use of org.dom4j.io.SAXReader in project randomizedtesting by randomizedtesting.
the class JUnit4Mojo method appendRawXml.
/**
* Append raw XML configuration.
*/
private void appendRawXml(PlexusConfiguration config, Element elem) {
try {
if (config == null) {
return;
}
StringWriter writer = new StringWriter();
AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
xmlWriter.write(config, writer);
Element root = new SAXReader().read(new StringReader(writer.toString())).getRootElement();
root.detach();
elem.add(root);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations