use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class REST_Quads method doPost.
@Override
protected void doPost(HttpAction action) {
if (!action.getDatasetRef().allowDatasetUpdate)
errorMethodNotAllowed("POST");
// Graph Store Protocol mode - POST triples to dataset causes
// a new graph to be created and the new URI returned via Location.
// Normally off.
// When off, POST of triples goes to default graph.
boolean gspMode = Fuseki.graphStoreProtocolPostCreate;
// Code to pass the GSP test suite.
// Not necessarily good code.
String x = action.request.getContentType();
if (x == null)
errorBadRequest("Content-type required for data format");
MediaType mediaType = MediaType.create(x);
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType());
if (lang == null)
lang = RDFLanguages.TRIG;
if (action.verbose)
log.info(format("[%d] Post: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));
if (RDFLanguages.isQuads(lang))
doPostQuads(action, lang);
else if (gspMode && RDFLanguages.isTriples(lang))
doPostTriplesGSP(action, lang);
else if (RDFLanguages.isTriples(lang))
doPostTriples(action, lang);
else
errorBadRequest("Not a triples or quads format: " + mediaType);
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class REST_Quads method doGet.
@Override
protected void doGet(HttpAction action) {
MediaType mediaType = HttpAction.contentNegotationQuads(action);
ServletOutputStream output;
try {
output = action.response.getOutputStream();
} catch (IOException ex) {
errorOccurred(ex);
output = null;
}
TypedOutputStream out = new TypedOutputStream(output, mediaType);
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType());
if (lang == null)
lang = RDFLanguages.TRIG;
if (action.verbose)
log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));
if (!RDFLanguages.isQuads(lang))
errorBadRequest("Not a quads format: " + mediaType);
action.beginRead();
try {
DatasetGraph dsg = action.getActiveDSG();
RDFDataMgr.write(out, dsg, lang);
success(action);
} finally {
action.endRead();
}
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class RDFLanguages method getCharsetForContentType.
public static String getCharsetForContentType(String contentType) {
MediaType ct = MediaType.create(contentType);
if (ct.getCharset() != null)
return ct.getCharset();
String mt = ct.getContentType();
if (contentTypeNTriples.equals(mt))
return charsetUTF8;
if (contentTypeNTriplesAlt.equals(mt))
return charsetASCII;
if (contentTypeNQuads.equals(mt))
return charsetUTF8;
if (contentTypeNQuadsAlt1.equals(mt))
return charsetASCII;
if (contentTypeNQuadsAlt2.equals(mt))
return charsetASCII;
return charsetUTF8;
}
Aggregations