use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class IndexAction method execute.
@Override
public String execute() throws Exception {
ActionContext context = ActionContext.getContext();
ActionInvocation invocation = context.getActionInvocation();
ActionProxy proxy = invocation.getProxy();
String name = proxy.getActionName().toLowerCase();
String namespace = proxy.getNamespace().toLowerCase();
// return the 404 message if so. There has to be a better way than this?
if ((name.equals("") || name.equals("index")) && (namespace.equals("") || namespace.equals("/"))) {
return SUCCESS;
}
return "NotFound";
}
use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class ExceptionInterceptor method getActionAsUrl.
private String getActionAsUrl(ActionInvocation invocation) {
ActionProxy proxy = invocation.getProxy();
ActionContext context = invocation.getInvocationContext();
StringBuilder b = new StringBuilder();
b.append(proxy.getNamespace());
b.append("/");
b.append(proxy.getActionName());
b.append("!");
b.append(proxy.getMethod());
Map<String, Object> params = context.getParameters();
if (!params.isEmpty()) {
b.append("?");
boolean seenFirst = false;
for (Map.Entry<String, Object> entry : params.entrySet()) {
// Prune out any identifying information
if ("app_uid".equals(entry.getKey()))
continue;
Object value = entry.getValue();
String[] values = (value instanceof String[]) ? (String[]) value : new String[] { value.toString() };
for (String v : values) {
if (seenFirst)
b.append("&");
else
seenFirst = true;
b.append(entry.getKey());
b.append("=");
b.append(v);
}
}
}
return b.toString();
}
use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class IndexActionTest method testExecute.
@Test
public void testExecute() throws Exception {
ActionProxy proxy = Mockito.mock(ActionProxy.class);
Mockito.when(proxy.getActionName()).thenReturn("index");
Mockito.when(proxy.getNamespace()).thenReturn("/");
ActionInvocation invocation = Mockito.mock(ActionInvocation.class);
Mockito.when(invocation.getProxy()).thenReturn(proxy);
Map<String, Object> c = new HashMap<String, Object>();
ActionContext ac = new ActionContext(c);
ac.setActionInvocation(invocation);
ActionContext.setContext(ac);
IndexAction action = new IndexAction();
String response = action.execute();
assertEquals("successful response", "success", response);
}
use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class IndexTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack stack = context.getValueStack();
List<BookmarkWithStopsBean> bookmarks = (List<BookmarkWithStopsBean>) stack.findValue("bookmarks");
if (bookmarks.isEmpty()) {
addMessage(Messages.BOOKMARKS_EMPTY);
} else {
int index = 1;
for (BookmarkWithStopsBean bookmark : bookmarks) {
String toPress = Integer.toString(index);
addMessage(Messages.FOR);
AgiActionName stopAction = addAction(toPress, "/stop/arrivalsAndDeparturesForStopId");
List<String> stopIds = MappingLibrary.map(bookmark.getStops(), "id");
Set<String> routeIds = new HashSet<String>(MappingLibrary.map(bookmark.getRoutes(), "id", String.class));
stopAction.putParam("stopIds", stopIds);
stopAction.putParam("routeIds", routeIds);
addBookmarkDescription(bookmark);
addMessage(Messages.PLEASE_PRESS);
addText(toPress);
index++;
}
}
addAction("(#|0|.+\\*)", "/repeat");
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class MultipleRoutesFoundTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack vs = context.getValueStack();
List<RouteBean> routes = (List<RouteBean>) vs.findValue("routes");
int index = 1;
addMessage(Messages.MULTIPLE_ROUTES_WERE_FOUND);
for (RouteBean route : routes) {
addMessage(Messages.FOR);
addMessage(Messages.ROUTE);
String routeNumber = route.getShortName();
addText(_routeNumberPronunciation.modify(routeNumber));
addMessage(Messages.OPERATED_BY);
addText(route.getAgency().getName());
addMessage(Messages.PLEASE_PRESS);
String key = Integer.toString(index++);
addText(key);
AgiActionName action = addAction(key, "/search/tree");
action.putParam("route", route);
}
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
Aggregations