From: Jakub Skoczen Date: Mon, 20 Oct 2014 10:38:17 +0000 (+0200) Subject: Add -s switch for sparql conversion X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=fce3f8f705508530a0b060f7f800e785b9c1d77f;p=cql-java-moved-to-github.git Add -s switch for sparql conversion --- diff --git a/src/main/java/org/z3950/zing/cql/CQLParser.java b/src/main/java/org/z3950/zing/cql/CQLParser.java index cbe64d5..0565afa 100644 --- a/src/main/java/org/z3950/zing/cql/CQLParser.java +++ b/src/main/java/org/z3950/zing/cql/CQLParser.java @@ -2,15 +2,18 @@ package org.z3950.zing.cql; import java.io.BufferedReader; +import java.io.FileInputStream; import java.io.IOException; -import java.util.Properties; import java.io.InputStream; -import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Properties; import java.util.Set; +import org.z3950.zing.cql.sparql.Query; +import org.z3950.zing.cql.sparql.SPARQLNodeVisitor; +import org.z3950.zing.cql.utils.PrettyPrinter; /** @@ -444,10 +447,13 @@ public class CQLParser { argv.remove(0); pfile = (String) argv.get(0); argv.remove(0); - } + } else if (argv.size() > 0 && argv.get(0).equals("-s")) { + mode = 's'; + argv.remove(0); + } if (argv.size() > 1) { - System.err.println("Usage: CQLParser [-1] [-d] [-c] " + + System.err.println("Usage: CQLParser [-1] [-d] [-c] [-s] " + "[-p []"); System.err.println("If unspecified, query is read from stdin"); System.exit(1); @@ -507,6 +513,13 @@ public class CQLParser { ex.getMessage()); System.exit(5); } + } else if (mode == 's') { + SPARQLNodeVisitor visitor = new SPARQLNodeVisitor(); + root.traverse(visitor); + Query sparql = visitor.getQuery(); + PrettyPrinter pp = new PrettyPrinter(); + sparql.print(pp); + System.out.println(pp.toString()); } else { System.out.print(root.toXCQL()); }