Given a starting path I want to create a tree like object representing the filesystem using Java, showing all the folders down to level x but not ordinary files. . So using FileVisitor I know that every time just before Im going to browse a new subfolder that the preVisitDirectory() method will be called and once it had completed parsing all its children the postVisitDirectory() will be called, but my problem is knowing how to attach this directory to its parent.
i.e in my case I want to create data for jstree using ul/li/ul/li elements, and Im doing this with j2html lib. So create root using ul(), then when I go into preVisitDirectory() I would create a li() element and in postVisitDirectory() would want to attach to ul() using ul().with(li) but I cant see how to keep track of where I am in building my tree.
e.g static hard coded example not actually browsing tree
public Tag createBrowseTreeAsHtml()
{
Tag ulTag = ul(
li("ChildNode 2").withId("child_node_1"),
li("ChildNode")
);
Tag divTag= div(
ul(
li("Root Node 1").with(ulTag),
li("Root Node 2")
)
)
.withId("jstree");
return div().with(divTag);
}
I see Guava has support for Graphs, should I be utilising this somehow ?