* @param path Path to resolve
* @return Resolved scope
*/
public static IScope resolveScope(IScope from, String path) {
log.debug("resolveScope from: {} path: {}", from.getName(), path);
IScope current = from;
if (path.startsWith(SLASH)) {
current = ScopeUtils.findRoot(current);
path = path.substring(1, path.length());
}
if (path.endsWith(SLASH)) {
path = path.substring(0, path.length() - 1);
}
log.trace("Current: {}", current);
String[] parts = path.split(SLASH);
if (log.isTraceEnabled()) {
log.trace("Parts: {}", Arrays.toString(parts));
}
for (String part : parts) {
log.trace("Part: {}", part);
if (part.equals(".")) {
continue;
}
if (part.equals("..")) {
if (!current.hasParent()) {
return null;
}
current = current.getParent();
continue;
}
if (!current.hasChildScope(part)) {
return null;
}
current = current.getScope(part);
log.trace("Current: {}", current);
}
return current;
}