Strabon

changeset 475:f777bdf67d30

added N3, RDF/XML, and NTriples formats in describe
author pico
date Fri Jul 20 01:20:14 2012 +0300 (2012-07-20)
parents 3ed88c51ec15
children b817cc860552
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Fri Jul 20 00:08:27 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Fri Jul 20 01:20:14 2012 +0300
     1.3 @@ -329,7 +329,7 @@
     1.4  		selections.put("NTriples", "NTriples");
     1.5  		selections.put("RDF/XML", "RDF/XML");
     1.6  		selections.put("CSV", "CSV");
     1.7 -                selections.put("TSV", "TSV");
     1.8 +        selections.put("TSV", "TSV");
     1.9  		
    1.10  		Iterator <String> it = selections.keySet().iterator();
    1.11  		
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 20 00:08:27 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 20 01:20:14 2012 +0300
     2.3 @@ -222,9 +222,9 @@
     2.4  			throw new RepositoryException("Could not connect to Strabon.");
     2.5  		} 
     2.6  
     2.7 -		String answer = null;
     2.8 +		ByteArrayOutputStream answer = new ByteArrayOutputStream();
     2.9  		
    2.10 -		strabon.describe(queryString, strabon.getSailRepoConnection(),  answer);
    2.11 +		strabon.describe(queryString, strabon.getSailRepoConnection(), answerFormatStrabon, answer);
    2.12  		
    2.13  		return answer.toString();
    2.14  	}
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 20 00:08:27 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 20 01:20:14 2012 +0300
     3.3 @@ -1,5 +1,6 @@
     3.4  package eu.earthobservatory.runtime.generaldb;
     3.5  
     3.6 +import java.io.ByteArrayOutputStream;
     3.7  import java.io.File;
     3.8  import java.io.FileNotFoundException;
     3.9  import java.io.FileOutputStream;
    3.10 @@ -39,6 +40,8 @@
    3.11  import org.openrdf.rio.RDFParser;
    3.12  import org.openrdf.rio.Rio;
    3.13  import org.openrdf.rio.ntriples.NTriplesWriter;
    3.14 +import org.openrdf.rio.n3.N3Writer;
    3.15 +import org.openrdf.rio.rdfxml.RDFXMLWriter;
    3.16  import org.openrdf.sail.helpers.SailBase;
    3.17  import org.slf4j.Logger;
    3.18  import org.slf4j.LoggerFactory;
    3.19 @@ -426,7 +429,7 @@
    3.20  		logger.info("[Strabon.storeString] Storing was successful.");
    3.21  	}
    3.22  
    3.23 -	public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException
    3.24 +	public void describe(String describeString, SailRepositoryConnection con, String format, OutputStream out) throws MalformedQueryException
    3.25  	{
    3.26  		GraphQuery  graphQuery = null;
    3.27  
    3.28 @@ -439,23 +442,45 @@
    3.29  
    3.30  		logger.info("[Strabon.describe] Executing describe query:" + describeString);
    3.31  
    3.32 -		try {
    3.33 -			OutputStream out = new FileOutputStream(outFile);
    3.34 -			RDFHandler rdfHandler = new NTriplesWriter(out);
    3.35 -			graphQuery.evaluate(rdfHandler);
    3.36 -			out.close();
    3.37 +		//try {
    3.38 +			//OutputStream out = new FileOutputStream(outFile);
    3.39 +			RDFHandler rdfHandler = null;
    3.40 +			
    3.41 +			if(format.equalsIgnoreCase("NTRIPLES")) {
    3.42 +				rdfHandler = new NTriplesWriter(out);
    3.43 +				
    3.44 +			} else if(format.equalsIgnoreCase("RDF/XML")) {
    3.45 +				rdfHandler = new RDFXMLWriter(out);
    3.46 +				
    3.47 +			} else if(format.equalsIgnoreCase("N3")) {
    3.48 +				rdfHandler = new N3Writer(out);
    3.49 +				
    3.50 +			} 
    3.51 +			logger.info("[Strabon.describe] Output: {}");
    3.52 +			
    3.53 +			try {
    3.54 +				graphQuery.evaluate(rdfHandler);
    3.55 +			} catch (QueryEvaluationException e) {
    3.56 +				// TODO Auto-generated catch block
    3.57 +				e.printStackTrace();
    3.58 +			} catch (RDFHandlerException e) {
    3.59 +				// TODO Auto-generated catch block
    3.60 +				e.printStackTrace();
    3.61 +			}
    3.62 +			//out.close();
    3.63 +			
    3.64  
    3.65 -		} catch (FileNotFoundException e) {
    3.66 -			logger.error("[Strabon.describe]", e);
    3.67 -		} catch (QueryEvaluationException e) {
    3.68 -			logger.error("[Strabon.describe]", e);
    3.69 -		} catch (RDFHandlerException e) {
    3.70 -			logger.error("[Strabon.describe]", e);
    3.71 -		} catch (IOException e) {
    3.72 -			logger.error("[Strabon.describe]", e);
    3.73 -		}
    3.74 +		//} catch (FileNotFoundException e) {
    3.75 +		//	logger.error("[Strabon.describe]", e);
    3.76 +		//} catch (QueryEvaluationException e) {
    3.77 +		//	logger.error("[Strabon.describe]", e);
    3.78 +		//} catch (RDFHandlerException e) {
    3.79 +		//	logger.error("[Strabon.describe]", e);
    3.80 +		//} catch (IOException e) {
    3.81 +		//	logger.error("[Strabon.describe]", e);
    3.82 +		//}
    3.83  
    3.84 -		logger.info("[Strabon.describe] Output: {}", outFile);
    3.85 +		
    3.86  	}
    3.87  	
    3.88  	private static void writeString(OutputStream out, String str) throws IOException {