use of jodd.madvoc.ScopeData in project jodd by oblac.
the class ApplicationScopeInjector method injectContext.
public void injectContext(Target target, ScopeData[] scopeData, ServletContext servletContext) {
ScopeData.In[] injectData = lookupInData(scopeData);
if (injectData == null) {
return;
}
Enumeration attributeNames = servletContext.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String attrName = (String) attributeNames.nextElement();
for (ScopeData.In in : injectData) {
String name = getMatchedPropertyName(in, attrName);
if (name != null) {
Object attrValue = servletContext.getAttribute(attrName);
setTargetProperty(target, name, attrValue);
}
}
}
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class RequestScopeInjector method outjectAfterMove.
protected void outjectAfterMove(ActionRequest sourceRequest) {
ScopeData[] outjectData = lookupScopeData(sourceRequest);
if (outjectData == null) {
return;
}
Target[] targets = sourceRequest.getTargets();
HttpServletRequest servletRequest = sourceRequest.getHttpServletRequest();
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (outjectData[i] == null) {
continue;
}
ScopeData.Out[] scopes = outjectData[i].out;
if (scopes == null) {
continue;
}
for (ScopeData.Out out : scopes) {
Object value = getTargetProperty(target, out);
servletRequest.setAttribute(out.name, value);
}
}
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class RequestScopeInjector method injectUploadedFiles.
/**
* Inject uploaded files from multipart request parameters.
*/
protected void injectUploadedFiles(Target[] targets, ScopeData[] injectData, HttpServletRequest servletRequest) {
if (!(servletRequest instanceof MultipartRequestWrapper)) {
return;
}
MultipartRequestWrapper multipartRequest = (MultipartRequestWrapper) servletRequest;
if (!multipartRequest.isMultipart()) {
return;
}
Enumeration paramNames = multipartRequest.getFileParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if (servletRequest.getAttribute(paramName) != null) {
continue;
}
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (injectData[i] == null) {
continue;
}
ScopeData.In[] scopes = injectData[i].in;
if (scopes == null) {
continue;
}
for (ScopeData.In in : scopes) {
String name = getMatchedPropertyName(in, paramName);
if (name != null) {
FileUpload[] paramValues = multipartRequest.getFiles(paramName);
if (ignoreInvalidUploadFiles) {
for (int j = 0; j < paramValues.length; j++) {
FileUpload paramValue = paramValues[j];
if ((!paramValue.isValid()) || (!paramValue.isUploaded())) {
paramValues[j] = null;
}
}
}
Object value = (paramValues.length == 1 ? paramValues[0] : paramValues);
setTargetProperty(target, name, value);
}
}
}
}
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class RequestScopeInjector method outject.
// ---------------------------------------------------------------- outject
public void outject(ActionRequest actionRequest) {
ScopeData[] outjectData = lookupScopeData(actionRequest);
if (outjectData == null) {
return;
}
Target[] targets = actionRequest.getTargets();
HttpServletRequest servletRequest = actionRequest.getHttpServletRequest();
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (outjectData[i] == null) {
continue;
}
ScopeData.Out[] scopes = outjectData[i].out;
if (scopes == null) {
continue;
}
for (ScopeData.Out out : scopes) {
Object value = getTargetProperty(target, out);
servletRequest.setAttribute(out.name, value);
}
}
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class ServletContextScopeInjector method outject.
public void outject(ActionRequest actionRequest) {
ScopeData[] outjectData = lookupScopeData(actionRequest);
if (outjectData == null) {
return;
}
Target[] targets = actionRequest.getTargets();
HttpServletResponse servletResponse = actionRequest.getHttpServletResponse();
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (outjectData[i] == null) {
continue;
}
ScopeData.Out[] scopes = outjectData[i].out;
if (scopes == null) {
continue;
}
for (ScopeData.Out out : scopes) {
if (out.name.startsWith(COOKIE_NAME)) {
Cookie cookie = (Cookie) getTargetProperty(target, out);
if (cookie != null) {
servletResponse.addCookie(cookie);
}
}
}
}
}
Aggregations