}
if ( cl.contains(helpDecl) )
{
usage() ;
throw new TerminationException(0) ;
}
if ( cl.contains(versionDecl) )
{
System.out.println("ARQ Version: "+ARQ.VERSION+" (Jena: "+Jena.VERSION+")") ;
throw new TerminationException(0) ;
}
// ==== General things
boolean verbose = cl.contains(verboseDecl) ;
boolean quiet = cl.contains(quietDecl) ;
if ( cl.contains(strictDecl) )
ARQ.setStrictMode() ;
boolean actionCopySubstitute = cl.contains(reduceDecl) ;
boolean actionPrintPrefix = false ;
boolean actionPrintSPARQL = false ;
boolean actionPrint = cl.contains(printDecl) ;
for ( Iterator<String> iter = cl.getValues(printDecl).iterator() ; iter.hasNext(); )
{
String v = iter.next();
if ( v.equalsIgnoreCase("prefix") || v.equalsIgnoreCase("op") )
actionPrintPrefix = true ;
else if ( v.equalsIgnoreCase("expr") ) actionPrintSPARQL = true ;
else
{
System.err.println("Unknown print form: "+v) ;
throw new TerminationException(0) ;
}
}
// ==== Do it
for ( int i = 0 ; i < cl.getNumPositional() ; i++ )
{
String exprStr = cl.getPositionalArg(i) ;
exprStr = cl.indirect(exprStr) ;
try {
PrefixMapping pmap = PrefixMapping.Factory.create() ;
pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap()) ;
pmap.setNsPrefix("", "http://example/") ;
pmap.setNsPrefix("ex", "http://example/ns#") ;
Expr expr = ExprUtils.parse(exprStr, pmap) ;
if ( verbose )
System.out.print(expr.toString()+" => ") ;
if ( actionPrint )
{
if ( actionPrintSPARQL )
System.out.println(ExprUtils.fmtSPARQL(expr)) ;
if ( actionPrintPrefix )
WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap)) ;
continue ;
}
try {
if ( actionCopySubstitute )
{
Expr e = expr.copySubstitute(BindingFactory.create(), true) ;
System.out.println(e) ;
}
else
{
// Default action
ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactory.nowAsDateTime()) ;
FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null) ;
NodeValue r = expr.eval(null, env) ;
//System.out.println(r.asQuotedString()) ;
Node n = r.asNode() ;
String s = FmtUtils.stringForNode(n) ;
System.out.println(s) ;
}
} catch (ExprEvalException ex)
{
System.out.println("Exception: "+ex.getMessage()) ;
throw new TerminationException(2) ;
}
} catch (QueryParseException ex)
{
System.err.println("Parse error: "+ex.getMessage()) ;
throw new TerminationException(2) ;
}
}
}