KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > xmldb > other > RetrieveDocument


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
package test.xmldb.other;
8
9 import org.w3c.dom.Document JavaDoc;
10 import org.xmldb.api.DatabaseManager;
11 import org.xmldb.api.base.Collection;
12 import org.xmldb.api.base.Database;
13 import org.xmldb.api.modules.XMLResource;
14 import org.apache.log4j.Logger;
15 import test.xmldb.Constants;
16 /**
17  * @author Per Nyfelt
18  */

19 public class RetrieveDocument implements Constants{
20
21     Logger logger = Logger.getLogger(RetrieveDocument.class);
22
23     /** Creates new RetrieveDocument */
24     public RetrieveDocument() {
25         try {
26             Class JavaDoc c = Class.forName(driver);
27
28             Database database = (Database) c.newInstance();
29             System.out.println("Registring Database " + database);
30             DatabaseManager.registerDatabase(database);
31             Collection col = database.getCollection(collectionURI);
32             System.out.println("Got Collection " + col);
33             XMLResource resource = (XMLResource) col.getResource(resourceName);
34             System.out.println("Got resource " + resource + " for " + resourceName);
35             
36             Document JavaDoc doc = (Document JavaDoc)resource.getContentAsDOM();
37             System.out.println("Retrieved the Document with root: " + doc.getDocumentElement().getTagName());
38             String JavaDoc content = (String JavaDoc)resource.getContent();
39             System.out.println("here's the content:\n" + content);
40             col.close();
41         }
42         catch (Exception JavaDoc e) {
43             e.printStackTrace();
44         }
45     }
46     
47     public static void main( String JavaDoc args[] ) {
48         new RetrieveDocument();
49     }
50 }
51
Popular Tags