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.FileInputStream;
009: import java.io.IOException;
010: import java.io.InputStream;
011:
012: import javax.xml.parsers.DocumentBuilder;
013: import javax.xml.parsers.DocumentBuilderFactory;
014: import javax.xml.parsers.ParserConfigurationException;
015:
016: import junit.framework.TestCase;
017:
018: import org.w3c.dom.Document;
019: import org.xml.sax.SAXException;
020:
021: import com.hp.hpl.jena.rdf.arp.ALiteral;
022: import com.hp.hpl.jena.rdf.arp.AResource;
023: import com.hp.hpl.jena.rdf.arp.DOM2Model;
024: import com.hp.hpl.jena.rdf.arp.StatementHandler;
025:
026: /**
027: * @author Jeremy J. Carroll
028: *
029: */
030: public class MoreDOM2RDFTest extends TestCase implements
031: StatementHandler {
032:
033: int count = 0;
034:
035: public MoreDOM2RDFTest(String name) {
036: super (name);
037: }
038:
039: static private DocumentBuilderFactory factory = DocumentBuilderFactory
040: .newInstance();
041: // DOM must have namespace information inside it!
042: static {
043: factory.setNamespaceAware(true);
044: }
045: static private DocumentBuilder domParser;
046:
047: static {
048: try {
049: domParser = factory.newDocumentBuilder();
050: } catch (ParserConfigurationException rte) {
051: throw new RuntimeException(rte);
052: }
053: }
054:
055: public void testDOMwithARP() throws SAXException, IOException {
056:
057: InputStream in = new FileInputStream(
058: "testing/wg/Class/conclusions001.rdf");
059: Document document = domParser.parse(in,
060: "http://www.example.org/");
061:
062: DOM2Model d2m = DOM2Model.createD2M("http://www.example.org/",
063: null);
064:
065: d2m.getHandlers().setStatementHandler(this );
066:
067: try {
068: d2m.load(document);
069: } finally {
070: d2m.close();
071: }
072:
073: assertEquals("Incorrect number of triples", 3, count);
074:
075: }
076:
077: public void statement(AResource subj, AResource pred, AResource obj) {
078: count++;
079:
080: }
081:
082: public void statement(AResource subj, AResource pred, ALiteral lit) {
083: count++;
084:
085: }
086:
087: }
088:
089: /*
090: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
091: * All rights reserved.
092: *
093: * Redistribution and use in source and binary forms, with or without
094: * modification, are permitted provided that the following conditions
095: * are met:
096: * 1. Redistributions of source code must retain the above copyright
097: * notice, this list of conditions and the following disclaimer.
098: * 2. Redistributions in binary form must reproduce the above copyright
099: * notice, this list of conditions and the following disclaimer in the
100: * documentation and/or other materials provided with the distribution.
101: * 3. The name of the author may not be used to endorse or promote products
102: * derived from this software without specific prior written permission.
103: *
104: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
105: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
106: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
107: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
108: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
109: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
110: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
111: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
112: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
113: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114: */
|