lineNumber++;
line = line.trim().replaceAll("\\s+", " ");
if (line.length() == 0 || line.startsWith("#")) {
continue;
}
Matcher matcher = routePattern.matcher(line);
if (matcher.matches()) {
String action = matcher.group("action");
// module:
if (action.startsWith("module:")) {
String moduleName = action.substring("module:".length());
String newPrefix = prefix + matcher.group("path");
if (newPrefix.length() > 1 && newPrefix.endsWith("/")) {
newPrefix = newPrefix.substring(0, newPrefix.length() - 1);
}
if (moduleName.equals("*")) {
for (String p : Yalp.modulesRoutes.keySet()) {
parse(Yalp.modulesRoutes.get(p), newPrefix + p);
}
} else if (Yalp.modulesRoutes.containsKey(moduleName)) {
parse(Yalp.modulesRoutes.get(moduleName), newPrefix);
} else {
Logger.error("Cannot include routes for module %s (not found)", moduleName);
}
} else {
String method = matcher.group("method");
String path = prefix + matcher.group("path");
String params = matcher.group("params");
String headers = matcher.group("headers");
appendRoute(method, path, action, params, headers, fileAbsolutePath, lineNumber);
}
} else {
Logger.error("Invalid route definition : %s", line);
}