KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > test > DOM2RDFTest


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.rdf.arp.test;
7
8 import java.io.IOException JavaDoc;
9 import java.io.InputStream JavaDoc;
10
11 import javax.xml.parsers.*;
12 import javax.xml.transform.Source JavaDoc;
13 import javax.xml.transform.dom.DOMSource JavaDoc;
14
15
16 import org.w3c.dom.Document JavaDoc;
17 import org.xml.sax.SAXException JavaDoc;
18 import org.xml.sax.SAXParseException JavaDoc;
19
20 import com.hp.hpl.jena.rdf.arp.MalformedURIException;
21 import com.hp.hpl.jena.rdf.arp.DOM2Model;
22 import com.hp.hpl.jena.rdf.model.Model;
23 import com.hp.hpl.jena.shared.*;
24
25 /**
26  * @author Jeremy J. Carroll
27  *
28  */

29 class DOM2RDFTest extends SAX2RDFTest {
30
31     /**
32      * @param dir
33      * @param base0
34      * @param file
35      */

36     public DOM2RDFTest(String JavaDoc dir, String JavaDoc base0, String JavaDoc file) {
37         super(dir, base0, file);
38     }
39     
40     static private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
41     // DOM must have namespace information inside it!
42
static { factory.setNamespaceAware(true);}
43     static private DocumentBuilder domParser;
44     
45     static {
46         try {
47         domParser = factory.newDocumentBuilder();
48         }
49         catch (ParserConfigurationException rte){
50             throw new JenaException(rte);
51         }
52     }
53     
54
55     void loadXMLModel(Model m2, InputStream JavaDoc in, RDFEHArray eh2) throws MalformedURIException, SAXException JavaDoc, IOException JavaDoc {
56         
57         Document JavaDoc document = domParser
58                 .parse(in,base);
59             
60         // Make DOM into transformer input
61
Source JavaDoc input = new DOMSource JavaDoc(document);
62         DOM2Model d2m = new DOM2Model(base,m2);
63
64         d2m.setErrorHandler(eh2);
65         
66         try {
67             try {
68                 d2m.load(document);
69             } finally {
70                 d2m.close();
71             }
72         } catch (SAXParseException JavaDoc e) {
73             // already reported, leave it be.
74
}
75         
76
77     }
78
79 }
80
81
82 /*
83  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
84  * All rights reserved.
85  *
86  * Redistribution and use in source and binary forms, with or without
87  * modification, are permitted provided that the following conditions
88  * are met:
89  * 1. Redistributions of source code must retain the above copyright
90  * notice, this list of conditions and the following disclaimer.
91  * 2. Redistributions in binary form must reproduce the above copyright
92  * notice, this list of conditions and the following disclaimer in the
93  * documentation and/or other materials provided with the distribution.
94  * 3. The name of the author may not be used to endorse or promote products
95  * derived from this software without specific prior written permission.
96  *
97  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
98  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
99  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
100  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
101  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
102  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
103  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
106  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
107  */

108  
109
Popular Tags