Search in sources :

Example 31 with ActionContext

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";
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 32 with ActionContext

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();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionContext(com.opensymphony.xwork2.ActionContext) Map(java.util.Map)

Example 33 with ActionContext

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);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) HashMap(java.util.HashMap) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext) Test(org.junit.Test)

Example 34 with ActionContext

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);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) List(java.util.List) AgiActionName(org.onebusaway.probablecalls.AgiActionName) HashSet(java.util.HashSet)

Example 35 with ActionContext

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);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ValueStack(com.opensymphony.xwork2.util.ValueStack) List(java.util.List) AgiActionName(org.onebusaway.probablecalls.AgiActionName)

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)32 ValueStack (com.opensymphony.xwork2.util.ValueStack)15 AgiActionName (org.onebusaway.probablecalls.AgiActionName)7 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 ServletActionContext (org.apache.struts2.ServletActionContext)6 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)5 List (java.util.List)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 IOException (java.io.IOException)2 SessionAware (org.apache.struts2.interceptor.SessionAware)2 Test (org.junit.Test)2 BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)2 NameBean (org.onebusaway.transit_data.model.NameBean)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2