use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class TestSyntaxDetermination method test.
static void test(String url, String ct, Lang hint, Lang expected) {
ContentType x = WebContent.determineCT(ct, hint, url);
Lang lang = RDFDataMgr.determineLang(url, ct, hint);
assertEquals(expected, lang);
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class LocatorClassLoader method open.
@Override
public TypedInputStream open(String resourceName) {
if (classLoader == null)
return null;
InputStream in = classLoader.getResourceAsStream(resourceName);
if (in == null) {
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Failed to open: " + resourceName);
return null;
}
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Found: " + resourceName);
ContentType ct = RDFLanguages.guessContentType(resourceName);
// No sensible base URI.
return new TypedInputStream(in, ct, null);
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class LocatorFile method open.
/** Open anything that looks a bit like a file name */
@Override
public TypedInputStream open(String filenameIRI) {
String fn = toFileName(filenameIRI);
if (fn == null)
return null;
try {
if (!exists$(fn)) {
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Not found: " + filenameIRI + thisDirLogStr);
return null;
}
} catch (AccessControlException e) {
log.warn("Security problem testing for file", e);
return null;
}
try {
InputStream in = IO.openFileEx(fn);
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Found: " + filenameIRI + thisDirLogStr);
ContentType ct = RDFLanguages.guessContentType(filenameIRI);
return new TypedInputStream(in, ct, filenameIRI);
} catch (IOException ioEx) {
// Includes FileNotFoundException
// We already tested whether the file exists or not.
log.warn("File unreadable (but exists): " + fn + " Exception: " + ioEx.getMessage());
return null;
}
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_REST_RW method incomingData.
private static void incomingData(HttpAction action, StreamRDF dest) {
String base = wholeRequestURL(action.request);
ContentType ct = FusekiLib.getContentType(action);
Lang lang = RDFLanguages.contentTypeToLang(ct.getContentType());
if (lang == null) {
errorBadRequest("Unknown content type for triples: " + ct);
return;
}
InputStream input = null;
try {
input = action.request.getInputStream();
} catch (IOException ex) {
IO.exception(ex);
}
int len = action.request.getContentLength();
if (action.verbose) {
if (len >= 0)
log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName()));
else
log.info(format("[%d] Body: Content-Type=%s, Charset=%s => %s", action.id, ct.getContentType(), ct.getCharset(), lang.getName()));
}
parse(action, dest, input, lang, base);
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_Query method validateParams.
/**
* Helper method for validating request.
* @param request HTTP request
* @param params parameters in a collection of Strings
*/
protected void validateParams(HttpServletRequest request, Collection<String> params) {
ContentType ct = FusekiLib.getContentType(request);
boolean mustHaveQueryParam = true;
if (ct != null) {
String incoming = ct.getContentType();
if (WebContent.contentTypeSPARQLQuery.equals(incoming)) {
mustHaveQueryParam = false;
//error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Unofficial "+WebContent.contentTypeSPARQLQuery+" not supported") ;
} else if (WebContent.contentTypeHTMLForm.equals(incoming)) {
} else
error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Unsupported: " + incoming);
}
if (mustHaveQueryParam) {
int N = countParamOccurences(request, paramQuery);
if (N == 0)
errorBadRequest("SPARQL Query: No 'query=' parameter");
if (N > 1)
errorBadRequest("SPARQL Query: Multiple 'query=' parameters");
// application/sparql-query does not use a query param.
String queryStr = request.getParameter(HttpNames.paramQuery);
if (queryStr == null)
errorBadRequest("SPARQL Query: No query specified (no 'query=' found)");
if (queryStr.isEmpty())
errorBadRequest("SPARQL Query: Empty query string");
}
if (params != null) {
Enumeration<String> en = request.getParameterNames();
for (; en.hasMoreElements(); ) {
String name = en.nextElement();
if (!params.contains(name))
warning("SPARQL Query: Unrecognize request parameter (ignored): " + name);
}
}
}
Aggregations