use of org.apache.jena.riot.Lang in project jena by apache.
the class FusekiConfig method readConfigurationDirectory.
// ---- Directory of assemblers
/** Read service descriptions in the given directory */
public static List<DataAccessPoint> readConfigurationDirectory(String dir) {
Path pDir = Paths.get(dir).normalize();
File dirFile = pDir.toFile();
if (!dirFile.exists()) {
log.warn("Not found: directory for assembler files for services: '" + dir + "'");
return Collections.emptyList();
}
if (!dirFile.isDirectory()) {
log.warn("Not a directory: '" + dir + "'");
return Collections.emptyList();
}
// Files that are not hidden.
DirectoryStream.Filter<Path> filter = (entry) -> {
File f = entry.toFile();
final Lang lang = filenameToLang(f.getName());
return !f.isHidden() && f.isFile() && lang != null && isRegistered(lang);
};
List<DataAccessPoint> dataServiceRef = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pDir, filter)) {
for (Path p : stream) {
DatasetDescriptionRegistry dsDescMap = FusekiServer.registryForBuild();
String fn = IRILib.filenameToIRI(p.toString());
log.info("Load configuration: " + fn);
Model m = readAssemblerFile(fn);
readConfiguration(m, dsDescMap, dataServiceRef);
}
} catch (IOException ex) {
log.warn("IOException:" + ex.getMessage(), ex);
}
return dataServiceRef;
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class ResponseDataset method doResponseDataset.
public static void doResponseDataset(HttpAction action, Dataset dataset) {
HttpServletRequest request = action.request;
HttpServletResponse response = action.response;
// Header request type
String mimeType = null;
MediaType i = ConNeg.chooseContentType(request, DEF.constructOffer, DEF.acceptTurtle);
if (i != null)
mimeType = i.getContentType();
String outputField = ResponseOps.paramOutput(request, shortNamesModel);
if (outputField != null)
mimeType = outputField;
String writerMimeType = mimeType;
if (mimeType == null) {
Fuseki.actionLog.warn("Can't find MIME type for response");
String x = WebLib.getAccept(request);
String msg;
if (x == null)
msg = "No Accept: header";
else
msg = "Accept: " + x + " : Not understood";
ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, msg);
}
String contentType = mimeType;
String charset = charsetUTF8;
String forceAccept = ResponseOps.paramForceAccept(request);
if (forceAccept != null) {
contentType = forceAccept;
charset = charsetUTF8;
}
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null)
ServletOps.errorBadRequest("Can't determine output content type: " + contentType);
try {
ResponseResultSet.setHttpResponse(action, contentType, charset);
response.setStatus(HttpSC.OK_200);
ServletOutputStream out = response.getOutputStream();
try {
if (RDFLanguages.isQuads(lang))
RDFDataMgr.write(out, dataset, lang);
else
RDFDataMgr.write(out, dataset.getDefaultModel(), lang);
out.flush();
} catch (JenaException ex) {
// request (inappropriate content type).
if (lang.equals(Lang.RDFXML))
ServletOps.errorBadRequest("Failed to write output in RDF/XML: " + ex.getMessage());
else
ServletOps.errorOccurred("Failed to write output: " + ex.getMessage(), ex);
}
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
action.log.info("Exception while writing the response model: " + ex.getMessage(), ex);
ServletOps.errorOccurred("Exception while writing the response model: " + ex.getMessage(), ex);
}
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class QueryEngineHTTP method execDataset.
private Dataset execDataset(Dataset dataset) {
Pair<InputStream, Lang> p = execConstructWorker(datasetContentType);
InputStream in = p.getLeft();
Lang lang = p.getRight();
try {
RDFDataMgr.read(dataset, in, lang);
} finally {
this.close();
}
return dataset;
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class QueryEngineHTTP method setModelContentType.
/**
* Sets the Content Type for CONSTRUCT/DESCRIBE queries provided that the
* format is supported
*
* @param contentType
*/
public void setModelContentType(String contentType) {
// Check that this is a valid setting
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null)
throw new IllegalArgumentException("Given Content Type '" + contentType + "' is not supported by RIOT");
if (!RDFLanguages.isTriples(lang))
throw new IllegalArgumentException("Given Content Type '" + contentType + "' is not a RDF Graph format");
modelContentType = contentType;
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class QueryEngineHTTP method execTriples.
private Iterator<Triple> execTriples() {
Pair<InputStream, Lang> p = execConstructWorker(modelContentType);
InputStream in = p.getLeft();
Lang lang = p.getRight();
// Base URI?
return RDFDataMgr.createIteratorTriples(in, lang, null);
}
Aggregations