use of org.dom4j.Document in project Openfire by igniterealtime.
the class Xep227Exporter method exportUsers.
/* (non-Javadoc)
* @see org.jivesoftware.openfire.plugin.Exporter#exportUsers(org.jivesoftware.openfire.user.UserManager)
*/
@Override
public Document exportUsers() {
Log.debug("exportUsers");
Document document = DocumentHelper.createDocument();
Element root = document.addElement(SERVER_DATA_ELEMENT_NAME, URN_XMPP_PIE_0_NS);
Element host = root.addElement(HOST_ELEMENT_NAME);
host.addAttribute(JID_NAME, serverName);
Collection<User> users = userManager.getUsers();
for (User user : users) {
String userName = user.getUsername();
Element userElement = host.addElement(USER_ELEMENT_NAME);
exportUser(userElement, user);
exportOfflineMessages(serverName, userElement, userName);
exportRoster(userElement, user);
exportVCard(userElement, userName);
exportPrivateStorage(userName, userElement);
}
return document;
}
use of org.dom4j.Document in project Openfire by igniterealtime.
the class Xep227ExporterTest method testExportUsers.
/**
* Test method for {@link org.jivesoftware.openfire.plugin.OpenfireExporter#exportUsers(org.jivesoftware.openfire.user.UserManager)}.
* @throws UserAlreadyExistsException
* @throws IOException
*/
@Test
public void testExportUsers() throws UserAlreadyExistsException, IOException {
InExporter testobject = new Xep227Exporter("serverName", offlineMessagesStore, vCardManager, privateStorage, userManager, null);
for (int i = 0; i < 10; i++) {
userManager.createUser("username" + i, "pw", "name" + i, "email" + i);
}
Document result = testobject.exportUsers();
assertNotNull(result);
assertEquals(1, result.nodeCount());
assertNotNull(result.node(0));
Element elem = ((Element) result.node(0));
assertEquals(1, elem.nodeCount());
assertNotNull(elem.node(0));
elem = ((Element) elem.node(0));
assertEquals(10, elem.nodeCount());
assertNotNull(elem.node(0));
elem = ((Element) elem.node(0));
assertEquals(3, elem.nodeCount());
assertEquals(2, elem.attributeCount());
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
writer.write(result);
logger.fine(out.toString());
assertTrue("Invalid input", testobject.validate(new ByteArrayInputStream(out.toByteArray())));
}
use of org.dom4j.Document 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.Document in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testWaitSetRequest.
@Test
public void testWaitSetRequest() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String authToken = mbox.getAuthToken().getValue();
CreateWaitSetRequest req = new CreateWaitSetRequest("all");
WaitSetAddSpec add = new WaitSetAddSpec();
add.setId(mbox.getAccountInfo(false).getId());
req.addAccount(add);
DocumentResult dr = new DocumentResult();
marshaller.marshal(req, dr);
Document doc = dr.getDocument();
ZimbraLog.test.info(doc.getRootElement().asXML());
CreateWaitSetResponse createResp = (CreateWaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "CreateWaitSetRequest");
String waitSetId = createResp.getWaitSetId();
Assert.assertNotNull(waitSetId);
WaitSetRequest waitSet = new com.zimbra.soap.mail.message.WaitSetRequest(waitSetId, "0");
dr = new DocumentResult();
marshaller.marshal(waitSet, dr);
doc = dr.getDocument();
WaitSetResponse wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
Assert.assertEquals("0", wsResp.getSeqNo());
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessageLmtp(subject, USER_NAME, "user999@example.com");
try {
Thread.sleep(500);
} catch (Exception e) {
}
wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
Assert.assertFalse(wsResp.getSeqNo().equals("0"));
}
use of org.dom4j.Document in project reflections by ronmamo.
the class XmlSerializer method createDocument.
private Document createDocument(final Reflections reflections) {
Store map = reflections.getStore();
Document document = DocumentFactory.getInstance().createDocument();
Element root = document.addElement("Reflections");
for (String indexName : map.keySet()) {
Element indexElement = root.addElement(indexName);
for (String key : map.get(indexName).keySet()) {
Element entryElement = indexElement.addElement("entry");
entryElement.addElement("key").setText(key);
Element valuesElement = entryElement.addElement("values");
for (String value : map.get(indexName).get(key)) {
valuesElement.addElement("value").setText(value);
}
}
}
return document;
}
Aggregations