// I. Generate list of parent dirs for this directory
//
List<DirLabelPair> parentDirPairList = new ArrayList<DirLabelPair>();
List<FileSummary> parentDirList = fe.getDirParents(targetDir);
FileSummary lastDir = null;
if (parentDirList != null) {
for (FileSummary curDirSummary: parentDirList) {
Path curDir = curDirSummary.getPath();
String prefix = "";
if (lastDir != null) {
prefix = lastDir.getPath().toString();
}
String label = curDir.toString().substring(prefix.length());
// Check rights
if (accessCtrl.hasReadAccess(curDirSummary)) {
String dirUrl = urlFor(FilesPage.class, new PageParameters("targetdir=" + curDir.toString())).toString();
label = "<a href=\"" + dirUrl + "\">" + label + "</a>";
}
parentDirPairList.add(new DirLabelPair(label, curDir));
lastDir = curDirSummary;
}
}
String targetDirLabel = targetDir.substring(lastDir == null ? 0 : lastDir.getPath().toString().length());
parentDirPairList.add(new DirLabelPair(targetDirLabel, new Path(targetDir)));
add(new Label("lastParentDirEntry", parentDirPairList.get(parentDirPairList.size()-1).getLabel()));
parentDirPairList.remove(parentDirPairList.size()-1);
add(new ListView<DirLabelPair>("parentdirlisting", parentDirPairList) {
protected void populateItem(ListItem<DirLabelPair> item) {
DirLabelPair pair = item.getModelObject();
item.add(new Label("dirlabel", pair.getLabel()).setEscapeModelStrings(false));
}
});
//
// II. Generate list of subdirs in the directory
//
final List<DirLabelPair> childDirPairList = new ArrayList<DirLabelPair>();
List<FileSummary> childDirList = fe.getDirChildren(targetDir);
if (childDirList != null) {
for (FileSummary curDirSummary: childDirList) {
String label = curDirSummary.getFname();
if (accessCtrl.hasReadAccess(curDirSummary)) {
String dirUrl = urlFor(FilesPage.class, new PageParameters("targetdir=" + curDirSummary.getPath().toString())).toString();
label = "<a href=\"" + dirUrl + "\">" + label + "</a>";
}
childDirPairList.add(new DirLabelPair(label, curDirSummary.getPath()));
}
}
add(new WebMarkupContainer("subdirbox") {
{
add(new ListView<DirLabelPair>("childdirlisting", childDirPairList) {
protected void populateItem(ListItem<DirLabelPair> item) {
DirLabelPair pair = item.getModelObject();
item.add(new Label("childdirlabel", pair.getLabel()).setEscapeModelStrings(false));
}
});
setOutputMarkupPlaceholderTag(true);
setVisibilityAllowed(false);
}
public void onConfigure() {
setVisibilityAllowed(childDirPairList.size() > 0);
}
});
//
// III. Generate list of files in the directory
//
List<FileSummary> filelist = FishEye.getInstance().getAnalyzer().getPrecachedFileSummariesInDir(false, targetDir);
add(new Label("numFisheyeFiles", "" + filelist.size()));
add(new ListView<FileSummary>("filelisting", filelist) {
protected void populateItem(ListItem<FileSummary> item) {
long start = System.currentTimeMillis();
FileSummary fs = item.getModelObject();
// 1. Filename. Link is conditional on having read access
if (accessCtrl.hasReadAccess(fs)) {
String fileUrl = urlFor(FilePage.class, new PageParameters("fid=" + fs.getFid())).toString();
item.add(new Label("filelabel", "<a href=\"" + fileUrl + "\">" + fs.getFname() + "</a>").setEscapeModelStrings(false));
} else {
item.add(new Label("filelabel", fs.getFname()));
}
// 2-5. A bunch of fields that get added no matter what the user's access rights.
item.add(new Label("sizelabel", "" + fs.getSize()));
item.add(new Label("ownerlabel", fs.getOwner()));
item.add(new Label("grouplabel", fs.getGroup()));
item.add(new Label("permissionslabel", fs.getPermissions().toString()));
// 6-7. Fields that have link conditional on read access AND the existence of relevant info.
if (accessCtrl.hasReadAccess(fs)) {
List<TypeGuessSummary> tgs = fs.getTypeGuesses();
if (tgs.size() > 0) {
TypeSummary ts = tgs.get(0).getTypeSummary();
SchemaSummary ss = tgs.get(0).getSchemaSummary();
String typeUrl = urlFor(FiletypePage.class, new PageParameters("typeid=" + ts.getTypeId())).toString();