• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ContentTypeNegotiator类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中de.fuberlin.wiwiss.pubby.negotiation.ContentTypeNegotiator的典型用法代码示例。如果您正苦于以下问题:Java ContentTypeNegotiator类的具体用法?Java ContentTypeNegotiator怎么用?Java ContentTypeNegotiator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ContentTypeNegotiator类属于de.fuberlin.wiwiss.pubby.negotiation包,在下文中一共展示了ContentTypeNegotiator类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doResponseModel

点赞 3

import de.fuberlin.wiwiss.pubby.negotiation.ContentTypeNegotiator; //导入依赖的package包/类
private void doResponseModel() throws IOException {
response.addHeader("Vary", "Accept");
ContentTypeNegotiator negotiator = PubbyNegotiator.getDataNegotiator();
MediaRangeSpec bestMatch = negotiator.getBestMatch(
		request.getHeader("Accept"), request.getHeader("User-Agent"));
if (bestMatch == null) {
	response.setStatus(406);
	response.setContentType("text/plain");
	ServletOutputStream out = response.getOutputStream();
	out.println("406 Not Acceptable: The requested data format is not supported.");
	out.println("Supported formats are RDF/XML, Turtle, N3, and N-Triples.");
	return;
}
response.setContentType(bestMatch.getMediaType());
getWriter(bestMatch.getMediaType()).write(model, response);
response.getOutputStream().flush();
  }
 

开发者ID:aitoralmeida,
项目名称:c4a_data_repository,
代码行数:18,
代码来源:ModelResponse.java

示例2: doGet

点赞 2

import de.fuberlin.wiwiss.pubby.negotiation.ContentTypeNegotiator; //导入依赖的package包/类
public boolean doGet(String relativeURI, HttpServletRequest request,
		HttpServletResponse response, Configuration config) throws IOException {
	MappedResource resource = config.getMappedResourceFromRelativeWebURI(relativeURI, true);
	if (resource == null) return false;

	response.addHeader("Vary", "Accept, User-Agent");
	ContentTypeNegotiator negotiator = PubbyNegotiator.getPubbyNegotiator();
	MediaRangeSpec bestMatch = negotiator.getBestMatch(
			request.getHeader("Accept"), request.getHeader("User-Agent"));
	if (bestMatch == null) {
		response.setStatus(406);
		response.setContentType("text/plain");
		response.getOutputStream().println(
				"406 Not Acceptable: The requested data format is not supported. " +
				"Only HTML and RDF are available.");
		return true;
	}
	
	response.setStatus(303);
	response.setContentType("text/plain");
	String location;
	if ("text/html".equals(bestMatch.getMediaType())) {
		location = resource.getPageURL();
	} else if (resource.getDataset().redirectRDFRequestsToEndpoint()) {
		location = resource.getDataset().getDataSource().getResourceDescriptionURL(
				resource.getDatasetURI());	
	} else {
		location = resource.getDataURL();
	}
	response.addHeader("Location", location);
	response.getOutputStream().println(
			"303 See Other: For a description of this item, see " + location);
	return true;
}
 

开发者ID:health-and-care-developer-network,
项目名称:health-and-care-developer-network,
代码行数:35,
代码来源:WebURIServlet.java

示例3: doGet

点赞 2

