use of grails.web.mime.MimeType in project grails-core by grails.
the class DataBindingUtils method createDataBindingSource.
public static DataBindingSource createDataBindingSource(GrailsApplication grailsApplication, Class bindingTargetType, Object bindingSource) {
final DataBindingSourceRegistry registry = getDataBindingSourceRegistry(grailsApplication);
final MimeType mimeType = getMimeType(grailsApplication, bindingSource);
return registry.createDataBindingSource(mimeType, bindingTargetType, bindingSource);
}
use of grails.web.mime.MimeType in project grails-core by grails.
the class MimeTypesConfiguration method mimeTypes.
@Bean("mimeTypes")
@Primary
protected MimeType[] mimeTypes() {
final Config config = grailsApplication.getConfig();
final Map<CharSequence, Object> mimeConfig = getMimeConfig(config);
MimeType[] mimeTypes;
if (mimeConfig == null || mimeConfig.isEmpty()) {
mimeTypes = MimeType.createDefaults();
return mimeTypes;
} else {
List<MimeType> mimes = new ArrayList<>();
for (Map.Entry<CharSequence, Object> entry : mimeConfig.entrySet()) {
final String key = entry.getKey().toString();
final Object v = entry.getValue();
if (v instanceof List) {
List list = (List) v;
for (Object i : list) {
mimes.add(new MimeType(i.toString(), key));
}
} else {
mimes.add(new MimeType(v.toString(), key));
}
}
final List<MimeTypeProvider> mimeTypeProviders = this.mimeTypeProviders;
processProviders(mimes, mimeTypeProviders);
final Map<String, MimeTypeProvider> childTypes = applicationContext.getBeansOfType(MimeTypeProvider.class);
processProviders(mimes, childTypes.values());
mimeTypes = mimes.toArray(new MimeType[0]);
return mimeTypes;
}
}
use of grails.web.mime.MimeType in project grails-core by grails.
the class GrailsConventionGroovyPageLocator method lookupRequestFormat.
protected String lookupRequestFormat() {
if (mimeTypeResolver != null) {
MimeType mimeType = mimeTypeResolver.resolveResponseMimeType();
if (mimeType != null) {
return mimeType.getExtension();
}
} else {
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
if (webRequest != null) {
HttpServletRequest request = webRequest.getCurrentRequest();
Object format = request.getAttribute(GrailsApplicationAttributes.RESPONSE_FORMAT);
return format == null ? null : format.toString();
}
}
return null;
}
use of grails.web.mime.MimeType in project grails-core by grails.
the class DataBindingUtils method createCollectionDataBindingSource.
public static CollectionDataBindingSource createCollectionDataBindingSource(GrailsApplication grailsApplication, Class bindingTargetType, Object bindingSource) {
final DataBindingSourceRegistry registry = getDataBindingSourceRegistry(grailsApplication);
final MimeType mimeType = getMimeType(grailsApplication, bindingSource);
return registry.createCollectionDataBindingSource(mimeType, bindingTargetType, bindingSource);
}
use of grails.web.mime.MimeType in project grails-core by grails.
the class WebUtils method getFormatFromURI.
/**
* Obtains the format from the URI. The format is the string following the . file extension in the last token of the URI.
* If nothing comes after the ".", this method assumes that there is no format and returns <code>null</code>.
*
* @param uri The URI
* @param mimeTypes The configured mime types
* @return The format or null if none
*/
public static String getFormatFromURI(String uri, MimeType[] mimeTypes) {
if (uri.endsWith("/")) {
return null;
}
int idx = uri.lastIndexOf('/');
if (idx > -1) {
String lastToken = uri.substring(idx + 1, uri.length());
idx = lastToken.lastIndexOf('.');
if (idx > -1 && idx != lastToken.length() - 1) {
String extension = lastToken.substring(idx + 1, lastToken.length());
if (mimeTypes != null) {
for (MimeType mimeType : mimeTypes) {
if (mimeType.getExtension().equals(extension))
return extension;
}
}
}
}
return null;
}
Aggregations