BrightSide Workbench Full Report + Source Code
Interceptors.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.action;
19 
20 import java.util.Map;
21 import org.turro.annotation.ElephantInterceptor;
22 import org.turro.collections.KeyValueMap;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.context.IConstructor;
25 import org.turro.reflection.Instances;
26 import org.turro.string.Strings;
27 
32 public class Interceptors {
33 
34  public static final String GOTO = "goto";
35 
36  /* Elephant Interceptor */
37 
38  public static boolean executeWeb(IConstructor constructor) {
39  boolean done = false;
40  KeyValueMap kvm = Parameters.from(constructor.getRequest().getParameterMap()).asMap();
41  String goTo = kvm.get(GOTO);
42  if(!Strings.isBlank(goTo)) {
43  for(IInterceptor iInterceptor : Instances.cached().byAnnotation(ElephantInterceptor.class, IInterceptor.class)) {
44  if(iInterceptor.executeWeb(constructor, goTo, kvm)) {
45  done = true;
46  break;
47  }
48  }
49  }
50  return done;
51  }
52 
53  public static boolean executeApp(Application application, Map<String, String[]> parameterMap) {
54  boolean done = false;
55  KeyValueMap kvm = Parameters.from(parameterMap).asMap();
56  String goTo = kvm.get(GOTO);
57  if(!Strings.isBlank(goTo)) {
58  for(IInterceptor iInterceptor : Instances.cached().byAnnotation(ElephantInterceptor.class, IInterceptor.class)) {
59  if(iInterceptor.executeApp(application, goTo, kvm)) {
60  done = true;
61  break;
62  }
63  }
64  }
65  return done;
66  }
67 
68  /* Utils */
69 
70  public static Parameters parameters(String root) {
71  return Parameters.instance()
72  .add(Interceptors.GOTO, root);
73  }
74 
75  public static Parameters parameters(String root, String id) {
76  return Parameters.instance()
77  .add(Interceptors.GOTO, root)
78  .add(root + "Id", id);
79  }
80 
81  /* Factory */
82 
83  private Interceptors() {
84  }
85 
86 }
static final String GOTO
static Parameters parameters(String root)
static boolean executeWeb(IConstructor constructor)
static Parameters parameters(String root, String id)
static boolean executeApp(Application application, Map< String, String[]> parameterMap)
static Parameters from(Map< String, String[]> parameterMap)
Parameters add(String key, Object value)
Definition: Parameters.java:48
static Parameters instance()