/** * Writes value to this target. Depending on a flag, writing the value can be * completely silent, when no exception is thrown and with top performances. * Otherwise, an exception is thrown on a failure. */ public void writeValue(final InjectionPoint injectionPoint, final Object propertyValue, final boolean silent) { writeValue(injectionPoint.targetName(), propertyValue, silent); } public void writeValue(final String name, final Object propertyValue, final boolean silent) {
/** * Injects request attributes. */ protected void injectAttributes(final HttpServletRequest servletRequest, final Targets targets) { final Enumeration<String> attributeNames = servletRequest.getAttributeNames(); while (attributeNames.hasMoreElements()) { final String attrName = attributeNames.nextElement(); targets.forEachTargetAndIn(this, (target, in) -> { final String name = in.matchedName(attrName); if (name != null) { final Object attrValue = servletRequest.getAttribute(attrName); target.writeValue(name, attrValue, true); } }); } }
@Override public void inject(final ServletContext servletContext, final Targets targets) { instancesInjector.inject(servletContext, targets); final Enumeration<String> attributeNames = servletContext.getAttributeNames(); while (attributeNames.hasMoreElements()) { final String attrName = attributeNames.nextElement(); targets.forEachTargetAndIn(this, (target, in) -> { final String name = in.matchedName(attrName); if (name != null) { final Object attrValue = servletContext.getAttribute(attrName); target.writeValue(name, attrValue, true); } }); } }
public void inject(final ServletContext servletContext, final Targets targets) { targets.forEachTargetAndIn(madvocScope, (target, in) -> { final Class inType = in.type(); Object value = null; if (inType == ServletContext.class) { value = servletContext; } if (value != null) { target.writeValue(in, value, true); } }); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); final HttpSession session = servletRequest.getSession(); final Enumeration<String> attributeNames = session.getAttributeNames(); while (attributeNames.hasMoreElements()) { final String attrName = attributeNames.nextElement(); targets.forEachTargetAndIn(this, (target, in) -> { final String name = in.matchedName(attrName); if (name != null) { final Object attrValue = session.getAttribute(attrName); target.writeValue(name, attrValue, true); } }); } }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); targets.forEachTargetAndIn(this, (target, in) -> { final Enumeration<String> headerNames = servletRequest.getHeaders(in.name()); if (headerNames != null) { final List<String> allValues = new ArrayList<>(); while (headerNames.hasMoreElements()) { allValues.add(headerNames.nextElement()); } final Object value; if (allValues.size() == 1) { value = allValues.get(0); } else { value = allValues; } target.writeValue(in, value, true); } }); }
@Override public void inject(final Targets targets) { targets.forEachTargetAndIn(this, (target, in) -> { final Object value = madpc.getBean(in.name()); if (value != null) { target.writeValue(in, value, false); } }); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final String body = actionRequest.readRequestBody(); if (StringUtil.isEmpty(body)) { return; } targets.forEachTargetAndIn(this, (target, in) -> target.writeValue(in, body, true)); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final String body = actionRequest.readRequestBody(); if (StringUtil.isEmpty(body)) { return; } targets.forEachTargetAndIn(this, (target, in) -> { if (in.type() == String.class) { target.writeValue(in, body, true); } else { final Object value = parseRequestBody(body, in.type()); target.writeValue(in, value, true); } }); }
target.writeValue(name, value, true);
@Override public void inject(final Targets targets) { targets.forEachTarget(target -> { final Class targetType = target.resolveType(); final String baseName = baseNameOf(targetType); final ParamManager madvocPetiteParamManager = madpc.paramManager(); final String[] params = madvocPetiteParamManager.filterParametersForBeanName(baseName, true); for (final String param : params) { final Object value = madvocPetiteParamManager.get(param); final String propertyName = param.substring(baseName.length() + 1); target.writeValue(propertyName, value, false); } }); }
public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); final HttpServletResponse servletResponse = actionRequest.getHttpServletResponse(); targets.forEachTargetAndIn(madvocScope, (target, in) -> { final Class inType = in.type(); Object value = null; if (inType == HttpServletRequest.class) { value = servletRequest; } else if (inType == ServletRequest.class) { value = servletRequest; } else if (inType == HttpServletResponse.class) { value = servletResponse; } else if (inType == ServletResponse.class) { value = servletResponse; } else if (inType == HttpSession.class) { value = servletRequest.getSession(); } else if (inType == ServletContext.class) { value = servletRequest.getServletContext(); } else if (inType == AsyncContext.class) { value = servletRequest.getAsyncContext(); } else if (inType == ActionRequest.class) { value = actionRequest; } if (value != null) { target.writeValue(in, value, true); } }); }
target.writeValue(name, value, true);
private void injectMacros(final String actionPath, final PathMacros pathMacros, final Targets targets) { final String[] names = pathMacros.names(); final String[] values = pathMacros.extract(actionPath); for (int ndx = 0; ndx < values.length; ndx++) { final String value = values[ndx]; if (StringUtil.isEmpty(value)) { continue; } final String macroName = names[ndx]; targets.forEachTargetAndIn(madvocScope, (target, in) -> { final String name = in.matchedName(macroName); if (name != null) { target.writeValue(name, value, true); } }); } }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); targets.forEachTargetAndIn(this, (target, in) -> { Object value = null; if (in.type() == Cookie.class) { // get single cookie final String cookieName = StringUtil.uncapitalize(in.name()); value = ServletUtil.getCookie(servletRequest, cookieName); } else if (in.type().isArray()) { if (in.type().getComponentType().equals(Cookie.class)) { if (StringUtil.isEmpty(in.name())) { // get all cookies value = servletRequest.getCookies(); } else { // get all cookies by name value = ServletUtil.getAllCookies(servletRequest, in.name()); } } } if (value != null) { target.writeValue(in, value, true); } }); }