use of org.apache.jena.query.Syntax in project jena by apache.
the class UpdateValidatorHTML method executeHTML.
//static final String paramSyntaxExtended = "extendedSyntax" ;
public static void executeHTML(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
try {
String[] args = httpRequest.getParameterValues(paramUpdate);
if (args == null || args.length == 0) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "No update parameter to validator");
return;
}
if (args.length > 1) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Too many update parameters");
return;
}
final String updateString = httpRequest.getParameter(paramUpdate).replaceAll("(\r|\n| )*$", "");
String updateSyntax = httpRequest.getParameter(paramSyntax);
if (updateSyntax == null || updateSyntax.equals(""))
updateSyntax = "SPARQL";
Syntax language = Syntax.lookup(updateSyntax);
if (language == null) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown syntax: " + updateSyntax);
return;
}
String lineNumbersArg = httpRequest.getParameter(paramLineNumbers);
String[] a = httpRequest.getParameterValues(paramFormat);
// Currently default.
boolean outputSPARQL = true;
boolean lineNumbers = true;
if (lineNumbersArg != null)
lineNumbers = lineNumbersArg.equalsIgnoreCase("true") || lineNumbersArg.equalsIgnoreCase("yes");
// Headers
setHeaders(httpResponse);
ServletOutputStream outStream = httpResponse.getOutputStream();
outStream.println("<html>");
printHead(outStream, "SPARQL Update Validation Report");
outStream.println("<body>");
outStream.println("<h1>SPARQL Update Validator</h1>");
// Print as received
outStream.println("<p>Input:</p>");
output(outStream, (out) -> out.print(updateString), lineNumbers);
// Attempt to parse it.
UpdateRequest request = null;
try {
request = UpdateFactory.create(updateString, "http://example/base/", language);
} catch (ARQException ex) {
// Over generous exception (should be QueryException)
// but this makes the code robust.
outStream.println("<p>Syntax error:</p>");
startFixed(outStream);
outStream.println(ex.getMessage());
finishFixed(outStream);
} catch (RuntimeException ex) {
outStream.println("<p>Internal error:</p>");
startFixed(outStream);
outStream.println(ex.getMessage());
finishFixed(outStream);
}
// Because we pass into anon inner classes
final UpdateRequest updateRequest = request;
// OK? Pretty print
if (updateRequest != null && outputSPARQL) {
outStream.println("<p>Formatted, parsed update request:</p>");
output(outStream, (out) -> updateRequest.output(out), lineNumbers);
}
outStream.println("</body>");
outStream.println("</html>");
} catch (Exception ex) {
serviceLog.warn("Exception in doGet", ex);
}
}
use of org.apache.jena.query.Syntax in project jena by apache.
the class ModQueryIn method processArgs.
@Override
public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException {
if (cmdline.contains(queryBaseDecl))
baseURI = cmdline.getValue(queryBaseDecl);
if (cmdline.contains(queryFileDecl)) {
queryFilename = cmdline.getValue(queryFileDecl);
querySyntax = Syntax.guessFileSyntax(queryFilename, defaultQuerySyntax);
}
if (cmdline.getNumPositional() == 0 && queryFilename == null)
cmdline.cmdError("No query string or query file");
if (cmdline.getNumPositional() > 1)
cmdline.cmdError("Only one query string allowed");
if (cmdline.getNumPositional() == 1 && queryFilename != null)
cmdline.cmdError("Either query string or query file - not both");
if (queryFilename == null) {
// One positional argument.
String qs = cmdline.getPositionalArg(0);
if (cmdline.matchesIndirect(qs))
querySyntax = Syntax.guessFileSyntax(qs, defaultQuerySyntax);
queryString = cmdline.indirect(qs);
}
// Set syntax
if (cmdline.contains(querySyntaxDecl)) {
// short name
String s = cmdline.getValue(querySyntaxDecl);
Syntax syn = Syntax.lookup(s);
if (syn == null)
cmdline.cmdError("Unrecognized syntax: " + s);
querySyntax = syn;
}
}
use of org.apache.jena.query.Syntax in project jena by apache.
the class ModQueryOut method processArgs.
@Override
public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException {
if (cmdline.contains(queryOutputSyntaxDecl)) {
// short name
String s = cmdline.getValue(queryOutputSyntaxDecl);
Syntax syn = Syntax.lookup(s);
if (syn == null)
cmdline.cmdError("Unrecognized syntax: " + s);
outputSyntax = syn;
}
lineNumbers = cmdline.contains(queryNumberDecl);
}
Aggregations