jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Stuart" <nstu...@speranzasystems.com>
Subject Re: paths
Date Wed, 23 Jul 2008 19:24:48 GMT
Hi Mike, I believe that is true, and I use the hasNode function to do the
functionality you want, and its actually a PathNotFoundException that gets
thrown. I use something like this to check for full paths and create them if
needed:

private Node createFolders(Node parent, String[] folders, int startIndex)
throws Exception {
        checkLocked(parent);
        for (; startIndex < folders.length; startIndex++) {
            String folderName = folders[startIndex];
            parent = parent.addNode(folderName, FOLDER_TYPE);
        }
        return parent;
    }

    private Node getFolderNodeForPath(String folderPath, Node objectNode)
throws Exception {
        String[] folders = folderPath.split("/");
        Node folderNode = objectNode;
        for (int i = 0; i < folders.length; i++) {
            String folderName = folders[i];
            if (StringUtils.isEmpty(folderName)) {
                break;
            }
            if (folderNode.hasNode(folderName)) {
                folderNode = folderNode.getNode(folderName);
            } else {
                folderNode = createFolders(folderNode, folders, i);
                break;
            }
        }

        return folderNode;
    }



On Wed, Jul 23, 2008 at 3:14 PM, Michael Harris <michael.e.harris@gmail.com>
wrote:

> Hello
>
> Can someone confirm or deny the following:  That when a programmer users
>
> getNode(somePath);
>
> that path has to exist or an exception is thrown.  If I want functionality
> that gets or creates if the path doesn't exist I have to implement it
> myself?
>
> thanx
>
> --
> ---------------------
> Michael Harris
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message