in plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java [832:898]
protected List<String> determineActionNamespace(Class<?> actionClass) {
List<String> namespaces = new ArrayList<>();
// Check if there is a class or package level annotation for the namespace
//single namespace
Namespace namespaceAnnotation = AnnotationUtils.findAnnotation(actionClass, Namespace.class);
if (namespaceAnnotation != null) {
LOG.trace("Using non-default action namespace from Namespace annotation of [{}]", namespaceAnnotation.value());
namespaces.add(namespaceAnnotation.value());
}
//multiple annotations
Namespaces namespacesAnnotation = AnnotationUtils.findAnnotation(actionClass, Namespaces.class);
if (namespacesAnnotation != null) {
if (LOG.isTraceEnabled()) {
StringBuilder sb = new StringBuilder();
for (Namespace namespace : namespacesAnnotation.value())
sb.append(namespace.value()).append(",");
sb.deleteCharAt(sb.length() - 1);
LOG.trace("Using non-default action namespaces from Namespaces annotation of [{}]", sb.toString());
}
for (Namespace namespace : namespacesAnnotation.value()) {
namespaces.add(namespace.value());
}
}
//don't use default if there are annotations
if (!namespaces.isEmpty())
return namespaces;
String pkg = actionClass.getPackage().getName();
String pkgPart = null;
if (actionPackages != null) {
for (String actionPackage : actionPackages) {
if (pkg.startsWith(actionPackage)) {
pkgPart = actionClass.getName().substring(actionPackage.length() + 1);
}
}
}
if (pkgPart == null && packageLocators != null) {
for (String packageLocator : packageLocators) {
// check subpackage and not a part of package name, eg. actions -> my.actions.transactions - WW-3803
int index = pkg.lastIndexOf("." + packageLocator + ".");
// This ensures that the match is at the end, beginning or has a dot on each side of it
if (index >= 0 && (index + packageLocator.length() == pkg.length() || index == 0 ||
(pkg.charAt(index) == '.' && pkg.charAt(index + 1 + packageLocator.length()) == '.'))) {
pkgPart = actionClass.getName().substring(index + packageLocator.length() + 2);
}
}
}
if (pkgPart != null) {
final int indexOfDot = pkgPart.lastIndexOf('.');
if (indexOfDot >= 0) {
String convertedNamespace = actionNameBuilder.build(pkgPart.substring(0, indexOfDot));
namespaces.add("/" + convertedNamespace.replace('.', '/'));
return namespaces;
}
}
namespaces.add("");
return namespaces;
}