if (queryLnStr != null) {
queryLn = QueryLanguage.valueOf(queryLnStr);
if (queryLn == null) {
throw new ClientHTTPException(SC_BAD_REQUEST, "Unknown query language: " + queryLnStr);
}
}
// determine if inferred triples should be included in query evaluation
boolean includeInferred = ProtocolUtil.parseBooleanParam(request, INCLUDE_INFERRED_PARAM_NAME, true);
// build a dataset, if specified
String[] defaultGraphURIs = request.getParameterValues(DEFAULT_GRAPH_PARAM_NAME);
String[] namedGraphURIs = request.getParameterValues(NAMED_GRAPH_PARAM_NAME);
DatasetImpl dataset = null;
if (defaultGraphURIs != null || namedGraphURIs != null) {
dataset = new DatasetImpl();
if (defaultGraphURIs != null) {
for (String defaultGraphURI : defaultGraphURIs) {
try {
URI uri = repository.getValueFactory().createURI(defaultGraphURI);
dataset.addDefaultGraph(uri);
}
catch (IllegalArgumentException e) {
throw new ClientHTTPException(SC_BAD_REQUEST, "Illegal URI for default graph: "
+ defaultGraphURI);
}
}
}
if (namedGraphURIs != null) {
for (String namedGraphURI : namedGraphURIs) {
try {
URI uri = repository.getValueFactory().createURI(namedGraphURI);
dataset.addNamedGraph(uri);
}
catch (IllegalArgumentException e) {
throw new ClientHTTPException(SC_BAD_REQUEST, "Illegal URI for named graph: "
+ namedGraphURI);
}
}
}
}
try {
result = repositoryCon.prepareQuery(queryLn, queryStr);
result.setIncludeInferred(includeInferred);
if (dataset != null) {
result.setDataset(dataset);
}
// determine if any variable bindings have been set on this query.
@SuppressWarnings("unchecked")
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String parameterName = parameterNames.nextElement();
if (parameterName.startsWith(BINDING_PREFIX) && parameterName.length() > BINDING_PREFIX.length())
{
String bindingName = parameterName.substring(BINDING_PREFIX.length());
Value bindingValue = ProtocolUtil.parseValueParam(request, parameterName,
repository.getValueFactory());
result.setBinding(bindingName, bindingValue);
}
}
}
catch (UnsupportedQueryLanguageException e) {
ErrorInfo errInfo = new ErrorInfo(ErrorType.UNSUPPORTED_QUERY_LANGUAGE, queryLn.getName());
throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString());
}
catch (MalformedQueryException e) {
ErrorInfo errInfo = new ErrorInfo(ErrorType.MALFORMED_QUERY, e.getMessage());
throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString());
}
catch (RepositoryException e) {
logger.error("Repository error", e);
response.sendError(SC_INTERNAL_SERVER_ERROR);
}