本文整理汇总了Java中net.sourceforge.stripes.controller.LifecycleStage类的典型用法代码示例。如果您正苦于以下问题:Java LifecycleStage类的具体用法?Java LifecycleStage怎么用?Java LifecycleStage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LifecycleStage类属于net.sourceforge.stripes.controller包,在下文中一共展示了LifecycleStage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initInterceptors
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
/**
* Splits a comma-separated list of class names and maps each {@link LifecycleStage} to the
* interceptors in the list that intercept it. Also automatically finds Interceptors in
* packages listed in {@link BootstrapPropertyResolver#PACKAGES} if searchExtensionPackages is true.
*
* @return a Map of {@link LifecycleStage} to Collection of {@link Interceptor}
*/
@SuppressWarnings("unchecked")
protected Map<LifecycleStage, Collection<Interceptor>> initInterceptors(List classes) {
Map<LifecycleStage, Collection<Interceptor>> map = new HashMap<LifecycleStage, Collection<Interceptor>>();
for (Object type : classes) {
try {
Interceptor interceptor = getObjectFactory().newInstance(
(Class<? extends Interceptor>) type);
addInterceptor(map, interceptor);
}
catch (Exception e) {
throw new StripesRuntimeException("Could not instantiate configured Interceptor ["
+ type.getClass().getName() + "].", e);
}
}
return map;
}
示例2: runStripesInterceptors
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
protected void runStripesInterceptors(ContainerRequestContext requestContext, Object resource, boolean before) {
if(resource instanceof ActionBean) {
BridgeExecutionContext executionContext = new BridgeExecutionContext(before);
ActionBean actionBean = (ActionBean) resource;
executionContext.setActionBean(actionBean);
executionContext.setActionBeanContext(actionBean.getContext());
executionContext.setHandler(resourceInfo.getResourceMethod());
executionContext.setLifecycleStage(LifecycleStage.EventHandling);
try {
Resolution resolution = beforeAfterMethodInterceptor.intercept(executionContext);
if(resolution != null) {
requestContext.abortWith(Response.ok(resolution).build());
}
} catch (Exception e) {
logger.error("Exception applying before/after method interceptor", e);
requestContext.abortWith(Response.serverError().entity(e).build());
}
}
}
示例3: intercept
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
// Continue on and execute other filters and the lifecycle code.
Resolution resolution = context.proceed();
// Get all fields with session.
Collection<Field> fields = getSessionFields(context.getActionBean().getClass());
// Restores values from session.
if (LifecycleStage.ActionBeanResolution.equals(context.getLifecycleStage())) {
this.restoreFields(fields, context.getActionBean(), context.getActionBeanContext());
}
// Store values in session.
if (LifecycleStage.EventHandling.equals(context.getLifecycleStage())) {
// Dont't update values in session if a validation error occured.
if (context.getActionBeanContext().getValidationErrors().isEmpty()) {
if (fields.size() > 0)
this.saveFields(fields, context.getActionBean(), context.getActionBeanContext().getRequest().getSession());
}
}
return resolution;
}
示例4: list
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@Before(stages = LifecycleStage.EventHandling)
public void list(){
if (this.getVanencompetition()!=null){
this.poules = Stripersist.getEntityManager().createQuery("FROM Poule where vanencompetition = :v").setParameter("v",this.getVanencompetition()).getResultList();
if (this.type!=null || (this.poule!=null && this.poule.getType()!=null)){
CompetitionType ct =null;
if (this.type!=null){
ct= CompetitionType.valueOf(this.type);
}else{
ct = this.poule.getType();
}
this.participantsWithoutPoule = Stripersist.getEntityManager()
.createQuery("FROM Participant where poule is null and vanencompetition = :v and type = :t order by karateka.belt,karateka.birthdate")
.setParameter("v", this.getVanencompetition()).setParameter("t", ct).getResultList();
}else{
this.participantsWithoutPoule = Stripersist.getEntityManager()
.createQuery("FROM Participant where poule is null and vanencompetition = :v order by karateka.belt,karateka.birthdate")
.setParameter("v", this.getVanencompetition()).getResultList();
}
}
}
示例5: initCoreInterceptors
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
/**
* Looks for a list of class names separated by commas under the configuration key
* {@link #CORE_INTERCEPTOR_LIST}. White space surrounding the class names is trimmed,
* the classes instantiated and then stored under the lifecycle stage(s) they should
* intercept.
*
* @return a Map of {@link LifecycleStage} to Collection of {@link Interceptor}
*/
@Override
protected Map<LifecycleStage, Collection<Interceptor>> initCoreInterceptors() {
List<Class<?>> coreInterceptorClasses = getBootstrapPropertyResolver().getClassPropertyList(CORE_INTERCEPTOR_LIST);
if (coreInterceptorClasses.size() == 0)
return super.initCoreInterceptors();
else
return initInterceptors(coreInterceptorClasses);
}
示例6: getInterceptors
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
/**
* Returns a list of interceptors that should be executed around the lifecycle stage
* indicated. By default returns a single element list containing the
* {@link BeforeAfterMethodInterceptor}.
*/
public Collection<Interceptor> getInterceptors(LifecycleStage stage) {
Collection<Interceptor> interceptors = this.interceptors.get(stage);
if (interceptors == null) {
interceptors = Collections.emptyList();
}
return interceptors;
}
示例7: mergeInterceptorMaps
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
/**
* Merges the two {@link Map}s of {@link LifecycleStage} to {@link Collection} of
* {@link Interceptor}. A simple {@link Map#putAll(Map)} does not work because it overwrites
* the collections in the map instead of adding to them.
*/
protected void mergeInterceptorMaps(Map<LifecycleStage, Collection<Interceptor>> dst,
Map<LifecycleStage, Collection<Interceptor>> src) {
for (Map.Entry<LifecycleStage, Collection<Interceptor>> entry : src.entrySet()) {
Collection<Interceptor> collection = dst.get(entry.getKey());
if (collection == null) {
collection = new LinkedList<Interceptor>();
dst.put(entry.getKey(), collection);
}
collection.addAll(entry.getValue());
}
}
示例8: addInterceptor
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
/**
* Adds the interceptor to the map, associating it with the {@link LifecycleStage}s indicated
* by the {@link Intercepts} annotation. If the interceptor implements
* {@link ConfigurableComponent}, then its init() method will be called.
*/
protected void addInterceptor(Map<LifecycleStage, Collection<Interceptor>> map,
Interceptor interceptor) {
Class<? extends Interceptor> type = interceptor.getClass();
Intercepts intercepts = type.getAnnotation(Intercepts.class);
if (intercepts == null) {
log.error("An interceptor of type ", type.getName(), " was configured ",
"but was not marked with an @Intercepts annotation. As a ",
"result it is not possible to determine at which ",
"lifecycle stages the interceptor should be applied. This ",
"interceptor will be ignored.");
return;
}
else {
log.debug("Configuring interceptor '", type.getSimpleName(),
"', for lifecycle stages: ", intercepts.value());
}
// call init() if the interceptor implements ConfigurableComponent
if (interceptor instanceof ConfigurableComponent) {
try {
((ConfigurableComponent) interceptor).init(this);
}
catch (Exception e) {
log.error("Error initializing interceptor of type " + type.getName(), e);
}
}
for (LifecycleStage stage : intercepts.value()) {
Collection<Interceptor> stack = map.get(stage);
if (stack == null) {
stack = new LinkedList<Interceptor>();
map.put(stage, stack);
}
stack.add(interceptor);
}
}
示例9: initCoreInterceptors
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
/** Instantiates the core interceptors, allowing subclasses to override the default behavior */
protected Map<LifecycleStage, Collection<Interceptor>> initCoreInterceptors() {
Map<LifecycleStage, Collection<Interceptor>> interceptors = new HashMap<LifecycleStage, Collection<Interceptor>>();
addInterceptor(interceptors, new BeforeAfterMethodInterceptor());
addInterceptor(interceptors, new HttpCacheInterceptor());
return interceptors;
}
示例10: setupContext
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@BeforeClass
@SuppressWarnings("unchecked")
public void setupContext() throws Exception {
context = new MockServletContext("waitpage");
// Add the Stripes Filter
Map<String,String> filterParams = new HashMap<String,String>();
filterParams.put("CoreInterceptor.Classes",
"org.stripesstuff.tests.waitpage.TestableWaitPageInterceptor," +
"net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor," +
"net.sourceforge.stripes.controller.HttpCacheInterceptor");
filterParams.put("ActionResolver.Packages",
"org.stripesstuff.tests.waitpage.action");
filterParams.put("WaitPageInterceptor.ContextTimeout",
"2000");
context.addFilter(StripesFilter.class, "StripesFilter", filterParams);
// Add the Stripes Dispatcher
context.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
// Obtain WaitPageInterceptor instance.
StripesFilter stripesFilter = (StripesFilter)context.getFilters().get(0);
Iterator<Interceptor> interceptorsIter = stripesFilter.getInstanceConfiguration().getInterceptors(LifecycleStage.ActionBeanResolution).iterator();
WaitPageInterceptor waitPageInterceptor = null;
while (waitPageInterceptor == null && interceptorsIter.hasNext()) {
Interceptor interceptor = interceptorsIter.next();
if (interceptor instanceof WaitPageInterceptor) {
waitPageInterceptor = (WaitPageInterceptor)interceptor;
}
}
assertNotNull(waitPageInterceptor);
Field field = WaitPageInterceptor.class.getDeclaredField("contexts");
field.setAccessible(true);
waitContexts = (Map<Integer, Context>)field.get(waitPageInterceptor);
}
示例11: load
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@Before(stages = LifecycleStage.BindingAndValidation)
public void load() {
user=(User) context.getRequest().getUserPrincipal();
Organisation o = user.getOrganisation();
Date now = new Date();
if (getUser().checkRole(Role.SUPERADMIN.name())){
setVanencompetitions((List<Vanencompetition>) Stripersist.getEntityManager().createQuery("From Vanencompetition where date >= :d ORDER BY date")
.setParameter("d",now).getResultList());
}else if (o!=null){
setVanencompetitions((List<Vanencompetition>) Stripersist.getEntityManager().createQuery("From Vanencompetition where date >= :d and organisation = :o ORDER BY date")
.setParameter("d",now).setParameter("o", o).getResultList());
}
}
示例12: initVanencompetition
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@After(stages = {LifecycleStage.BindingAndValidation})
public void initVanencompetition() {
if (vanencompetitionId != null) {
EntityManager em = Stripersist.getEntityManager();
setVanencompetition(em.find(Vanencompetition.class, vanencompetitionId));
}
}
示例13: beforeHandlerResolution
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@Before(stages = { LifecycleStage.HandlerResolution })
public void beforeHandlerResolution() {
fbAppId = WebContainerProperties.INSTANCE.getFbAppId();
googleClientId = WebContainerProperties.INSTANCE.getGoogleClientId();
if (fbAppId.isEmpty() && googleClientId.isEmpty()) {
showCycLogin = true;
}
WinnerResult result = WinnerHistoryCalculation.INSTANCE.calc();
threeDayWinner = result.getThreeDayWinner();
threeDayWinnerTimeRange = result.getThreeDayWinnerTimeRange().toString();
registerDisabled = WebContainerProperties.INSTANCE.getSystemDisabledDate().before(new Date());
systemMessage = WebContainerProperties.INSTANCE.getSystemMessage();
}
示例14: generateCaptcha
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@After(stages = { LifecycleStage.BindingAndValidation })
public void generateCaptcha() {
if (WebContainerProperties.INSTANCE.isCaptchaEnabled()
&& (captchaTokenCrypted == null || captchaTokenCrypted.isEmpty())) {
captchaTokenCrypted = CaptchaServlet.getService().encrypt(CaptchaServlet.generateToken());
}
}
示例15: encodeCaptchaTokenCrypted
import net.sourceforge.stripes.controller.LifecycleStage; //导入依赖的package包/类
@Before(stages = { LifecycleStage.ResolutionExecution })
public void encodeCaptchaTokenCrypted() {
try {
if (WebContainerProperties.INSTANCE.isCaptchaEnabled()) {
captchaTokenCryptedUrl = URLEncoder.encode(captchaTokenCrypted, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
log.error("Failed to encode captchaTokenCrypted", e);
}
}