protected void checkChildLocation(String pathSegment, FileObject child) throws FileSystemException { if(child == null) { return; } if(!child.getParent().equals(getChildrenLocation())) { throw new IllegalArgumentException( "Path segment " + pathSegment + " results in a path that is not a child of the current node and " + "for security reasons this is forbidden."); } }
protected FileObject getChildLocation(String pathSegment) throws FileSystemException { FileObject child = getChildrenLocation().resolveFile(pathSegment); checkChildLocation(pathSegment, child); return child; }
@Override public Collection<String> getSubResources() { try { List<String> subResources = new ArrayList<>(); FileObject childrenLocation = getChildrenLocation(); if(childrenLocation == null || !childrenLocation.exists() || childrenLocation.getType() != FileType.FOLDER) { return subResources; } FileObject[] children = childrenLocation.getChildren(); for (FileObject child : children) { if (child.getType() == FileType.FOLDER) { subResources.add(child.getName().getBaseName()); } } return subResources; } catch (FileSystemException e) { throw new RuntimeException(e); } }