01: /*
02: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: */
06:
07: package com.hp.hpl.jena.n3.turtle;
08:
09: import java.io.*;
10:
11: import com.hp.hpl.jena.graph.Graph;
12: import com.hp.hpl.jena.n3.turtle.parser.ParseException;
13: import com.hp.hpl.jena.n3.turtle.parser.TokenMgrError;
14: import com.hp.hpl.jena.n3.turtle.parser.TurtleParser;
15: import com.hp.hpl.jena.shared.JenaException;
16: import com.hp.hpl.jena.util.FileUtils;
17:
18: public class ParserTurtle {
19: public ParserTurtle() {
20: }
21:
22: public void parse(Graph graph, String baseURI, InputStream in) {
23: Reader reader = FileUtils.asUTF8(in);
24: parse(graph, baseURI, reader);
25: }
26:
27: public void parse(Graph graph, String baseURI, Reader reader) {
28: // Nasty things happen if the reader is not UTF-8.
29: try {
30: TurtleParser parser = new TurtleParser(reader);
31: parser.setEventHandler(new TurtleEventInserter(graph));
32: parser.setBaseURI(baseURI);
33: parser.parse();
34: }
35:
36: catch (ParseException ex) {
37: throw new TurtleParseException(ex.getMessage());
38: }
39:
40: catch (TokenMgrError tErr) {
41: throw new TurtleParseException(tErr.getMessage());
42: }
43:
44: catch (TurtleParseException ex) {
45: throw ex;
46: }
47:
48: catch (JenaException ex) {
49: throw new TurtleParseException(ex.getMessage(), ex);
50: } catch (Error err) {
51: throw new TurtleParseException(err.getMessage(), err);
52: } catch (Throwable th) {
53: throw new TurtleParseException(th.getMessage(), th);
54: }
55: }
56:
57: }
58:
59: /*
60: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: * All rights reserved.
62: *
63: * Redistribution and use in source and binary forms, with or without
64: * modification, are permitted provided that the following conditions
65: * are met:
66: * 1. Redistributions of source code must retain the above copyright
67: * notice, this list of conditions and the following disclaimer.
68: * 2. Redistributions in binary form must reproduce the above copyright
69: * notice, this list of conditions and the following disclaimer in the
70: * documentation and/or other materials provided with the distribution.
71: * 3. The name of the author may not be used to endorse or promote products
72: * derived from this software without specific prior written permission.
73: *
74: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84: */
|