[Yanel-dev] Little correction for VirtualFilesystemNode

Michael Wechner michael.wechner at wyona.com
Tue Apr 12 11:18:39 CEST 2011


Hi Balz

It seems to me that the Javadoc of

src/core/java/org/wyona/yarep/core/Node.java#addNode(String, int)

is pretty clear or please feel free to suggest a better wording.

Re the Virtual Filesystem implementation I would suggest that we check 
the name for slashes
and throw an exception such that it is clear that one should not use the 
method (1) like this.

WDYT?

Thanks

Michael

On 4/11/11 9:32 AM, Balz Schreier wrote:
> Hi,
>
> I have detected the following (at least for me) unexpected behaviour 
> and it should get corrected, the fix is very easy, so I don't send a 
> patch for this.
>
> *Use Case:*
> You have prepared a Yarep path (e.g. 
> "/vouchers/thisisanidstring.xml"), and you want to add this node now 
> to a repository.
>
> *Solution:*
> there are two ways in Yanel how to do that:
> 1) repo.getRootNode().addNode(yarepPath, NodeType.RESOURCE);
>
> 2) YarepUtil.addNodes(repo, yarepPath, NodeType.RESOURCE);
>
> of course, yarepPath = "/vouchers/thisisanidstring.xml" in both scenarios.
>
> Unexpected result:
> 1) Does store the new node under "//vouchers/thisisanidstring.xml", 
> starting with a double slash!! --> Index also contains then that path
> 2) Correct, stores node under "/vouchers/thisisanidstring.xml"
>
>
> *How to fix it:*
>
> Class VirtualFileSystemNode:
>
> Currently this code looks like this:
>
> /**
>
>      * @see org.wyona.yarep.core.Node#addNode(java.lang.String, int)
>
>      */
>
> public Node addNode(String name, int type) throws RepositoryException {
>
>         String newPath = getPath() + "/" + name;
>
> if (getPath().endsWith("/")) {
>
>             newPath = getPath() + name;
>
>         }
>
>
> Corrected code would be:
>
>         String newPath = null;
>
> if (name.startsWith("/")) {
>
>             name = name.substring(1);
>
>         }
>
> if (getPath().endsWith("/")) {
>
>             newPath = getPath() + name;
>
>         } else {
>
>             newPath = getPath() + "/" + name;
>
>         }
>
>
> Alternative:
> If you think that this should not get fixed, I would add a clear 
> Javadoc saying that the "String name" parameter MUST BE RELATIVE.
>
> What do you think?
> Cheers
> Balz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wyona.org/pipermail/yanel-development/attachments/20110412/0bbf8971/attachment.html>


More information about the Yanel-development mailing list