01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.rio.n3;
07:
08: import java.io.OutputStream;
09: import java.io.Writer;
10:
11: import org.openrdf.model.Statement;
12: import org.openrdf.rio.RDFFormat;
13: import org.openrdf.rio.RDFHandlerException;
14: import org.openrdf.rio.RDFWriter;
15: import org.openrdf.rio.turtle.TurtleWriter;
16:
17: /**
18: * An implementation of the RDFWriter interface that writes RDF documents in N3
19: * format. Note: the current implementation simply wraps a {@link TurtleWriter}
20: * and writes documents in Turtle format, which is a subset of N3.
21: */
22: public class N3Writer implements RDFWriter {
23:
24: /*-----------*
25: * Variables *
26: *-----------*/
27:
28: private TurtleWriter ttlWriter;
29:
30: /*--------------*
31: * Constructors *
32: *--------------*/
33:
34: /**
35: * Creates a new N3Writer that will write to the supplied OutputStream.
36: *
37: * @param out
38: * The OutputStream to write the N3 document to.
39: */
40: public N3Writer(OutputStream out) {
41: ttlWriter = new TurtleWriter(out);
42: }
43:
44: /**
45: * Creates a new N3Writer that will write to the supplied Writer.
46: *
47: * @param writer
48: * The Writer to write the N3 document to.
49: */
50: public N3Writer(Writer writer) {
51: ttlWriter = new TurtleWriter(writer);
52: }
53:
54: /*---------*
55: * Methods *
56: *---------*/
57:
58: public RDFFormat getRDFFormat() {
59: return RDFFormat.N3;
60: }
61:
62: public void startRDF() throws RDFHandlerException {
63: ttlWriter.startRDF();
64: }
65:
66: public void endRDF() throws RDFHandlerException {
67: ttlWriter.endRDF();
68: }
69:
70: public void handleNamespace(String prefix, String name)
71: throws RDFHandlerException {
72: ttlWriter.handleNamespace(prefix, name);
73: }
74:
75: public void handleStatement(Statement st)
76: throws RDFHandlerException {
77: ttlWriter.handleStatement(st);
78: }
79:
80: public void handleComment(String comment)
81: throws RDFHandlerException {
82: ttlWriter.handleComment(comment);
83: }
84: }
|