Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Malformed requests



The SparqlHelperConfig.setErrorsHandlingType(char errorsHandlingType) specifies how the SPARQLParser should behave for malformed requests:

Behavior with the EXCEPTION value

If SparqlHelperConfig.getErrorsHandlingType() is set to ErrorsHandlingType.EXCEPTION, a MalformedQueryException will be thrown for malformed queries.

For example for the following request:
   SELECT ?zone
   WHER {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }
To parse this request, we can do:
   SPARQLParser parser = new SPARQLParser("sitac");
   SparqlRequest request = parser.parseQuery(<the request String>);
The following code will throw a MalformedQueryException.

Behavior with the EMPTY_QUERY value

If SparqlHelperConfig.getErrorsHandlingType() is set to ErrorsHandlingType.EMPTY_QUERY, malformed queries will generate a query withj no matches, and the resulting query will be set as not well-formed.

For example for the following request:
   SELECT ?zone
   WHER {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }
To parse this request, we can do:
   SparqlHelperConfig.getInstance().setErrorsHandlingType(ErrorsHandlingType.EMPTY_QUERY);      
   SPARQLParser parser = new SPARQLParser("sitac");
   SparqlRequest request = parser.parseQuery(<the request String>);
   boolean isValid = request.isWellformed(); // will return false
If you perform:
   String parsedQuery = request.toString();
You will have the following content:
   SELECT *
   WHERE {
      ?o rdf:type owl:Thing .
   }
   LIMIT 0

See also


Categories: Requestparsing

Copyright 2025 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence

Project Web Hosted by SourceForge.net Copyright 1999-2010 - Geeknet, Inc., All Rights Reserved About - Legal - Help