import de.fuberlin.wiwiss.pubby.negotiation.ContentTypeNegotiator; //导入依赖的package包/类
public void doGet(HttpServletRequest request,
		HttpServletResponse response) throws IOException, ServletException {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	String relativeResourceURI = request.getRequestURI().substring(
			request.getContextPath().length() + request.getServletPath().length());
	// Some servlet containers keep the leading slash, some don't
	if (!"".equals(relativeResourceURI) && "/".equals(relativeResourceURI.substring(0, 1))) {
		relativeResourceURI = relativeResourceURI.substring(1);
	}
	if (request.getQueryString() != null) {
		relativeResourceURI = relativeResourceURI + "?" + request.getQueryString();
	}
	
	/* Determine service stem, i.e. vocab/ in /[vocab/]resource */
	int servicePos;
	if (-1 == (servicePos = request.getServletPath().indexOf("/" + D2RServer.getResourceServiceName())))
			throw new ServletException("Expected to find service name /" + D2RServer.getResourceServiceName());
	String serviceStem = request.getServletPath().substring(1, servicePos + 1);

	String resourceURI = server.resourceBaseURI(serviceStem) + relativeResourceURI;
	if (handleDownload(resourceURI, response, server)) {
		return;
	}

	response.addHeader("Vary", "Accept, User-Agent");
	ContentTypeNegotiator negotiator = PubbyNegotiator.getPubbyNegotiator();
	MediaRangeSpec bestMatch = negotiator.getBestMatch(
			request.getHeader("Accept"), request.getHeader("User-Agent"));
	if (bestMatch == null) {
		response.setStatus(406);
		response.setContentType("text/plain");
		response.getOutputStream().println(
				"406 Not Acceptable: The requested data format is not supported. " +
				"Only HTML and RDF are available.");
		return;
	}
	
	response.setStatus(303);
	response.setContentType("text/plain");
	String location;
	if ("text/html".equals(bestMatch.getMediaType())) {
		location = server.pageURL(serviceStem, relativeResourceURI);
	} else {
		location = server.dataURL(serviceStem, relativeResourceURI);
	}
	response.addHeader("Location", location);
	response.getOutputStream().println(
			"303 See Other: For a description of this item, see " + location);
}
 

开发者ID:aitoralmeida,
项目名称:c4a_data_repository,
代码行数:51,
代码来源:ResourceServlet.java

示例4: doGet

点赞 2

import de.fuberlin.wiwiss.pubby.negotiation.ContentTypeNegotiator; //导入依赖的package包/类
public void doGet(HttpServletRequest request,
		HttpServletResponse response) throws IOException, ServletException {
	D2RRWServer server = D2RRWServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	String relativeResourceURI = request.getRequestURI().substring(
			request.getContextPath().length() + request.getServletPath().length());
	// Some servlet containers keep the leading slash, some don't
	if (!"".equals(relativeResourceURI) && "/".equals(relativeResourceURI.substring(0, 1))) {
		relativeResourceURI = relativeResourceURI.substring(1);
	}
	if (request.getQueryString() != null) {
		relativeResourceURI = relativeResourceURI + "?" + request.getQueryString();
	}
	
	/* Determine service stem, i.e. vocab/ in /[vocab/]resource */
	int servicePos;
	if (-1 == (servicePos = request.getServletPath().indexOf("/" + D2RRWServer.getResourceServiceName())))
			throw new ServletException("Expected to find service name /" + D2RRWServer.getResourceServiceName());
	String serviceStem = request.getServletPath().substring(1, servicePos + 1);

	response.addHeader("Vary", "Accept, User-Agent");
	ContentTypeNegotiator negotiator = PubbyNegotiator.getPubbyNegotiator();
	MediaRangeSpec bestMatch = negotiator.getBestMatch(
			request.getHeader("Accept"), request.getHeader("User-Agent"));
	if (bestMatch == null) {
		response.setStatus(406);
		response.setContentType("text/plain");
		response.getOutputStream().println(
				"406 Not Acceptable: The requested data format is not supported. " +
				"Only HTML and RDF are available.");
		return;
	}
	
	response.setStatus(303);
	response.setContentType("text/plain");
	String location;
	if ("text/html".equals(bestMatch.getMediaType())) {
		location = server.pageURL(serviceStem, relativeResourceURI);
	} else {
		location = server.dataURL(serviceStem, relativeResourceURI);
	}
	response.addHeader("Location", location);
	response.getOutputStream().println(
			"303 See Other: For a description of this item, see " + location);
}
 

开发者ID:vaibhavkhadilkar,
项目名称:D2RQ-Update,
代码行数:46,
代码来源:ResourceServlet.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)