public TreeNode findChildByEncodedName(String encodedName) { String name = encodedName.substring(7, encodedName.length()); List<TreeNodeImpl> lst = childs.get(name); if (lst != null) { for (TreeNode node : lst) { if (node.getName().equals(encodedName)) { return node; } } } return null; }
public boolean remove(String ctxPath) { String[] path = ctxPath.split("/"); boolean result = false; // validate root context if (!("/" + path[1]).startsWith(ContextPath.FILE_CTX_PRX)) { throw new ValidationException("Broken Context Path occurred: FILE CTX Path must be first!"); } else { switch (path.length) { case 0: case 1: throw new ValidationException("Broken Context Path occurred"); case 2: // remove the file and all its children String fileName = path[1].substring(6); FileEntitiesHolder fileHolder = files.remove(fileName); if (fileHolder != null) { fileHolder.removeChildren(); result = true; } break; default: TreeNode parent = root; TreeNode target = null; int i = 2; while (true) { target = parent.findChildByEncodedName("/" + path[i]); if (++i < path.length && target != null) { parent = target; target = null; } else { break; } } if (target != null) { result = parent.removeNodeByEncodedName(target.getName()); } else { // todo -- handle internal error } break; } } // NOTE: do not simplify! modCOunter should be incremented! return result ? ++modCount > 0 : false; }