All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dynamicextensionsalfresco.webscripts.arguments.FileFieldArgumentResolver Maven / Gradle / Ivy

Go to download

Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features

There is a newer version: 3.1.0
Show newest version
package com.github.dynamicextensionsalfresco.webscripts.arguments;

import java.lang.annotation.Annotation;

import com.github.dynamicextensionsalfresco.webscripts.AnnotationWebScriptRequest;
import com.github.dynamicextensionsalfresco.webscripts.WebScriptUtil;
import com.github.dynamicextensionsalfresco.webscripts.annotations.FileField;
import com.github.dynamicextensionsalfresco.webscripts.annotations.Header;

import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.extensions.webscripts.servlet.FormData.FormField;
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
import org.springframework.util.StringUtils;

/**
 * {@link ArgumentResolver} that maps String parameters annotated with {@link Header}.
 * 
 * @author Laurens Fridael
 * 
 */
public class FileFieldArgumentResolver implements ArgumentResolver {

	@Override
	public boolean supports(final Class argumentType, final Class annotationType) {
		return FormField.class.equals(argumentType) && FileField.class.equals(annotationType);
	}

	@Override
	public FormField resolveArgument(final Class argumentType, final FileField fileField, final String name,
			WebScriptRequest request, final WebScriptResponse response) {
		if (request instanceof AnnotationWebScriptRequest) {
			request = ((AnnotationWebScriptRequest) request).getWebScriptRequest();
		}
		FormField formField = null;
		final WebScriptServletRequest req = WebScriptUtil.extractWebScriptServletRequest(request);
		if (req != null) {
			String parameterName = fileField.value();
			if (StringUtils.hasText(parameterName) == false) {
				parameterName = name;
			}
			formField = req.getFileField(parameterName);
		}
		return formField;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy