in src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java [246:352]
private void addByType(Set<String> pathSet, ServiceReference<Servlet> ref) {
String[] types = Converters.standardConverter()
.convert(ref.getProperty(SLING_SERVLET_RESOURCE_TYPES))
.to(String[].class);
String[] paths = Converters.standardConverter()
.convert(ref.getProperty(SLING_SERVLET_PATHS))
.to(String[].class);
boolean hasPathRegistration = true;
if (paths.length == 0) {
hasPathRegistration = false;
}
if (types.length == 0) {
if (log.isDebugEnabled()) {
log.debug("addByType({}): no resource types declared", getServiceReferenceInfo(ref));
}
return;
}
// check for selectors
String[] selectors = Converters.standardConverter()
.convert(ref.getProperty(SLING_SERVLET_SELECTORS))
.to(String[].class);
if (selectors.length == 0) {
selectors = new String[] {null};
}
// we have types and expect extensions and/or methods
String[] extensions = Converters.standardConverter()
.convert(ref.getProperty(SLING_SERVLET_EXTENSIONS))
.to(String[].class);
// handle the methods property specially (SLING-430)
String[] methods = Converters.standardConverter()
.convert(ref.getProperty(SLING_SERVLET_METHODS))
.to(String[].class);
if (methods.length == 0) {
// SLING-512 only, set default methods if no extensions are declared
if (extensions.length == 0 && !hasPathRegistration) {
if (log.isDebugEnabled()) {
log.debug("addByType({}): No methods declared, assuming GET/HEAD", getServiceReferenceInfo(ref));
}
methods = DEFAULT_SERVLET_METHODS;
}
} else if (methods.length == 1 && ALL_METHODS.equals(methods[0])) {
if (log.isDebugEnabled()) {
log.debug("addByType({}): Assuming all methods for '*'", getServiceReferenceInfo(ref));
}
methods = null;
}
for (String type : types) {
// ensure namespace prefixes are converted to slashes
type = ResourceUtil.resourceTypeToPath(type);
// make absolute if relative
if (!type.startsWith("/")) {
type = this.getPrefix(ref) + type;
}
// ensure trailing slash for full path building
if (!type.endsWith("/")) {
type += "/";
}
// add entries for each selector combined with each ext and method
for (String selector : selectors) {
String selPath = type;
if (selector != null && selector.length() > 0) {
selPath += selector.replace('.', '/') + ".";
}
boolean pathAdded = false;
if (extensions.length > 0) {
if (methods != null && methods.length > 0) {
// both methods and extensions declared
for (String ext : extensions) {
for (String method : methods) {
pathSet.add(selPath + ext + "." + method + SERVLET_PATH_EXTENSION);
pathAdded = true;
}
}
} else {
// only extensions declared
for (String ext : extensions) {
pathSet.add(selPath + ext + SERVLET_PATH_EXTENSION);
pathAdded = true;
}
}
} else if (methods != null) {
// only methods declared
for (String method : methods) {
pathSet.add(selPath + method + SERVLET_PATH_EXTENSION);
pathAdded = true;
}
}
// if neither methods nor extensions were added
if (!pathAdded && !hasPathRegistration) {
pathSet.add(selPath.substring(0, selPath.length() - 1) + SERVLET_PATH_EXTENSION);
}
}
}
}