Search in sources :

Example 16 with Document

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;
}
Also used : User(org.jivesoftware.openfire.user.User) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 17 with 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())));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DOMElement(org.dom4j.dom.DOMElement) Element(org.dom4j.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) Test(org.junit.Test)

Example 18 with Document

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;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) Document(org.dom4j.Document) File(java.io.File)

Example 19 with Document

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"));
}
Also used : WaitSetRequest(com.zimbra.soap.mail.message.WaitSetRequest) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) ZMailbox(com.zimbra.client.ZMailbox) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) WaitSetResponse(com.zimbra.soap.mail.message.WaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) DocumentResult(org.dom4j.io.DocumentResult) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) Document(org.dom4j.Document) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) HttpException(org.apache.commons.httpclient.HttpException) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) Test(org.junit.Test)

Example 20 with Document

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;
}
Also used : Element(org.dom4j.Element) Store(org.reflections.Store) Document(org.dom4j.Document)

Aggregations

Document (org.dom4j.Document)891 Element (org.dom4j.Element)492 SAXReader (org.dom4j.io.SAXReader)252 File (java.io.File)135 IOException (java.io.IOException)135 StringReader (java.io.StringReader)111 ArrayList (java.util.ArrayList)110 List (java.util.List)107 Test (org.junit.Test)101 DocumentException (org.dom4j.DocumentException)93 HashMap (java.util.HashMap)90 InputStream (java.io.InputStream)82 Node (org.dom4j.Node)80 Test (org.junit.jupiter.api.Test)80 XMLWriter (org.dom4j.io.XMLWriter)53 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)48 FileInputStream (java.io.FileInputStream)45 Map (java.util.Map)41 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)40 XMLParser (org.olat.core.util.xml.XMLParser)40