use of com.opensymphony.xwork2.util.location.Location in project tis by qlangtech.
the class TisResultMapBuilder method build.
@Override
public Map<String, ResultConfig> build(Class<?> actionClass, Action annotation, String actionName, PackageConfig packageConfig) {
ResultConfig.Builder build = null;
final String resultName = actionClass.getSimpleName();
Map<String, ResultConfig> resultsConfig = new HashMap<String, ResultConfig>();
resultsConfig.put(BasicModule.key_FORWARD, ACTION_RESULT_CONFIG);
Matcher matcher = TisPackageBasedActionConfigBuilder.NAMESPACE_PATTERN.matcher(actionClass.getName());
if (// || (matcher = TisPackageBasedActionConfigBuilder.NAMESPACE_TIS_PATTERN.matcher(actionClass.getName())).matches()
matcher.matches()) {
if ("action".equals(matcher.group(2))) {
// process ajax
String resultCode = resultName + "_ajax";
build = new ResultConfig.Builder(resultCode, AjaxValve.class.getName());
resultsConfig.put(resultCode, build.build());
// process action submit
resultCode = resultName + "_action";
// final String resultCode = resultName.toString() + "_ajax";
build = new ResultConfig.Builder(resultCode, ActionChainResult.class.getName());
build.addParam("actionName", TisActionMapper.addUnderline(resultName).toString());
build.addParam("namespace", "/" + matcher.group(1) + StringUtils.replace(matcher.group(3), ".", "/") + "#screen");
resultsConfig.put(resultCode, build.build());
} else {
// build = new ResultConfig.Builder(resultName, TerminatorVelocityResult.class.getName());
// build.addParam("location", "/" + matcher.group(1) + "/templates/"
// + matcher.group(2) + StringUtils.replace(matcher.group(3), ".", "/") + '/' + getViewName(resultName) + ".vm");
// resultsConfig.put(resultName, build.build());
}
} else {
throw new IllegalStateException("class name :" + actionClass.getName() + " is illegal");
}
return resultsConfig;
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class XmlConfigurationProvider method addAction.
protected void addAction(Element actionElement, PackageConfig.Builder packageContext) throws ConfigurationException {
String name = actionElement.getAttribute("name");
String className = actionElement.getAttribute("class");
// methodName should be null if it's not set
String methodName = StringUtils.trimToNull(actionElement.getAttribute("method"));
Location location = DomHelper.getLocationObject(actionElement);
if (location == null) {
LOG.warn("Location null for {}", className);
}
// use the default-class-ref from the <package/>
if (StringUtils.isEmpty(className)) {
// if there is a package default-class-ref use that, otherwise use action support
/* if (StringUtils.isNotEmpty(packageContext.getDefaultClassRef())) {
className = packageContext.getDefaultClassRef();
} else {
className = ActionSupport.class.getName();
}*/
} else {
if (!verifyAction(className, name, location)) {
LOG.error("Unable to verify action [{}] with class [{}], from [{}]", name, className, location);
return;
}
}
Map<String, ResultConfig> results;
try {
results = buildResults(actionElement, packageContext);
} catch (ConfigurationException e) {
throw new ConfigurationException("Error building results for action " + name + " in namespace " + packageContext.getNamespace(), e, actionElement);
}
List<InterceptorMapping> interceptorList = buildInterceptorList(actionElement, packageContext);
List<ExceptionMappingConfig> exceptionMappings = buildExceptionMappings(actionElement, packageContext);
Set<String> allowedMethods = buildAllowedMethods(actionElement, packageContext);
ActionConfig actionConfig = new ActionConfig.Builder(packageContext.getName(), name, className).methodName(methodName).addResultConfigs(results).addInterceptors(interceptorList).addExceptionMappings(exceptionMappings).addParams(XmlHelper.getParams(actionElement)).setStrictMethodInvocation(packageContext.isStrictMethodInvocation()).addAllowedMethod(allowedMethods).location(location).build();
packageContext.addActionConfig(name, actionConfig);
LOG.debug("Loaded {}{} in '{}' package: {}", StringUtils.isNotEmpty(packageContext.getNamespace()) ? (packageContext.getNamespace() + "/") : "", name, packageContext.getName(), actionConfig);
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class XmlConfigurationProvider method buildExceptionMappings.
/**
* Build a list of exception mapping objects from below a given XML element.
*
* @param element the given XML element
* @param packageContext the package context
*
* @return list of exception mapping config objects
*/
protected List<ExceptionMappingConfig> buildExceptionMappings(Element element, PackageConfig.Builder packageContext) {
NodeList exceptionMappingEls = element.getElementsByTagName("exception-mapping");
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<>();
for (int i = 0; i < exceptionMappingEls.getLength(); i++) {
Element ehElement = (Element) exceptionMappingEls.item(i);
if (ehElement.getParentNode().equals(element) || ehElement.getParentNode().getNodeName().equals(element.getNodeName())) {
String emName = ehElement.getAttribute("name");
String exceptionClassName = ehElement.getAttribute("exception");
String exceptionResult = ehElement.getAttribute("result");
Map<String, String> params = XmlHelper.getParams(ehElement);
if (StringUtils.isEmpty(emName)) {
emName = exceptionResult;
}
ExceptionMappingConfig ehConfig = new ExceptionMappingConfig.Builder(emName, exceptionClassName, exceptionResult).addParams(params).location(DomHelper.getLocationObject(ehElement)).build();
exceptionMappings.add(ehConfig);
}
}
return exceptionMappings;
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class XmlConfigurationProvider method buildPackageContext.
/**
* <p>
* This method builds a package context by looking for the parents of this new package.
* </p>
*
* <p>
* If no parents are found, it will return a root package.
* </p>
*
* @param packageElement the package element
*
* @return the package config builder
*/
protected PackageConfig.Builder buildPackageContext(Element packageElement) {
String parent = packageElement.getAttribute("extends");
String abstractVal = packageElement.getAttribute("abstract");
boolean isAbstract = Boolean.parseBoolean(abstractVal);
String name = StringUtils.defaultString(packageElement.getAttribute("name"));
String namespace = StringUtils.defaultString(packageElement.getAttribute("namespace"));
// Strict DMI is enabled by default, it can disabled by user
boolean strictDMI = true;
if (packageElement.hasAttribute("strict-method-invocation")) {
strictDMI = Boolean.parseBoolean(packageElement.getAttribute("strict-method-invocation"));
}
PackageConfig.Builder cfg = new PackageConfig.Builder(name).namespace(namespace).isAbstract(isAbstract).strictMethodInvocation(strictDMI).location(DomHelper.getLocationObject(packageElement));
if (StringUtils.isNotEmpty(StringUtils.defaultString(parent))) {
// has parents, let's look it up
List<PackageConfig> parents = new ArrayList<>();
for (String parentPackageName : ConfigurationUtil.buildParentListFromString(parent)) {
if (configuration.getPackageConfigNames().contains(parentPackageName)) {
parents.add(configuration.getPackageConfig(parentPackageName));
} else if (declaredPackages.containsKey(parentPackageName)) {
if (configuration.getPackageConfig(parentPackageName) == null) {
addPackage(declaredPackages.get(parentPackageName));
}
parents.add(configuration.getPackageConfig(parentPackageName));
} else {
throw new ConfigurationException("Parent package is not defined: " + parentPackageName);
}
}
if (parents.size() <= 0) {
cfg.needsRefresh(true);
} else {
cfg.addParents(parents);
}
}
return cfg;
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class XmlConfigurationProvider method loadInterceptorStack.
protected InterceptorStackConfig loadInterceptorStack(Element element, PackageConfig.Builder context) throws ConfigurationException {
String name = element.getAttribute("name");
InterceptorStackConfig.Builder config = new InterceptorStackConfig.Builder(name).location(DomHelper.getLocationObject(element));
NodeList interceptorRefList = element.getElementsByTagName("interceptor-ref");
for (int j = 0; j < interceptorRefList.getLength(); j++) {
Element interceptorRefElement = (Element) interceptorRefList.item(j);
List<InterceptorMapping> interceptors = lookupInterceptorReference(context, interceptorRefElement);
config.addInterceptors(interceptors);
}
return config.build();
}
Aggregations