Search in sources :

Example 6 with Actions

use of org.apache.struts2.convention.annotation.Actions in project onebusaway-application-modules by camsys.

the class TripAction method execute.

@Override
@Actions({ @Action(value = "/where/trip"), @Action(value = "/where/iphone/trip") })
public String execute() throws ServiceException {
    if (_id == null)
        return INPUT;
    if (_time == null)
        _time = new Date();
    TripDetailsQueryBean query = new TripDetailsQueryBean();
    query.setTripId(_id);
    if (_serviceDate != null)
        query.setServiceDate(_serviceDate.getTime());
    query.setVehicleId(_vehicleId);
    query.setTime(_time.getTime());
    _tripDetails = _service.getSingleTripDetails(query);
    if (_tripDetails == null)
        throw new NoSuchTripServiceException(_id);
    TripStopTimesBean stopTimes = _tripDetails.getSchedule();
    _timeZone = TimeZone.getTimeZone(stopTimes.getTimeZone());
    _actualServiceDate = getActualServiceDate();
    return SUCCESS;
}
Also used : TripDetailsQueryBean(org.onebusaway.transit_data.model.trips.TripDetailsQueryBean) NoSuchTripServiceException(org.onebusaway.exceptions.NoSuchTripServiceException) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean) Date(java.util.Date) Actions(org.apache.struts2.convention.annotation.Actions)

Example 7 with Actions

use of org.apache.struts2.convention.annotation.Actions in project onebusaway-application-modules by camsys.

the class AgenciesAction method execute.

@Override
@Actions({ @Action(value = "/where/iphone/agencies") })
public String execute() throws ServiceException {
    _model = _transitDataService.getAgenciesWithCoverage();
    Collections.sort(_model, new AgencyWithCoverageBeanComparator());
    return SUCCESS;
}
Also used : AgencyWithCoverageBeanComparator(org.onebusaway.presentation.impl.AgencyWithCoverageBeanComparator) Actions(org.apache.struts2.convention.annotation.Actions)

Example 8 with Actions

use of org.apache.struts2.convention.annotation.Actions in project qi4j-sdk by Qi4j.

the class Qi4jCodebehindPackageProvider method processActionClass.

/**
     * Create a default action mapping for a class instance.
     *
     * The namespace annotation is honored, if found, otherwise
     * the Java package is converted into the namespace
     * by changing the dots (".") to slashes ("/").
     *
     * @param cls  Action or POJO instance to process
     * @param pkgs List of packages that were scanned for Actions
     */
protected void processActionClass(Class<?> cls, String[] pkgs) {
    String name = cls.getName();
    String actionPackage = cls.getPackage().getName();
    String actionNamespace = null;
    String actionName = null;
    org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) cls.getAnnotation(org.apache.struts2.config.Action.class);
    if (actionAnn != null) {
        actionName = actionAnn.name();
        if (actionAnn.namespace().equals(org.apache.struts2.config.Action.DEFAULT_NAMESPACE)) {
            actionNamespace = "";
        } else {
            actionNamespace = actionAnn.namespace();
        }
    } else {
        for (String pkg : pkgs) {
            if (name.startsWith(pkg)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("ClasspathPackageProvider: Processing class " + name);
                }
                name = name.substring(pkg.length() + 1);
                actionNamespace = "";
                actionName = name;
                int pos = name.lastIndexOf('.');
                if (pos > -1) {
                    actionNamespace = "/" + name.substring(0, pos).replace('.', '/');
                    actionName = name.substring(pos + 1);
                }
                break;
            }
        }
        // Truncate Action suffix if found
        if (actionName.endsWith(getClassSuffix())) {
            actionName = actionName.substring(0, actionName.length() - getClassSuffix().length());
        }
        // Force initial letter of action to lowercase, if desired
        if ((forceLowerCase) && (actionName.length() > 1)) {
            int lowerPos = actionName.lastIndexOf('/') + 1;
            StringBuilder sb = new StringBuilder();
            sb.append(actionName.substring(0, lowerPos));
            sb.append(Character.toLowerCase(actionName.charAt(lowerPos)));
            sb.append(actionName.substring(lowerPos + 1));
            actionName = sb.toString();
        }
    }
    PackageConfig.Builder pkgConfig = loadPackageConfig(actionNamespace, actionPackage, cls);
    // In case the package changed due to namespace annotation processing
    if (!actionPackage.equals(pkgConfig.getName())) {
        actionPackage = pkgConfig.getName();
    }
    Annotation annotation = cls.getAnnotation(ParentPackage.class);
    if (annotation != null) {
        String parent = ((ParentPackage) annotation).value()[0];
        PackageConfig parentPkg = configuration.getPackageConfig(parent);
        if (parentPkg == null) {
            throw new ConfigurationException("ClasspathPackageProvider: Unable to locate parent package " + parent, annotation);
        }
        pkgConfig.addParent(parentPkg);
        if (!isNotEmpty(pkgConfig.getNamespace()) && isNotEmpty(parentPkg.getNamespace())) {
            pkgConfig.namespace(parentPkg.getNamespace());
        }
    }
    ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
    ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName()).addResultConfigs(new ResultMap<String, ResultConfig>(cls, actionName, defaultResultType)).build();
    pkgConfig.addActionConfig(actionName, actionConfig);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) Annotation(java.lang.annotation.Annotation) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) org.apache.struts2.config(org.apache.struts2.config)

Example 9 with Actions

use of org.apache.struts2.convention.annotation.Actions in project onebusaway-application-modules by camsys.

the class BlockAction method execute.

@Override
@Actions({ @Action(value = "/where/block"), @Action(value = "/where/iphone/block") })
public String execute() throws ServiceException {
    if (_id == null)
        return INPUT;
    _blockInstance = _service.getBlockInstance(_id, _serviceDate.getTime());
    if (_blockInstance == null)
        return ERROR;
    BlockConfigurationBean blockConfig = _blockInstance.getBlockConfiguration();
    _timeZone = TimeZone.getTimeZone(blockConfig.getTimeZone());
    return SUCCESS;
}
Also used : BlockConfigurationBean(org.onebusaway.transit_data.model.blocks.BlockConfigurationBean) Actions(org.apache.struts2.convention.annotation.Actions)

Aggregations

Actions (org.apache.struts2.convention.annotation.Actions)8 Date (java.util.Date)2 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)2 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)1 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Annotation (java.lang.annotation.Annotation)1 org.apache.struts2.config (org.apache.struts2.config)1 Action (org.apache.struts2.convention.annotation.Action)1 NoSuchStopServiceException (org.onebusaway.exceptions.NoSuchStopServiceException)1 NoSuchTripServiceException (org.onebusaway.exceptions.NoSuchTripServiceException)1 AgencyWithCoverageBeanComparator (org.onebusaway.presentation.impl.AgencyWithCoverageBeanComparator)1 RoutesBean (org.onebusaway.transit_data.model.RoutesBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopCalendarDaysBean (org.onebusaway.transit_data.model.StopCalendarDaysBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1