公共类 FileDAO 扩展 DaoBase 实现 ITreeDao {
File rootDirectory = null;
public FileDAO(File rootDirectory) {
if(!rootDirectory.exists()){
throw new IllegalArgumentException("Directory " + rootDirectory.getAbsolutePath() + " doesn't exist");
}
this.rootDirectory = rootDirectory;
}
protected ITreeNode readRoot(ITree tree) {
tree.setRoot(readNode(this.rootDirectory));
TreeSorter.sortById(tree.getRoot());
return tree.getRoot();
}
protected Set readChildren(ITreeNode parentNode) {
Set children = new HashSet();
File parentDir = (File) parentNode.getObject();
String[] files = parentDir.list();
if(files == null) return children;
for(int i=0; i<files.length; i++){
File childFile = new File(parentDir.getAbsolutePath() + File.separator + files[i]);
ITreeNode child = readNode(childFile);
child.setParentId(parentNode.getId());
if(!childFile.exists()) continue;
children.add(child);
}
// Sort here
TreeSorter.sortById(parentNode);
return children;
}
protected Set readGrandChildren(ITreeNode parentNode) {
Set grandChildren = new HashSet();
Iterator children = parentNode.getChildren().iterator();
while(children.hasNext()){
ITreeNode child = (ITreeNode) children.next();
grandChildren.addAll(readChildren(child));
}
return grandChildren;
}
protected ITreeNode readNode(File file){
if(!file.exists()) return null;
ITreeNode node = null;
String childType = file.isDirectory() ? "directory" : "file";
if(childType.equals("file")){
node = new TreeNode(file.getAbsolutePath(), "<a href=\"openPdf.jsp?fileName=" + file.getAbsolutePath() + "\" target=_blank>" + file.getName() + "</a>" , childType);
}else{
node = new TreeNode(file.getAbsolutePath(), file.getName() , childType);
}
node.setObject(file);
return node;
}
}
在这段代码中,我在readGrandChildren()方法上面临一个问题。就像那里我得到日历月份的升序,但我想显示日历顺序,如 Jan、Feb、Mar.....Dec。
请任何人都可以帮助我吗?
回首忆惘然
相关分类