[Yanel-dev] Little correction for VirtualFilesystemNode
Balz Schreier
balz.schreier at gmail.com
Mon Apr 11 09:32:03 CEST 2011
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/20110411/0f0a5d32/attachment.html>
More information about the Yanel-development
mailing list