use of com.opensymphony.xwork2.Action in project onebusaway-application-modules by camsys.
the class MultipleStopsFoundTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack vs = context.getValueStack();
List<StopBean> stops = (List<StopBean>) vs.findValue("stops");
int index = 1;
addMessage(Messages.MULTIPLE_STOPS_WERE_FOUND);
for (StopBean stop : stops) {
addMessage(Messages.FOR);
addText(_destinationPronunciation.modify(stop.getName()));
addMessage(Messages.PLEASE_PRESS);
String key = Integer.toString(index++);
addText(key);
AgiActionName action = addAction(key, "/stop/arrivalsAndDeparturesForStopId");
action.putParam("stopIds", Arrays.asList(stop.getId()));
}
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
use of com.opensymphony.xwork2.Action in project onebusaway-application-modules by camsys.
the class StopsForRouteNavigationTemplate method buildTemplate.
@Override
public void buildTemplate(ActionContext context) {
ValueStack vs = context.getValueStack();
NavigationBean navigation = (NavigationBean) vs.findValue("navigation");
List<NameBean> names = navigation.getNames();
int index = navigation.getCurrentIndex();
if (index < 0)
index = 0;
/**
* We always listen for the key-press for the previous name in case it takes
* the user a second to press
*/
if (index > 0)
addNavigationSelectionActionForIndex(navigation, index - 1);
/**
* If we're at the first entry and there is a second, we allow the user to
* jump ahead
*/
if (index == 0 && names.size() > 1) {
addNavigationSelectionActionForIndex(navigation, index + 1);
}
if (index >= names.size()) {
AgiActionName action = setNextAction("/search/navigate-to");
action.putParam("navigation", navigation);
action.putParam("index", 0);
action.setExcludeFromHistory(true);
// Add an extra pause so the user has a chance to make a selection from
// the previous entry
addPause(1000);
addMessage(Messages.TO_REPEAT);
} else {
String key = addNavigationSelectionActionForIndex(navigation, index);
NameBean name = names.get(index);
handleName(name, key);
addNavigateToAction(navigation, "4", first(index - 1));
addNavigateToAction(navigation, "6", index + 1);
addNavigateToAction(navigation, "7", first(index - 10));
addNavigateToAction(navigation, "9", index + 10);
AgiActionName action = setNextAction("/search/navigate-to");
action.putParam("navigation", navigation);
action.putParam("index", index + 1);
action.setExcludeFromHistory(true);
}
addAction("\\*", "/back");
}
use of com.opensymphony.xwork2.Action in project qi4j-sdk by Qi4j.
the class Qi4jCodebehindPackageProvider method loadPackageConfig.
/**
* Finds or creates the package configuration for an Action class.
*
* The namespace annotation is honored, if found,
* and the namespace is checked for a parent configuration.
*
* @param actionNamespace The configuration namespace
* @param actionPackage The Java package containing our Action classes
* @param actionClass The Action class instance
*
* @return PackageConfig object for the Action class
*/
protected PackageConfig.Builder loadPackageConfig(String actionNamespace, String actionPackage, Class actionClass) {
PackageConfig.Builder parent = null;
// Check for the @Namespace annotation
if (actionClass != null) {
Namespace ns = (Namespace) actionClass.getAnnotation(Namespace.class);
if (ns != null) {
parent = loadPackageConfig(actionNamespace, actionPackage, null);
actionNamespace = ns.value();
actionPackage = actionClass.getName();
// See if the namespace has been overridden by the @Action annotation
} else {
org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) actionClass.getAnnotation(org.apache.struts2.config.Action.class);
if (actionAnn != null && !actionAnn.DEFAULT_NAMESPACE.equals(actionAnn.namespace())) {
// we pass null as the namespace in case the parent package hasn't been loaded yet
parent = loadPackageConfig(null, actionPackage, null);
actionPackage = actionClass.getName();
}
}
}
PackageConfig.Builder pkgConfig = packageLoader.getPackage(actionPackage);
if (pkgConfig == null) {
pkgConfig = new PackageConfig.Builder(actionPackage);
pkgConfig.namespace(actionNamespace);
if (parent == null) {
PackageConfig cfg = configuration.getPackageConfig(defaultParentPackage);
if (cfg != null) {
pkgConfig.addParent(cfg);
} else {
throw new ConfigurationException("ClasspathPackageProvider: Unable to locate default parent package: " + defaultParentPackage);
}
}
packageLoader.registerPackage(pkgConfig);
// if the parent package was first created by a child, ensure the namespace is correct
} else if (pkgConfig.getNamespace() == null) {
pkgConfig.namespace(actionNamespace);
}
if (parent != null) {
packageLoader.registerChildToParent(pkgConfig, parent);
}
if (LOG.isDebugEnabled()) {
LOG.debug("class:" + actionClass + " parent:" + parent + " current:" + (pkgConfig != null ? pkgConfig.getName() : ""));
}
return pkgConfig;
}
use of com.opensymphony.xwork2.Action in project dhis2-core by dhis2.
the class DefaultModuleManager method detectModules.
private synchronized void detectModules() {
if (modulesDetected) {
return;
}
I18n i18n = i18nManager.getI18n();
for (PackageConfig packageConfig : getPackageConfigs()) {
String name = packageConfig.getName();
String namespace = packageConfig.getNamespace();
String displayName = i18n.getString(name);
log.debug("Package config: " + name + ", " + namespace);
if (packageConfig.getAllActionConfigs().size() == 0) {
log.debug("Ignoring action package with no actions: " + name);
continue;
}
if (namespace == null || namespace.length() == 0) {
throw new RuntimeException("Missing namespace in action package: " + name);
}
if (modulesByName.containsKey(name)) {
throw new RuntimeException("Two action packages have the same name: " + name);
}
if (modulesByNamespace.containsKey(namespace)) {
Module module = modulesByNamespace.get(namespace);
throw new RuntimeException("These action packages have the same namespace: " + name + " and " + module.getName());
}
Module module = new Module(name, namespace);
module.setDisplayName(displayName);
modulesByName.put(name, module);
modulesByNamespace.put(namespace, module);
boolean include = !menuModuleExclusions.contains(name);
if (packageConfig.getActionConfigs().containsKey(defaultActionName) && include) {
module.setDefaultAction(".." + namespace + "/" + defaultActionName + ".action");
menuModules.add(module);
log.debug("Has default action: " + name);
} else {
log.debug("Doesn't have default action: " + name);
}
}
Collections.sort(menuModules, moduleComparator);
log.debug("Menu modules detected: " + menuModules);
modulesDetected = true;
currentLocale = localeManager.getCurrentLocale();
}
use of com.opensymphony.xwork2.Action in project dhis2-core by dhis2.
the class SpringSecurityActionAccessResolver method hasAccess.
// -------------------------------------------------------------------------
// ActionAccessResolver implementation
// -------------------------------------------------------------------------
@Override
public boolean hasAccess(String module, String name) {
// ---------------------------------------------------------------------
// Get ObjectDefinitionSource
// ---------------------------------------------------------------------
Configuration config = Dispatcher.getInstance().getConfigurationManager().getConfiguration();
PackageConfig packageConfig = config.getPackageConfig(module);
if (packageConfig == null) {
throw new IllegalArgumentException("Module doesn't exist: '" + module + "'");
}
ActionConfig actionConfig = packageConfig.getActionConfigs().get(name);
if (actionConfig == null) {
throw new IllegalArgumentException("Module " + module + " doesn't have an action named: '" + name + "'");
}
SecurityMetadataSource securityMetadataSource = requiredAuthoritiesProvider.createSecurityMetadataSource(actionConfig);
// ---------------------------------------------------------------------
// Test access
// ---------------------------------------------------------------------
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext.getAuthentication();
try {
if (securityMetadataSource.getAttributes(actionConfig) != null) {
if (authentication == null || !authentication.isAuthenticated()) {
return false;
}
accessDecisionManager.decide(authentication, actionConfig, securityMetadataSource.getAttributes(actionConfig));
}
log.debug("Access to [" + module + ", " + name + "]: TRUE");
return true;
} catch (AccessDeniedException e) {
log.debug("Access to [" + module + ", " + name + "]: FALSE (access denied)");
return false;
} catch (InsufficientAuthenticationException e) {
log.debug("Access to [" + module + ", " + name + "]: FALSE (insufficient authentication)");
return false;
}
}
Aggregations