Strabon

changeset 479:ccc5a44197a9

added RDFHandlerFactory that creates an RDFHandler (RDFWriter) given a format (String)
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Jul 20 14:50:10 2012 +0300 (2012-07-20)
parents 27a92cb6315c
children 7bad4b0576f9
files runtime/src/main/java/eu/earthobservatory/utils/RDFHandlerFactory.java
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/RDFHandlerFactory.java	Fri Jul 20 14:50:10 2012 +0300
     1.3 @@ -0,0 +1,57 @@
     1.4 +/**
     1.5 + * 
     1.6 + */
     1.7 +package eu.earthobservatory.utils;
     1.8 +
     1.9 +import java.io.OutputStream;
    1.10 +
    1.11 +import org.openrdf.rio.RDFFormat;
    1.12 +import org.openrdf.rio.RDFHandler;
    1.13 +import org.openrdf.rio.binary.BinaryRDFWriter;
    1.14 +import org.openrdf.rio.n3.N3Writer;
    1.15 +import org.openrdf.rio.ntriples.NTriplesWriter;
    1.16 +import org.openrdf.rio.rdfxml.util.RDFXMLPrettyWriter;
    1.17 +import org.openrdf.rio.trig.TriGWriter;
    1.18 +import org.openrdf.rio.trix.TriXWriter;
    1.19 +import org.openrdf.rio.turtle.TurtleWriter;
    1.20 +
    1.21 +/**
    1.22 + * Factory class for creating instances of RDFHandler class
    1.23 + * based on the given format, which should be one of the formats
    1.24 + * mentioned in {@link org.openrdf.rio.RDFFormat} class, and 
    1.25 + * an OutputStream to which the handler should write to.
    1.26 + * 
    1.27 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    1.28 + */
    1.29 +public class RDFHandlerFactory {
    1.30 +
    1.31 +	public static RDFHandler createRDFHandler(String format, OutputStream out) {
    1.32 +		RDFHandler handler = null;
    1.33 +		RDFFormat rdfFormat = RDFFormat.valueOf(format);
    1.34 +		
    1.35 +		if (rdfFormat == RDFFormat.NTRIPLES || rdfFormat == null) {
    1.36 +			handler = new NTriplesWriter(out);
    1.37 +			
    1.38 +		} else if (rdfFormat == RDFFormat.N3) {
    1.39 +			handler = new N3Writer(out);
    1.40 +			
    1.41 +		} else if (rdfFormat == RDFFormat.RDFXML) {
    1.42 +			handler = new RDFXMLPrettyWriter(out);
    1.43 +			
    1.44 +		} else if (rdfFormat == RDFFormat.TURTLE) {
    1.45 +			handler = new TurtleWriter(out);
    1.46 +			
    1.47 +		} else if (rdfFormat == RDFFormat.TRIG) {
    1.48 +			handler = new TriGWriter(out);
    1.49 +			
    1.50 +		} else if (rdfFormat == RDFFormat.TRIX) {
    1.51 +			handler = new TriXWriter(out);
    1.52 +			
    1.53 +		} else if (rdfFormat == RDFFormat.BINARY) {
    1.54 +			handler = new BinaryRDFWriter(out);
    1.55 +			
    1.56 +		}
    1.57 +		
    1.58 +		return handler;
    1.59 +	}
    1.60 +}