diff options
Diffstat (limited to 'src/wcps/server/cli')
| -rw-r--r-- | src/wcps/server/cli/f_grammar.java | 66 | ||||
| -rw-r--r-- | src/wcps/server/cli/grammar.java | 16 | ||||
| -rw-r--r-- | src/wcps/server/cli/xml.java | 105 |
3 files changed, 137 insertions, 50 deletions
diff --git a/src/wcps/server/cli/f_grammar.java b/src/wcps/server/cli/f_grammar.java new file mode 100644 index 0000000..6468767 --- /dev/null +++ b/src/wcps/server/cli/f_grammar.java @@ -0,0 +1,66 @@ +package wcps.server.cli; + +import grammar.*; +import grammar.wcpsParser.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import org.antlr.runtime.ANTLRInputStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.apache.commons.io.FileUtils; + +/** Test the WCPS grammar parser (generated by ANTLR). + * Input the path that contains an Abstract Syntax query. + * Outputs the corresponding XML tree. + * + * @author Andrei Aiordachioaie + */ +public class f_grammar { + + private static String query; + private static String path; + + public static void main(String[] args) throws RecognitionException, IOException + { + if (args.length != 1) + { + System.err.println("AbstractGrammarGen: no parameter to specify input file !"); + path = "test/test-tmp/29.test"; + query = FileUtils.readFileToString(new File(path)); + } + else + { + path = args[0]; + query = FileUtils.readFileToString(new File(path)); + } + + System.out.println("Running with the following query: " + query); + + String xmlString = runQuery(query); + System.out.println("Output XML: \n****************\n" + xmlString); + + System.exit(0); + + } + + public static String runQuery(String query) throws IOException, RecognitionException + { + InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1 + ANTLRInputStream inputStream = new ANTLRInputStream(stream); +// wcpsLexer lexer = new wcpsLexer( inputStream ); + wcpsLexer lexer = new wcpsLexer( inputStream ); + + CommonTokenStream tokenStream = new CommonTokenStream(lexer); +// wcpsParser parser = new wcpsParser(tokenStream); + wcpsParser parser = new wcpsParser(tokenStream); + + wcpsRequest_return rrequest = parser.wcpsRequest(); + WCPSRequest request = rrequest.value; + + String result = request.toXML(); + return result; + } + +} diff --git a/src/wcps/server/cli/grammar.java b/src/wcps/server/cli/grammar.java index eabee72..29961a2 100644 --- a/src/wcps/server/cli/grammar.java +++ b/src/wcps/server/cli/grammar.java @@ -24,22 +24,30 @@ public class grammar { if (args.length != 1) { System.err.println("AbstractGrammarGen: no query as parameter !"); - query = "for r in (rgb) return encode( r * ((r.green > 130) and " + - "(r.red < 110)), \"jpeg\")"; + query = "for a in (rgb) return " + + "condense + over $x x(1:10), $y y(25:75) " + + "using $x * (a[x($x), y($y)]).red"; } else query = args[0]; System.out.println("Running with the following query: " + query); - String xmlString = runQuery(query); + String xmlString = convertAbstractQueryToXml(query); System.out.println("Output XML: \n****************\n" + xmlString); System.exit(0); } - public static String runQuery(String query) throws IOException, RecognitionException + /** Converts a WCPS abstract syntax query to an XML query + * + * @param query Abstract Syntax query + * @return String XML query + * @throws java.io.IOException + * @throws org.antlr.runtime.RecognitionException + */ + public static String convertAbstractQueryToXml(String query) throws IOException, RecognitionException { InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1 ANTLRInputStream inputStream = new ANTLRInputStream(stream); diff --git a/src/wcps/server/cli/xml.java b/src/wcps/server/cli/xml.java index 10c201c..b4f5639 100644 --- a/src/wcps/server/cli/xml.java +++ b/src/wcps/server/cli/xml.java @@ -23,6 +23,7 @@ package wcps.server.cli;
+import java.io.IOException;
import wcps.server.core.CachedMetadataSource;
import wcps.server.core.DbMetadataSource;
import wcps.server.core.ProcessCoveragesRequest;
@@ -31,7 +32,9 @@ import wcps.server.core.WCPS; import java.io.File;
import java.io.FileInputStream;
+import java.io.StringReader;
import java.util.Properties;
+import org.xml.sax.InputSource;
/**
* This is a small application around the WCPS core. It takes XML requests as files and runs them
@@ -43,27 +46,13 @@ import java.util.Properties; public class xml
{
private static WCPS wcps;
+ private static DbMetadataSource metadataSource;
- public static void main(String[] args)
- {
- if (args.length < 1)
- {
- System.err.println("WCPS CLI: no input files");
-
- System.err.println("\nWCPS CLI Usage: java wcps.server.cli.xml input.xml");
- System.err.println("Where input.xml contains a ProcessCoverages Request ");
- System.exit(1);
-
- args = new String[1];
- args[0] = "old_testing/testcases/1.test.xml";
- }
- if (args.length > 1)
- {
- System.err.println("WCPS: no input files");
- System.exit(1);
- }
-
- String pcSchemaFileName =
+ private static void initMetadata()
+ {
+ File cwd = new File(".");
+ System.out.println("Working in " + cwd.getAbsolutePath());
+ String pcSchemaFileName = "src/conf/" +
"xml" + File.separator + "ogc" + File.separator + "wcps"
+ File.separator + "1.0.0" + File.separator + "wcpsProcessCoverages.xsd";
File pcSchemaFile = new File(pcSchemaFileName);
@@ -75,7 +64,7 @@ public class xml System.exit(1);
}
- DbMetadataSource metadataSource = null;
+ metadataSource = null;
try
{
@@ -95,14 +84,38 @@ public class xml e.printStackTrace(System.err);
System.exit(1);
}
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length < 1)
+ {
+ System.err.println("WCPS CLI: no input files");
+
+ System.err.println("\nWCPS CLI Usage: java wcps.server.cli.xml input.xml");
+ System.err.println("Where input.xml contains a ProcessCoverages Request ");
+// System.exit(1);
+
+ args = new String[1];
+ args[0] = "test/testcases-wcps_dollar/25.test.xml";
+ }
+ if (args.length > 1)
+ {
+ System.err.println("WCPS: no input files");
+ System.exit(1);
+ }
+
+ initMetadata();
for (int i = 0; i < args.length; i++)
{
File fileIn = null;
+ InputSource is = null;
try
{
fileIn = new File(args[i]);
+ is = new InputSource(new FileInputStream(fileIn));
}
catch (Exception fnfe)
{
@@ -111,9 +124,11 @@ public class xml System.exit(1);
}
- boolean ok = processCoverage(fileIn, i);
-
- if (!ok)
+
+ String result = processCoverage(is, i);
+ if (result != null)
+ System.out.println(result);
+ else
{
System.err.println("WCPS: " + args[i] + " failed");
System.exit(1);
@@ -125,30 +140,18 @@ public class xml }
- private static boolean processCoverage(File in, int i)
+ private static String processCoverage(InputSource is, int i)
{
+ String result = null;
+
try
{
-
- ProcessCoveragesRequest r =
- wcps.pcPrepare("http://kahlua.eecs.jacobs-university.de:7001",
- "RASSERVICE", in);
-
+ ProcessCoveragesRequest r = wcps.pcPrepare("http://kahlua.eecs.jacobs-university.de:9001",
+ "RASSERVICE", is);
System.err.println("Request " + i);
-
- System.out.println(r.getRasqlQuery());
-
-
-/* Iterator<byte[]> results = r.execute().iterator();
-
- int j = 0;
- while( results.hasNext() ) {
- String outFileName = "WCPS-" + i + "-" + j++;
- FileOutputStream out = new FileOutputStream( outFileName );
- out.write( results.next() );
- out.close();
- System.out.println( "WCPS: " + outFileName + " written" );
- }*/
+ String rasql = r.getRasqlQuery();
+ String mime = r.getMime();
+ result = "[" + mime + "] " + rasql;
}
catch (Exception e)
{
@@ -157,7 +160,17 @@ public class xml e.printStackTrace(System.err);
}
- return true;
-
+ return result;
}
+
+ /** Converts a WCPS XML query into a RasQL query string **/
+ public static String convertXmlToRasql(String query)
+ {
+ String rasql = null;
+ if (metadataSource == null)
+ initMetadata();
+ InputSource is = new InputSource(new StringReader(query));
+ rasql = processCoverage(is, 1);
+ return rasql;
+ }
}
|
