public static TemplateMode computeTemplateModeForRequestPath(final String requestPath) { final String fileExtension = computeFileExtensionFromRequestPath(requestPath); if (fileExtension == null) { return null; } final String mimeType = MIME_TYPE_BY_FILE_EXTENSION.get(fileExtension); if (mimeType == null) { return null; } return TEMPLATE_MODE_BY_MIME_TYPE.get(mimeType); }
public static boolean hasRecognizedFileExtension(final String templateName) { final String fileExtension = computeFileExtensionFromTemplateName(templateName); if (fileExtension == null) { return false; } return MIME_TYPE_BY_FILE_EXTENSION.containsKey(fileExtension); }
public static boolean isContentTypeHTML(final String contentType) { return isContentType(contentType, MIME_TYPES_HTML[0]); }
public static String computeViewContentType( final HttpServletRequest request, final String defaultContentType, final Charset defaultCharset) { if (request == null) { throw new IllegalArgumentException("Request cannot be null"); } // We will apply the default charset here because, after all, we are in an HTTP environment, and // the way charset is specified in HTTP is as a parameter in the same Content-Type HTTP header. final String combinedContentType = ContentTypeUtils.combineContentTypeAndCharset(defaultContentType, defaultCharset); // Maybe there is no value for 'defaultValue', but anyway we might want to preserve the charset // from the defaultContentType into the viewName-computed one final Charset combinedCharset = ContentTypeUtils.computeCharsetFromContentType(combinedContentType); // If the request path offers clues on the content type that would be more appropriate (because it // ends in ".html", ".xml", ".js", etc.), just use it final String requestPathContentType = ContentTypeUtils.computeContentTypeForRequestPath(request.getRequestURI(), combinedCharset); if (requestPathContentType != null) { return requestPathContentType; } // No way to determine a better/more specific content-type, so just return the (adequately combined) defaults return combinedContentType; }
ContentTypeUtils.computeTemplateModeForContentType(this.outputContentType); this.outputSSE = ContentTypeUtils.isContentTypeSSE(this.outputContentType);
hasSuffix && (forceSuffix || !ContentTypeUtils.hasRecognizedFileExtension(unaliasedName));
ContentTypeUtils.computeTemplateModeForTemplateName(templateResourceName); if (autoResolvedTemplateMode != null) { return autoResolvedTemplateMode;
public static String computeViewContentType( final HttpServletRequest request, final String defaultContentType, final Charset defaultCharset) { if (request == null) { throw new IllegalArgumentException("Request cannot be null"); } // We will apply the default charset here because, after all, we are in an HTTP environment, and // the way charset is specified in HTTP is as a parameter in the same Content-Type HTTP header. final String combinedContentType = ContentTypeUtils.combineContentTypeAndCharset(defaultContentType, defaultCharset); // Maybe there is no value for 'defaultValue', but anyway we might want to preserve the charset // from the defaultContentType into the viewName-computed one final Charset combinedCharset = ContentTypeUtils.computeCharsetFromContentType(combinedContentType); // If the request path offers clues on the content type that would be more appropriate (because it // ends in ".html", ".xml", ".js", etc.), just use it final String requestPathContentType = ContentTypeUtils.computeContentTypeForRequestPath(request.getRequestURI(), combinedCharset); if (requestPathContentType != null) { return requestPathContentType; } // No way to determine a better/more specific content-type, so just return the (adequately combined) defaults return combinedContentType; }
return negotiatedMediaType.toString(); } else { return ContentTypeUtils.combineContentTypeAndCharset(negotiatedMediaType.toString(), defaultCharset); ContentTypeUtils.combineContentTypeAndCharset(defaultContentType, defaultCharset); ContentTypeUtils.computeCharsetFromContentType(combinedContentType); ContentTypeUtils.computeContentTypeForRequestPath(request.getRequestURI(), combinedCharset); if (requestPathContentType != null) { return requestPathContentType;
public static boolean isContentTypeSSE(final String contentType) { return isContentType(contentType, MIME_TYPES_SSE[0]); }
public static TemplateMode computeTemplateModeForTemplateName(final String templateName) { final String fileExtension = computeFileExtensionFromTemplateName(templateName); if (fileExtension == null) { return null; } final String mimeType = MIME_TYPE_BY_FILE_EXTENSION.get(fileExtension); if (mimeType == null) { return null; } return TEMPLATE_MODE_BY_MIME_TYPE.get(mimeType); }
public static String computeContentTypeForRequestPath(final String requestPath, final Charset charset) { final String fileExtension = computeFileExtensionFromRequestPath(requestPath); if (fileExtension == null) { return null; } final String mimeType = MIME_TYPE_BY_FILE_EXTENSION.get(fileExtension); if (mimeType == null) { return null; } final ContentType contentType = ContentType.parseContentType(mimeType); if (contentType == null) { return null; } if (charset != null) { contentType.setCharset(charset); } return contentType.toString(); }
return negotiatedMediaType.toString(); } else { return ContentTypeUtils.combineContentTypeAndCharset(negotiatedMediaType.toString(), defaultCharset); ContentTypeUtils.combineContentTypeAndCharset(defaultContentType, defaultCharset); ContentTypeUtils.computeCharsetFromContentType(combinedContentType); ContentTypeUtils.computeContentTypeForRequestPath(request.getRequestURI(), combinedCharset); if (requestPathContentType != null) { return requestPathContentType;
public static boolean isContentTypeRSS(final String contentType) { return isContentType(contentType, MIME_TYPES_RSS[0]); }
public static String computeContentTypeForTemplateName(final String templateName, final Charset charset) { final String fileExtension = computeFileExtensionFromTemplateName(templateName); if (fileExtension == null) { return null; } final String mimeType = MIME_TYPE_BY_FILE_EXTENSION.get(fileExtension); if (mimeType == null) { return null; } final ContentType contentType = ContentType.parseContentType(mimeType); if (contentType == null) { return null; } if (charset != null) { contentType.setCharset(charset); } return contentType.toString(); }
return negotiatedMediaType.toString(); } else { return ContentTypeUtils.combineContentTypeAndCharset(negotiatedMediaType.toString(), defaultCharset); ContentTypeUtils.combineContentTypeAndCharset(defaultContentType, defaultCharset); ContentTypeUtils.computeCharsetFromContentType(combinedContentType); ContentTypeUtils.computeContentTypeForRequestPath(request.getRequestURI(), combinedCharset); if (requestPathContentType != null) { return requestPathContentType;
public static boolean isContentTypeAtom(final String contentType) { return isContentType(contentType, MIME_TYPES_ATOM[0]); }
public static boolean isContentTypeJSON(final String contentType) { return isContentType(contentType, MIME_TYPES_JSON[0]); }
public static boolean isContentTypeCSS(final String contentType) { return isContentType(contentType, MIME_TYPES_CSS[0]); }
public static boolean isContentTypeText(final String contentType) { return isContentType(contentType, MIME_TYPES_TEXT[0]); }