1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.samples;
24
25 import java.io.ByteArrayInputStream;
26 import java.io.InputStream;
27
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30
31 import org.w3c.dom.Document;
32
33 import de.bea.domingo.DDatabase;
34 import de.bea.domingo.DDocument;
35 import de.bea.domingo.DDxlExporter;
36 import de.bea.domingo.DNotesFactory;
37 import de.bea.domingo.DSession;
38 import de.bea.domingo.DView;
39
40 /***
41 * A simple example accessing the local NAB.
42 *
43 * <p>The file NCSO.jar from the Lotus Domino server must be in the classpath to
44 * run this test.</p>
45 *
46 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
47 */
48 public final class DocumentToDOM {
49
50 /***
51 * Main method of sample.
52 *
53 * @param args arguments
54 * @throws Exception If any error occurs
55 */
56 public static void main(final String[] args) throws Exception {
57
58
59 DNotesFactory factory = DNotesFactory.getInstance();
60
61
62 DSession session = factory.getSession();
63
64
65 DDatabase database = session.getMailDatabase();
66
67
68 DView view = database.getView("$Inbox");
69 DDocument document = (DDocument) view.getAllDocuments().next();
70
71
72 DDxlExporter exporter = session.createDxlExporter();
73 exporter.setOutputDoctype(false);
74 String xmlString = exporter.exportDxl(document);
75
76
77 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
78 DocumentBuilder builder = dbf.newDocumentBuilder();
79 InputStream inputStream = new ByteArrayInputStream(xmlString.getBytes());
80 Document dom = builder.parse(inputStream);
81
82
83 System.out.println("Document created: " + dom.getDocumentElement().getNodeName());
84 }
85 }