001: /*
002: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: * [See end of file]
005: */
006:
007: package jena;
008:
009: import java.io.FileInputStream;
010: import java.io.FileNotFoundException;
011: import java.io.InputStream;
012: import java.io.Reader;
013:
014: import com.hp.hpl.jena.n3.turtle.TurtleEventDump;
015: import com.hp.hpl.jena.n3.turtle.TurtleParseException;
016: import com.hp.hpl.jena.n3.turtle.parser.ParseException;
017: import com.hp.hpl.jena.n3.turtle.parser.TokenMgrError;
018: import com.hp.hpl.jena.n3.turtle.parser.TurtleParser;
019: import com.hp.hpl.jena.shared.JenaException;
020: import com.hp.hpl.jena.util.FileUtils;
021:
022: public class turtle {
023: /** Run the Turtle parser in debugging mode */
024: public static void main(String[] args) {
025:
026: for (int i = 0; i < args.length; i++) {
027: String fn = args[i];
028: parse(fn, "http://base/");
029: }
030: }
031:
032: public static void parse(String baseURI, String filename) {
033: InputStream in = null;
034: try {
035: in = new FileInputStream(filename);
036: } catch (FileNotFoundException ex) {
037: System.err.println("File not found: " + filename);
038: return;
039: }
040: parse(baseURI, in);
041: }
042:
043: public static void parse(String baseURI, InputStream in) {
044: Reader reader = FileUtils.asUTF8(in);
045: parseDebug(baseURI, reader);
046: }
047:
048: public static void parseDebug(String baseURI, Reader reader) {
049: // Nasty things happen if the reader is not UTF-8.
050: try {
051: TurtleParser parser = new TurtleParser(reader);
052: parser.setEventHandler(new TurtleEventDump());
053: parser.setBaseURI(baseURI);
054: parser.parse();
055: } catch (ParseException ex) {
056: throw new TurtleParseException(ex.getMessage());
057: } catch (TokenMgrError tErr) {
058: throw new TurtleParseException(tErr.getMessage());
059: }
060:
061: catch (TurtleParseException ex) {
062: throw ex;
063: }
064:
065: catch (JenaException ex) {
066: throw new TurtleParseException(ex.getMessage(), ex);
067: } catch (Error err) {
068: throw new TurtleParseException(err.getMessage(), err);
069: } catch (Throwable th) {
070: throw new TurtleParseException(th.getMessage(), th);
071: }
072: }
073: }
074:
075: /*
076: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
077: * All rights reserved.
078: *
079: * Redistribution and use in source and binary forms, with or without
080: * modification, are permitted provided that the following conditions
081: * are met:
082: * 1. Redistributions of source code must retain the above copyright
083: * notice, this list of conditions and the following disclaimer.
084: * 2. Redistributions in binary form must reproduce the above copyright
085: * notice, this list of conditions and the following disclaimer in the
086: * documentation and/or other materials provided with the distribution.
087: * 3. The name of the author may not be used to endorse or promote products
088: * derived from this software without specific prior written permission.
089: *
090: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
091: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
092: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
093: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
094: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
095: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
096: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
097: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
098: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
099: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100: */
|