本文整理汇总了Java中net.sourceforge.stripes.action.ActionBeanContext类的典型用法代码示例。如果您正苦于以下问题:Java ActionBeanContext类的具体用法?Java ActionBeanContext怎么用?Java ActionBeanContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActionBeanContext类属于net.sourceforge.stripes.action包,在下文中一共展示了ActionBeanContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasErrors
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/** Indicates if validation errors exist for the given field of the given {@link ActionBean}. */
public static boolean hasErrors(ActionBean actionBean, String field) {
if (actionBean == null || field == null)
return false;
ActionBeanContext context = actionBean.getContext();
if (context == null)
return false;
ValidationErrors errors = context.getValidationErrors();
if (errors == null || errors.isEmpty())
return false;
List<ValidationError> fieldErrors = errors.get(field);
return fieldErrors != null && fieldErrors.size() > 0;
}
示例2: logValidationErrors
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/** Log validation errors at DEBUG to help during development. */
public static final void logValidationErrors(ActionBeanContext context) {
StringBuilder buf = new StringBuilder("The following validation errors need to be fixed:");
for (List<ValidationError> list : context.getValidationErrors().values()) {
for (ValidationError error : list) {
String fieldName = error.getFieldName();
if (ValidationErrors.GLOBAL_ERROR.equals(fieldName))
fieldName = "GLOBAL";
String message;
try {
message = error.getMessage(Locale.getDefault());
}
catch (MissingResourceException e) {
message = "(missing resource)";
}
buf.append("\n -> [").append(fieldName).append("] ").append(message);
}
}
log.debug(buf);
}
示例3: getActionBean
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* <p>Overridden to trap the exception that is thrown when a URL cannot be mapped to an
* ActionBean and then attempt to construct a dummy ActionBean that will forward the
* user to an appropriate view. In an exception is caught then the method
* {@link #handleActionBeanNotFound(ActionBeanContext, String)} is invoked to handle
* the exception.</p>
*
* @param context the ActionBeanContext of the current request
* @param urlBinding the urlBinding determined for the current request
* @return an ActionBean if there is an appropriate way to handle the request
* @throws StripesServletException if no ActionBean or alternate strategy can be found
*/
@Override
public ActionBean getActionBean(ActionBeanContext context,
String urlBinding) throws StripesServletException {
try {
return super.getActionBean(context, urlBinding);
}
catch (StripesServletException sse) {
ActionBean bean = handleActionBeanNotFound(context, urlBinding);
if (bean != null) {
setActionBeanContext(bean, context);
assertGetContextWorks(bean);
return bean;
}
else {
throw sse;
}
}
}
示例4: getEventNameFromRequestParams
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* Loops through the set of known events for the ActionBean to see if the event
* names are present as parameter names in the request. Returns the first event
* name found in the request, or null if none is found.
*
* @param bean the ActionBean type bound to the request
* @param context the ActionBeanContext for the current request
* @return String the name of the event submitted, or null if none can be found
*/
@SuppressWarnings("unchecked")
protected String getEventNameFromRequestParams(Class<? extends ActionBean> bean,
ActionBeanContext context) {
List<String> eventParams = new ArrayList<String>();
Map<String,String[]> parameterMap = context.getRequest().getParameterMap();
for (String event : this.eventMappings.get(bean).keySet()) {
if (parameterMap.containsKey(event) || parameterMap.containsKey(event + ".x")) {
eventParams.add(event);
}
}
if (eventParams.size() == 0) {
return null;
}
else if (eventParams.size() == 1) {
return eventParams.get(0);
}
else {
throw new StripesRuntimeException("Multiple event parameters " + eventParams
+ " are present in this request. Only one event parameter may be specified "
+ "per request. Otherwise, Stripes would be unable to determine which event "
+ "to execute.");
}
}
示例5: getEventNameFromPath
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* Looks to see if there is extra path information beyond simply the url binding of the
* bean. If it does and the next /-separated part of the path matches one of the known
* event names for the bean, that event name will be returned, otherwise null.
*
* @param bean the ActionBean type bound to the request
* @param context the ActionBeanContect for the current request
* @return String the name of the event submitted, or null if none can be found
*/
protected String getEventNameFromPath(Class<? extends ActionBean> bean,
ActionBeanContext context) {
Map<String,Method> mappings = this.eventMappings.get(bean);
String path = HttpUtil.getRequestedPath(context.getRequest());
UrlBinding prototype = getUrlBindingFactory().getBindingPrototype(path);
String binding = prototype == null ? null : prototype.getPath();
if (binding != null && path.length() != binding.length()) {
String extra = path.substring(binding.length() + 1);
int index = extra.indexOf("/");
String event = extra.substring(0, (index != -1) ? index : extra.length());
if (mappings.containsKey(event)) {
return event;
}
}
return null;
}
示例6: bindMissingValuesAsNull
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* Uses a hidden field to determine what (if any) fields were present in the form but did not get
* submitted to the server. For each such field the value is "softly" set to null on the
* ActionBean. This is not uncommon for checkboxes, and also for multi-selects.
*
* @param bean the ActionBean being bound to
* @param context the current ActionBeanContext
*/
@SuppressWarnings("unchecked")
protected void bindMissingValuesAsNull(ActionBean bean, ActionBeanContext context) {
Set<String> parametersSubmitted = context.getRequest().getParameterMap().keySet();
for (String name : getFieldsPresentInfo(bean)) {
if (!parametersSubmitted.contains(name)) {
try {
BeanUtil.setPropertyToNull(name, bean);
}
catch (Exception e) {
handlePropertyBindingError(bean, new ParameterName(name), null, e, context
.getValidationErrors());
}
}
}
}
示例7: getFieldsPresentInfo
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* In a lot of cases (and specifically during wizards) the Stripes form field writes out a
* hidden field containing a set of field names. This is encrypted to stop the user from
* monkeying with it. This method retrieves the list of field names, decrypts it and splits it
* out into a Collection of field names.
*
* @param bean the current ActionBean
* @return a non-null (though possibly empty) list of field names
*/
protected Collection<String> getFieldsPresentInfo(ActionBean bean) {
ActionBeanContext ctx = bean.getContext();
String fieldsPresent = ctx.getRequest().getParameter(StripesConstants.URL_KEY_FIELDS_PRESENT);
Wizard wizard = bean.getClass().getAnnotation(Wizard.class);
boolean isWizard = wizard != null;
if (fieldsPresent == null || "".equals(fieldsPresent)) {
if (isWizard && !CollectionUtil.contains(wizard.startEvents(), ctx.getEventName())) {
throw new StripesRuntimeException(
"Submission of a wizard form in Stripes absolutely requires that "
+ "the hidden field Stripes writes containing the names of the fields "
+ "present on the form is present and encrypted (as Stripes write it). "
+ "This is necessary to prevent a user from spoofing the system and "
+ "getting around any security/data checks.");
}
else {
return Collections.emptySet();
}
}
else {
fieldsPresent = CryptoUtil.decrypt(fieldsPresent);
return HtmlUtil.splitValues(fieldsPresent);
}
}
示例8: getEventNameFromPath
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* Looks to see if there is extra path information beyond simply the url
* binding of the bean. If it does and the next /-separated part of the path
* matches one of the known event names for the bean, that event name will
* be returned, otherwise null.
*
* @param bean
* the ActionBean type bound to the request
* @param context
* the ActionBeanContect for the current request
* @return String the name of the event submitted, or null if none can be
* found
*/
protected String getEventNameFromPath(Class<? extends ActionBean> bean, ActionBeanContext context) {
Map<String, Method> mappings = eventMappings.get(getGuicelessActionBean(bean));
String path = HttpUtil.getRequestedPath(context.getRequest());
UrlBinding prototype = getUrlBindingFactory().getBindingPrototype(path);
String binding = prototype == null ? null : prototype.getPath();
if (binding != null && path.length() != binding.length()) {
String extra = path.substring(binding.length() + 1);
int index = extra.indexOf("/");
String event = extra.substring(0, (index != -1) ? index : extra.length());
if (mappings.containsKey(event)) {
return event;
}
}
return null;
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:31,代码来源:AnnotatedClassActionResolver.java
示例9: makeNewActionBean
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
@Override
protected ActionBean makeNewActionBean(
Class<? extends ActionBean> type, ActionBeanContext context) throws Exception {
Dispatch dispatch = DispatcherUtil.getDispatch(context.getRequest());
if(dispatch != null) {
PageInstance pageInstance = dispatch.getLastPageInstance();
if(type.equals(pageInstance.getActionClass())) {
if(pageInstance.getActionBean() != null) {
return pageInstance.getActionBean();
} else {
assert false;
if(DispatcherLogic.isValidActionClass(type)) {
ActionBean actionBean = super.makeNewActionBean(type, context);
pageInstance.setActionBean((PageAction) actionBean);
return actionBean;
} else {
throw new Exception("Invalid action bean type for dispatch: " + type); //TODO
}
}
}
}
return super.makeNewActionBean(type, context);
}
示例10: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
ActionBeanContext actionContext = context.getActionBeanContext();
ActionBean actionBean = context.getActionBean();
Method handler = context.getHandler();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
Dispatch dispatch = DispatcherUtil.getDispatch(request);
if(SecurityLogic.isAllowed(request, dispatch, actionBean, handler)) {
logger.debug("Security check passed.");
return context.proceed();
} else {
return new ForbiddenAccessResolution();
}
}
示例11: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
ActionBeanContext actionContext = context.getActionBeanContext();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
if (request.getDispatcherType() == DispatcherType.REQUEST) {
logger.debug("Starting page response timer");
StopWatch stopWatch = new StopWatch();
// There is no need to stop this timer.
stopWatch.start();
request.setAttribute(RequestAttributes.STOP_WATCH, stopWatch);
}
Resolution resolution = dispatch(actionContext);
return resolution != null ? resolution : context.proceed();
}
示例12: makeNewActionBean
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
@Override
protected ActionBean makeNewActionBean(
Class<? extends ActionBean> type, ActionBeanContext context) throws Exception {
Dispatch dispatch = DispatcherUtil.getDispatch(context.getRequest());
if(dispatch != null) {
PageInstance pageInstance = dispatch.getLastPageInstance();
if(type.equals(pageInstance.getActionClass())) {
if(pageInstance.getActionBean() != null) {
return pageInstance.getActionBean();
} else {
if(DispatcherLogic.isValidActionClass(type)) {
ActionBean actionBean = super.makeNewActionBean(type, context);
pageInstance.setActionBean((PageAction) actionBean);
return actionBean;
} else {
throw new Exception("Invalid action bean type for dispatch: " + type); //TODO
}
}
}
}
return super.makeNewActionBean(type, context);
}
示例13: handleValidationErrors
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* Responsible for checking to see if validation errors exist and if so for handling
* them appropriately. This includes ensuring that the error objects have all information
* necessary to render themselves appropriately and invoking any error handling code.
*
* @param ctx the ExecutionContext being used to process the current request
* @return a Resolution if the error handling code determines that some kind of resolution
* should be processed in favor of continuing on to handler invocation
*/
public static Resolution handleValidationErrors(ExecutionContext ctx) throws Exception {
DontValidate annotation = ctx.getHandler().getAnnotation(DontValidate.class);
boolean doValidate = annotation == null || !annotation.ignoreBindingErrors();
// If we have errors, add the action path to them
fillInValidationErrors(ctx);
Resolution resolution = null;
if (doValidate) {
ActionBean bean = ctx.getActionBean();
ActionBeanContext context = ctx.getActionBeanContext();
ValidationErrors errors = context.getValidationErrors();
// Now if we have errors and the bean wants to handle them...
if (errors.size() > 0 && bean instanceof ValidationErrorHandler) {
resolution = ((ValidationErrorHandler) bean).handleValidationErrors(errors);
fillInValidationErrors(ctx);
}
// If there are still errors see if we need to lookup the resolution
if (errors.size() > 0 && resolution == null) {
logValidationErrors(context);
resolution = context.getSourcePageResolution();
}
}
return resolution;
}
示例14: fillInValidationErrors
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* Makes sure that validation errors have all the necessary information to render
* themselves properly, including the UrlBinding of the action bean and the field
* value if it hasn't already been set.
*
* @param ctx the ExecutionContext being used to process the current request
*/
public static void fillInValidationErrors(ExecutionContext ctx) {
ActionBeanContext context = ctx.getActionBeanContext();
ValidationErrors errors = context.getValidationErrors();
if (errors.size() > 0) {
String formAction = StripesFilter.getConfiguration().getActionResolver()
.getUrlBinding(ctx.getActionBean().getClass());
HttpServletRequest request = ctx.getActionBeanContext().getRequest();
/** Since we don't pass form action down the stack, we add it to the errors here. */
for (Map.Entry<String, List<ValidationError>> entry : errors.entrySet()) {
String parameterName = entry.getKey();
List<ValidationError> listOfErrors = entry.getValue();
for (ValidationError error : listOfErrors) {
// Make sure we process each error only once, no matter how often we're called
if (error.getActionPath() == null) {
error.setActionPath(formAction);
error.setBeanclass(ctx.getActionBean().getClass());
// If the value isn't set, set it, otherwise encode the one that's there
if (error.getFieldValue() == null) {
error.setFieldValue(HtmlUtil.encode(request.getParameter(parameterName)));
}
else {
error.setFieldValue(HtmlUtil.encode(error.getFieldValue()));
}
}
}
}
}
}
示例15: completeRequest
import net.sourceforge.stripes.action.ActionBeanContext; //导入依赖的package包/类
/**
* <p>Used by the StripesFilter to notify the flash scope that the request for which
* it is used has been completed. The FlashScope uses this notification to start a
* timer, and also to null out it's reference to the request so that it can be
* garbage collected.</p>
*
* <p>The timer is used to determine if a flash scope has been orphaned (i.e. the subsequent
* request was not made) after a period of time, so that it can be removed from session.</p>
*/
public void completeRequest() {
// Clean up any old-age flash scopes
Map<Integer, FlashScope> scopes = getContainer(request, false);
if (scopes != null && !scopes.isEmpty()) {
Iterator<FlashScope> iterator = scopes.values().iterator();
while (iterator.hasNext()) {
if (iterator.next().isExpired()) {
iterator.remove();
}
}
}
// Replace the request and response objects for the request cycle that is ending
// with objects that are safe to use on the ensuing request.
HttpServletRequest flashRequest = FlashRequest.replaceRequest(request);
HttpServletResponse flashResponse = (HttpServletResponse) Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class<?>[] { HttpServletResponse.class },
new FlashResponseInvocationHandler());
for (Object o : this.values()) {
if (o instanceof ActionBean) {
ActionBeanContext context = ((ActionBean) o).getContext();
if (context != null) {
context.setRequest(flashRequest);
context.setResponse(flashResponse);
}
}
}
// start timer, clear request
this.startTime = System.currentTimeMillis();
this.request = null;
this.semaphore.release();
}