Java Code Examples for org.springframework.web.util.WebUtils#CONTENT_TYPE_CHARSET_PREFIX

The following examples show how to use org.springframework.web.util.WebUtils#CONTENT_TYPE_CHARSET_PREFIX . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XsltView.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Configure the supplied {@link HttpServletResponse}.
 * <p>The default implementation of this method sets the
 * {@link HttpServletResponse#setContentType content type} and
 * {@link HttpServletResponse#setCharacterEncoding encoding}
 * from the "media-type" and "encoding" output properties
 * specified in the {@link Transformer}.
 * @param model merged output Map (never {@code null})
 * @param response current HTTP response
 * @param transformer the target transformer
 */
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
	String contentType = getContentType();
	String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
	String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
	if (StringUtils.hasText(mediaType)) {
		contentType = mediaType;
	}
	if (StringUtils.hasText(encoding)) {
		// Only apply encoding if content type is specified but does not contain charset clause already.
		if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
			contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
		}
	}
	response.setContentType(contentType);
}
 
Example 2
Source File: XsltView.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Configure the supplied {@link HttpServletResponse}.
 * <p>The default implementation of this method sets the
 * {@link HttpServletResponse#setContentType content type} and
 * {@link HttpServletResponse#setCharacterEncoding encoding}
 * from the "media-type" and "encoding" output properties
 * specified in the {@link Transformer}.
 * @param model merged output Map (never {@code null})
 * @param response current HTTP response
 * @param transformer the target transformer
 */
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
	String contentType = getContentType();
	String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
	String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
	if (StringUtils.hasText(mediaType)) {
		contentType = mediaType;
	}
	if (StringUtils.hasText(encoding)) {
		// Only apply encoding if content type is specified but does not contain charset clause already.
		if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
			contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
		}
	}
	response.setContentType(contentType);
}
 
Example 3
Source File: XsltView.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Configure the supplied {@link HttpServletResponse}.
 * <p>The default implementation of this method sets the
 * {@link HttpServletResponse#setContentType content type} and
 * {@link HttpServletResponse#setCharacterEncoding encoding}
 * from the "media-type" and "encoding" output properties
 * specified in the {@link Transformer}.
 * @param model merged output Map (never {@code null})
 * @param response current HTTP response
 * @param transformer the target transformer
 */
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
	String contentType = getContentType();
	String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
	String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
	if (StringUtils.hasText(mediaType)) {
		contentType = mediaType;
	}
	if (StringUtils.hasText(encoding)) {
		// Only apply encoding if content type is specified but does not contain charset clause already.
		if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
			contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
		}
	}
	response.setContentType(contentType);
}
 
Example 4
Source File: AbstractJasperReportsSingleFormatView.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We need to write text to the response Writer.
 * @param exporter the JasperReports exporter to use
 * @param populatedReport the populated {@code JasperPrint} to render
 * @param response the HTTP response the report should be rendered to
 * @throws Exception if rendering failed
 */
protected void renderReportUsingWriter(net.sf.jasperreports.engine.JRExporter exporter,
		JasperPrint populatedReport, HttpServletResponse response) throws Exception {

	// Copy the encoding configured for the report into the response.
	String contentType = getContentType();
	String encoding = (String) exporter.getParameter(net.sf.jasperreports.engine.JRExporterParameter.CHARACTER_ENCODING);
	if (encoding != null) {
		// Only apply encoding if content type is specified but does not contain charset clause already.
		if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
			contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
		}
	}
	response.setContentType(contentType);

	// Render report into HttpServletResponse's Writer.
	JasperReportsUtils.render(exporter, populatedReport, response.getWriter());
}
 
Example 5
Source File: XsltView.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Configure the supplied {@link HttpServletResponse}.
 * <p>The default implementation of this method sets the
 * {@link HttpServletResponse#setContentType content type} and
 * {@link HttpServletResponse#setCharacterEncoding encoding}
 * from the "media-type" and "encoding" output properties
 * specified in the {@link Transformer}.
 * @param model merged output Map (never {@code null})
 * @param response current HTTP response
 * @param transformer the target transformer
 */
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
	String contentType = getContentType();
	String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
	String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
	if (StringUtils.hasText(mediaType)) {
		contentType = mediaType;
	}
	if (StringUtils.hasText(encoding)) {
		// Only apply encoding if content type is specified but does not contain charset clause already.
		if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
			contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
		}
	}
	response.setContentType(contentType);
}
 
Example 6
Source File: AbstractJasperReportsSingleFormatView.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * We need to write text to the response Writer.
 * @param exporter the JasperReports exporter to use
 * @param populatedReport the populated {@code JasperPrint} to render
 * @param response the HTTP response the report should be rendered to
 * @throws Exception if rendering failed
 */
protected void renderReportUsingWriter(net.sf.jasperreports.engine.JRExporter exporter,
		JasperPrint populatedReport, HttpServletResponse response) throws Exception {

	// Copy the encoding configured for the report into the response.
	String contentType = getContentType();
	String encoding = (String) exporter.getParameter(net.sf.jasperreports.engine.JRExporterParameter.CHARACTER_ENCODING);
	if (encoding != null) {
		// Only apply encoding if content type is specified but does not contain charset clause already.
		if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
			contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
		}
	}
	response.setContentType(contentType);

	// Render report into HttpServletResponse's Writer.
	JasperReportsUtils.render(exporter, populatedReport, response.getWriter());
}