本文整理汇总了Java中org.openrdf.rio.RDFFormat.forMIMEType方法的典型用法代码示例。如果您正苦于以下问题:Java RDFFormat.forMIMEType方法的具体用法?Java RDFFormat.forMIMEType怎么用?Java RDFFormat.forMIMEType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.rio.RDFFormat
的用法示例。
在下文中一共展示了RDFFormat.forMIMEType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatFor
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private static RDFFormat formatFor(final String mimeType) {
final RDFFormat format = RDFFormat.forMIMEType(mimeType);
if (format == null) {
throw new IllegalArgumentException("No RDF format for MIME type '" + mimeType + "'");
}
return format;
}
示例2: forMIMEType
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private RDFFormat forMIMEType(String contentType, RDFFormat fallback) {
RDFFormat format = RDFFormat.forMIMEType(contentType);
RDFParserRegistry registry = RDFParserRegistry.getInstance();
if (format != null && registry.has(format))
return format;
return fallback;
}
示例3: doQuery
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
@Override
protected void doQuery(QueryDefinition query, WriterConfig config,
RepositoryConnection cxn, OutputStream os) throws Exception {
final GraphQuery sailGraphQuery = cxn
.prepareGraphQuery(query.getQueryLanguage(), query.getQuery(),
config.getBaseUri());
final RDFFormat format = RDFFormat.forMIMEType(config.getContentType(),
RDFFormat.RDFXML);
// final RDFFormat format = RDFWriterRegistry.getInstance()
// .getFileFormatForMIMEType(config.getFormat());
final RDFWriter w = RDFWriterRegistry.getInstance().get(format)
.getWriter(os);
applyConfig(w);
sailGraphQuery.evaluate(w);
}
示例4: getRDFFormat
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
/**
* Resolves an RDF2Go {@link Syntax} to an OpenRDF {@link RDFFormat}.
*
* @param syntax The RDF2Go Syntax to resolve.
* @return A RDFFormat for the specified syntax.
* @throws SyntaxNotSupportedException When the Syntax could not be resolved to a
* RDFFormat.
*/
public static RDFFormat getRDFFormat(Syntax syntax) throws SyntaxNotSupportedException {
for (String mimeType : syntax.getMimeTypes()) {
RDFFormat format = RDFFormat.forMIMEType(mimeType);
if (format != null) {
return format;
}
}
throw new SyntaxNotSupportedException("This version of Sesame seems to have no "
+ "support for " + syntax);
}
示例5: doProcessRequest
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
void doProcessRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException {
ServletOutputStream out = response.getOutputStream();
// get the RDF format (we check only the Accept header)
RDFFormat format = RDFFormat.forMIMEType(request.getHeader("accept"));
// get the query
String query = request.getParameter("query");
response.setContentType(format.getDefaultMIMEType());
response.setHeader(
"Content-Disposition",
"attachment; filename=describe." + format.getDefaultFileExtension() + "; "
+ format.getCharset());
try {
describe(query, format.getName(), out);
response.setStatus(HttpServletResponse.SC_OK);
} catch (Exception e) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
out.print(ResponseMessages.getXMLHeader());
out.print(ResponseMessages.getXMLException(e.getMessage()));
out.print(ResponseMessages.getXMLFooter());
} finally {
out.flush();
}
}
示例6: parseContentTypeHeader
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
/**
* <p>Retrieves the MIME type for the content-type parameter.
* The content-type parameter could be specified by the client as a parameter or
* a header in the HTTP request.
* HTTP header has a higher priority.</p>
* <p> Default (if no content-type parameter is given): RDF/XML.</p>
*
* @param request - the HTTP request.
* @return MIME type of the content-type parameter.
*/
public static String parseContentTypeHeader(final HttpServletRequest request) {
String content_type = request.getHeader(Headers.CONTENT_TYPE);
if (isNullOrEmptyString(content_type)) {
content_type = getParameterValue(request, Parameters.CONTENT_TYPE);
}
if (isNotNullOrEmptyString(content_type)) {
content_type = content_type.trim().toLowerCase();
}
if (RDFFormat.forMIMEType(content_type) == null) {
/*
* default: MimeTypes.RDF_XML
*/
if ((content_type == null) || content_type.isEmpty()) {
content_type = MimeTypes.RDF_XML;
}
/*
* guess MIME type
*/
else if (content_type.contains("htm")) {
content_type = MimeTypes.TEXT_HTML;
} else if (content_type.contains("xml")) {
content_type = MimeTypes.RDF_XML;
} else if (content_type.contains("rdf+json")) {
content_type = MimeTypes.RDF_JSON;
} else if (content_type.contains("json")) {
content_type = MimeTypes.JSON_LD;
} else if (content_type.contains("trix")) {
content_type = MimeTypes.TRIX;
} else if (content_type.contains("trig")) {
content_type = MimeTypes.TRIG;
} else if (content_type.contains("n3")) {
content_type = MimeTypes.N3;
} else if (content_type.contains("turtle") || content_type.contains("ttl")) {
content_type = MimeTypes.TURTLE;
} else if (content_type.contains("triple")) {
content_type = MimeTypes.TEXT_PLAIN;
} else if (content_type.contains("quad")) {
content_type = MimeTypes.N_QUADS;
} else if (content_type.contains("plain")) {
content_type = MimeTypes.TEXT_PLAIN;
} else if (content_type.contains("binary")) {
content_type = MimeTypes.BINARY;
}
/*
* default: RDF/XML
*/
else {
content_type = MimeTypes.RDF_XML;
}
}
return content_type;
}
示例7: processRequest
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
/**
* Processes the request made by a client of the endpoint that uses it as a service.
*
* @param request
* @param response
* @throws IOException
*/
private void processRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException {
// check whether we read from INPUT or URL
boolean input = (request.getParameter(Common.SUBMIT_URL) == null);
// graph
String graph =
(request.getParameter(Common.PARAM_GRAPH) != null) ? request
.getParameter(Common.PARAM_GRAPH) : null;
// inference
Boolean inference =
(request.getParameter(Common.PARAM_INFERENCE) != null) ? Boolean.valueOf(request
.getParameter(Common.PARAM_INFERENCE)) : false;
// RDF data to store
String data = getData(request);
if (data == null) {
response.sendError(HttpServletResponse.SC_NO_CONTENT);
return;
}
// the format of the data
RDFFormat format = RDFFormat.forMIMEType(request.getHeader("accept"));
if (format == null) { // unknown format
response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
return;
}
// store data
try {
store(data, graph, format.getName(), inference, !input);
// store was successful, return the respective message
response.sendError(HttpServletResponse.SC_OK);
} catch (Exception e) {
if (e instanceof RDFParseException || e instanceof IllegalArgumentException
|| e instanceof MalformedURLException) {
response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
} else {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
logger.error("[StrabonEndpoint.StoreBean] " + e.getMessage());
}
}