Search in sources :

Example 31 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class IndexTemplate method buildTemplate.

@Override
public void buildTemplate(ActionContext context) {
    ValueStack stack = context.getValueStack();
    UserBean user = (UserBean) stack.findValue("currentUser");
    if (user.getDefaultLocationName() != null) {
        addMessage(Messages.SETTINGS_YOUR_DEFAULT_SEARCH_LOCATION_IS_CURRENTLY);
        addText(_locationPronunciation.modify(user.getDefaultLocationName()));
    }
    addMessage(Messages.INDEX_ACTION_SET_DEFAULT_SEARCH_LOCATION);
    addAction("1", "/settings/askForDefaultSearchLocation");
    if (user != null) {
        if (user.isRememberPreferencesEnabled())
            addMessage(Messages.PREFERENCES_DO_NOT_REMEMBER);
        else
            addMessage(Messages.PREFERENCES_DO_REMEMBER);
        addAction("2", "/settings/setRememberPreferences", "enabled", !user.isRememberPreferencesEnabled());
    }
    addMessage(Messages.HOW_TO_GO_BACK);
    addAction("\\*", "/back");
    addMessage(Messages.TO_REPEAT);
    addAction("[#23456789*]", "/repeat");
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) UserBean(org.onebusaway.users.client.model.UserBean)

Example 32 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class MessageTemplateDispatcher method executeTemplate.

@Override
protected AgiActionName executeTemplate(ActionContext context, AgiTemplate template) throws Exception {
    if (_message != null) {
        ValueStack stack = context.getValueStack();
        MessageSource source = new MessageSource(_message, _nextAction);
        stack.push(source);
    }
    return super.executeTemplate(context, template);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 33 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class SpringContainer method register.

@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
    // Since we're about to override...
    builder.setAllowDuplicates(true);
    builder.factory(ObjectFactory.class, new Factory<ObjectFactory>() {

        public ObjectFactory create(Context xworkContext) throws Exception {
            SpringObjectFactory f = new SpringObjectFactory();
            xworkContext.getContainer().inject(f);
            f.setApplicationContext(_applicationContext);
            f.setAutowireStrategy(_autoWireStrategy);
            return f;
        }
    });
}
Also used : Context(com.opensymphony.xwork2.inject.Context) ApplicationContext(org.springframework.context.ApplicationContext) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Example 34 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class MessageAndBackTemplate method buildTemplate.

@Override
public void buildTemplate(ActionContext context) {
    ValueStack stack = context.getValueStack();
    String message = stack.findString("message");
    String nextAction = stack.findString("nextAction");
    if (message != null)
        addMessage(message);
    else
        System.err.println("no message specified");
    if (nextAction != null) {
        setNextAction(nextAction);
    } else {
        addAction(".*\\*", "/back");
        setNextAction("/back");
    }
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 35 with Context

use of com.opensymphony.xwork2.inject.Context in project entando-core by entando.

the class ApsDateTypeConverter method convertFromString.

@Override
public Object convertFromString(Map context, String[] values, Class toType) {
    if (null == values)
        return null;
    if (values.length > 1) {
        throw new XWorkException("Multiple values");
    }
    Date result = null;
    String value = values[0];
    if (value instanceof String && value != null && ((String) value).length() > 0) {
        String sa = (String) value;
        DateFormat df = new SimpleDateFormat(ApsAdminSystemConstants.CALENDAR_DATE_PATTERN);
        try {
            // let's use strict parsing (XW-341)
            df.setLenient(false);
            result = df.parse(sa);
            if (!(Date.class == toType)) {
                try {
                    Constructor constructor = toType.getConstructor(new Class[] { long.class });
                    return constructor.newInstance(new Object[] { Long.valueOf(result.getTime()) });
                } catch (Exception e) {
                    throw new XWorkException("Couldn't create class " + toType + " using default (long) constructor", e);
                }
            }
        } catch (ParseException e) {
            throw new XWorkException("Could not parse date", e);
        }
    }
    return result;
}
Also used : XWorkException(com.opensymphony.xwork2.XWorkException) Constructor(java.lang.reflect.Constructor) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) XWorkException(com.opensymphony.xwork2.XWorkException) ParseException(java.text.ParseException)

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)21 ValueStack (com.opensymphony.xwork2.util.ValueStack)14 AgiActionName (org.onebusaway.probablecalls.AgiActionName)7 List (java.util.List)5 ActionProxy (com.opensymphony.xwork2.ActionProxy)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 XWorkException (com.opensymphony.xwork2.XWorkException)2 Inject (com.opensymphony.xwork2.inject.Inject)2 Constructor (java.lang.reflect.Constructor)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Map (java.util.Map)2 ServletActionContext (org.apache.struts2.ServletActionContext)2 SessionAware (org.apache.struts2.interceptor.SessionAware)2 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)2 BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)2