001: /*
002: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp.test;
007:
008: import java.io.IOException;
009: import java.io.InputStream;
010:
011: import javax.xml.parsers.DocumentBuilder;
012: import javax.xml.parsers.DocumentBuilderFactory;
013: import javax.xml.parsers.ParserConfigurationException;
014:
015: import org.w3c.dom.Document;
016: import org.xml.sax.SAXException;
017:
018: import com.hp.hpl.jena.rdf.arp.DOM2Model;
019: import com.hp.hpl.jena.rdf.model.Model;
020: import com.hp.hpl.jena.shared.JenaException;
021:
022: /**
023: * @author Jeremy J. Carroll
024: *
025: */
026: class DOM2RDFTest extends SAX2RDFTest {
027:
028: /**
029: * @param dir
030: * @param base0
031: * @param file
032: */
033: public DOM2RDFTest(String dir, String base0, String file) {
034: super (dir, base0, file);
035: }
036:
037: static private DocumentBuilderFactory factory = DocumentBuilderFactory
038: .newInstance();
039: // DOM must have namespace information inside it!
040: static {
041: factory.setNamespaceAware(true);
042: }
043: static private DocumentBuilder domParser;
044:
045: static {
046: try {
047: domParser = factory.newDocumentBuilder();
048: } catch (ParserConfigurationException rte) {
049: throw new JenaException(rte);
050: }
051: }
052:
053: void loadXMLModel(Model m2, InputStream in, RDFEHArray eh2)
054: throws SAXException, IOException {
055:
056: Document document = domParser.parse(in, base);
057:
058: // Make DOM into transformer input
059: // Source input = new DOMSource(document);
060: DOM2Model d2m = DOM2Model.createD2M(base, m2);
061:
062: d2m.setErrorHandler(eh2);
063:
064: // try {
065: try {
066: d2m.load(document);
067: } finally {
068: d2m.close();
069: }
070: // } catch (SAXParseException e) {
071: // // already reported, leave it be.
072: // }
073:
074: }
075:
076: }
077:
078: /*
079: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
080: * All rights reserved.
081: *
082: * Redistribution and use in source and binary forms, with or without
083: * modification, are permitted provided that the following conditions
084: * are met:
085: * 1. Redistributions of source code must retain the above copyright
086: * notice, this list of conditions and the following disclaimer.
087: * 2. Redistributions in binary form must reproduce the above copyright
088: * notice, this list of conditions and the following disclaimer in the
089: * documentation and/or other materials provided with the distribution.
090: * 3. The name of the author may not be used to endorse or promote products
091: * derived from this software without specific prior written permission.
092: *
093: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
094: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
095: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
096: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
097: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
098: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
099: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103: */
|