Search in sources :

Example 6 with ScopeData

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);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ScopeData(jodd.madvoc.ScopeData)

Example 7 with ScopeData

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);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ScopeData(jodd.madvoc.ScopeData)

Example 8 with ScopeData

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);
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) MultipartRequestWrapper(jodd.servlet.upload.MultipartRequestWrapper) ScopeData(jodd.madvoc.ScopeData) FileUpload(jodd.upload.FileUpload)

Example 9 with ScopeData

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);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ScopeData(jodd.madvoc.ScopeData)

Example 10 with ScopeData

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);
                }
            }
        }
    }
}
Also used : Cookie(javax.servlet.http.Cookie) ScopeData(jodd.madvoc.ScopeData) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

ScopeData (jodd.madvoc.ScopeData)21 Enumeration (java.util.Enumeration)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ServletContext (javax.servlet.ServletContext)4 In (jodd.madvoc.meta.In)4 Out (jodd.madvoc.meta.Out)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 ScopeType (jodd.madvoc.ScopeType)2 ScopeDataResolver (jodd.madvoc.component.ScopeDataResolver)2 InOut (jodd.madvoc.meta.InOut)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 Cookie (javax.servlet.http.Cookie)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 PropertyDescriptor (jodd.introspector.PropertyDescriptor)1 ActionConfig (jodd.madvoc.ActionConfig)1 ActionConfigSet (jodd.madvoc.ActionConfigSet)1