if(reachable)
{
level++;
NodeContainer nc = new NodeContainer();
//** selected link/filtering **
Set<List<String>> newPathsToUri = pathsToUri;
if(pathsToUri!=null)
{
//check if node is on one of the paths in pathsToUri - if yes cut off this path
for(List<String> path:pathsToUri)
{
if(!path.isEmpty())
if(path.get(0).equals(resource.getStringURI()))
{
onPath = true;
break;
}
}
//if the current node is on some path - rewrite the list, and remove current node from it.
if(onPath)
{
newPathsToUri = new HashSet<List<String>>();
for(List<String> path:pathsToUri)
{
if(!path.isEmpty())
if(path.get(0).equals(resource.getStringURI()))
{
path.remove(0);
}
if(!path.isEmpty())
{
newPathsToUri.add(path);
}
}
}
}
//need to think some more wise way to tell when script should stop go deeper
//FIXME: del.icio.us would be always dynamic!
if(level>=maxAbsoluteLevel&&hasContent&&!onPath) {
isDyn = true;
}
nc.setDyn(isDyn);
//special case for filtering and user's own directory. there is no need to generate elements
//that has been already generated.
//maxAbsoluteLevel==0 means that there is filtering mode enabled
boolean isSelected = false;
if(selectedUri!=null&&!"".equals(selectedUri.trim())) {
isSelected = (resource.getStringURI().equals(selectedUri));
if(!isSelected&&selectedUri.length()>40)
isSelected = resource.getStringURI().endsWith(selectedUri.substring(selectedUri.length()-40,selectedUri.length()));
}
if(maxAbsoluteLevel!=0||onPath||isSelected||!isOwner)
{
if(isDiu)
{
nc.setType("diuDirectory");
if(onPath)
{
isDyn = false;
nc.setDyn(isDyn);
}
DirectoryNode dn = new DirectoryNode();
dn.setId(resource.getResource().toString());
dn.setLevel(level);
String label = resource.getStringURI();
if(label.length()>9)
label = label.substring(0,label.length()-9);
dn.setLabel(label+" bookmarks");
dn.setOwn(isOwner);
dn.setOwnerMbox((issuer != null) ? (issuer.getId()) : "");
dn.setOwnerName((issuer != null) ? (issuer.getName()) : "");
dn.setRemovable(!hasContent);
dn.setLinkedIn(parentIsOwner&!isOwner);
dn.setOpened(onPath);
dn.setStandalone(standalone);
nc.setContent(dn);
}
//normal directory
else if(isDir&&!isSuggested)
{
nc.setType("directory");
DirectoryNode dn = new DirectoryNode();
dn.setId(resource.getResource().toString());
dn.setLevel(level);
if(resource.getLabel().contains("\"")||resource.getLabel().contains("'"))
{
dn.setLabel("bleble "+resource.getLabel().replace("\"", "\\\"").replace("'","\\'"));
}
else if(resource.getLabel().trim().equals(""))
{
dn.setLabel(resource.getStringURI());
}
else
{
dn.setLabel(resource.getLabel());
}
dn.setOwn(isOwner);
dn.setOwnerMbox((issuer != null) ? (issuer.getId()) : "");
dn.setOwnerName((issuer != null) ? (issuer.getName()) : "");
dn.setRemovable(!hasContent);
dn.setLinkedIn(parentIsOwner&!isOwner);
dn.setOpened(onPath);
//check if user select this directory - we can get id or whole uri.
if(isSelected)
{
dn.setSelected(true);
dn.setOpened(false);
}
else dn.setSelected(false);
dn.setStandalone(standalone);
nc.setContent(dn);
}
//suggested directory
else if(isDir&&isSuggested)
{
nc.setType("sugDirectory");
SugDirectoryNode sdn = new SugDirectoryNode();
sdn.setId(resource.getResource().toString());
sdn.setLevel(level);
sdn.setLabel(resource.getLabel());
sdn.setOwnerMbox((issuer != null) ? (issuer.getId()) : "");
sdn.setOwnerName((issuer != null) ? (issuer.getName()) : "");
sdn.setOpened(onPath);
//check if user select this directory - we can get id or whole uri.
if(isSelected)
{
sdn.setSelected(true);
sdn.setOpened(false);
}
else sdn.setSelected(false);
sdn.setStandalone(standalone);
nc.setContent(sdn);
}
//bookmark
else
{
nc.setType("bookmark");
BookmarkNode bn = new BookmarkNode();
ResourceWrapper bookRes = new ResourceWrapper(resource,serviceAddr,true);
bn.setId(resource.getResource().toString());
if (bookRes.getAuthors() != null && bookRes.getTitle() != null) {
bn.setLabel("<i>[" + bookRes.getAuthors() + "]</i> " + bookRes.getTitle());
} else {
//TODO: temporarly switched of to get some efficiency - will be substituted with - "fetch details" button
if(resource.getLabel().contains("\"")||resource.getLabel().contains("'"))
bn.setLabel(resource.getLabel().replace("\"", "\\\"").replace("'", "\\'"));
else
bn.setLabel(resource.getLabel()!=null&&!"".equals(resource.getLabel())?resource.getLabel(): resource.getResource().toString());
}
//check if this bookmark is selected this directory
if(isSelected)
{
bn.setSelected(true);
}
else bn.setSelected(false);
bn.setHits(resource.getResourceHits());
bn.setLevel(level);
bn.setOwn(parentIsOwner);
bn.setStandalone(standalone);
nc.setContent(bn);
}
//add created nodes to the buffer
if(reachable)
nc.toJSON(buffer);
}
//proceed the content of this resource
if (hasContent&&reachable&&!isDyn) {
//parentIsOwner = isOwner;