01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: package test.xmldb.other;
08:
09: import test.xmldb.*;
10: import java.io.StringWriter;
11:
12: import org.ozoneDB.xml.core.XMLCollection;
13: import org.xmldb.api.modules.XMLResource;
14:
15: import org.xmldb.api.base.Collection;
16: import org.xmldb.api.base.Database;
17: import org.xmldb.api.DatabaseManager;
18:
19: import org.w3c.dom.Document;
20: import org.apache.xml.serialize.OutputFormat;
21: import org.apache.xml.serialize.XMLSerializer;
22:
23: /**
24: * @author Per Nyfelt
25: */
26: public class RetrieveDocument implements Constants {
27:
28: /** Creates new RetrieveDocument */
29: public RetrieveDocument() {
30: try {
31: Class c = Class.forName(driver);
32:
33: Database database = (Database) c.newInstance();
34: System.out.println("Registring Database " + database);
35: DatabaseManager.registerDatabase(database);
36: Collection col = database.getCollection(collectionURI);
37: System.out.println("Got Collection " + col);
38: XMLResource resource = (XMLResource) col
39: .getResource(resourceName);
40: System.out.println("Got resource " + resource + " for "
41: + resourceName);
42:
43: Document doc = (Document) resource.getContentAsDOM();
44: System.out.println("Retrieved the Document with root: "
45: + doc.getDocumentElement().getTagName());
46: String content = (String) resource.getContent();
47: System.out.println("here's the content:\n" + content);
48: col.close();
49: } catch (Exception e) {
50: e.printStackTrace();
51: }
52: }
53:
54: public static void main(String args[]) {
55: new RetrieveDocument();
56: }
57: }
|