publicString directory(String author)
{
StringBuffer treeHtml= newStringBuffer();//得到所有的目录词(包含全部字段)
List words =bdExpandService.getAllWords(author);for (int i = 0; i < words.size(); i++)
{
Tutorial wordMap=words.get(i);//System.out.println(wordMap);
if (wordMap.getPid() == 0)
{
treeHtml.append("
appendTree(words, wordMap, treeHtml);
treeHtml.append("
"); 
 
}
}
words.clear();returntreeHtml.toString();
}/***
* 构造目录树 
*
*@paramtutorials
*@paramtutorial
*@paramtreeHtml
*@see[类、类#方法、类#成员]*/
private void appendTree(Listwords, Tutorial wordMap, StringBuffer treeHtml)
{int tid =wordMap.getTid();//得到根目录的id,根据这个id找到这个的所有子目录
Map map =childTreeHtml(words, tid);
String nodeHtml= map.get("treeHtml").toString();boolean hasChild = Boolean.valueOf(map.get("hasChild").toString());if(hasChild)
{
treeHtml.append("
treeHtml.append("id='tree_dt").append(tid).append("'>");
treeHtml.append(wordMap.getKeyWord()).append("
"); 
 
treeHtml.append(nodeHtml);
}else{
treeHtml.append("
"); 
 
treeHtml.append(wordMap.getKeyWord()).append("
"); 
 
}
}/***
* 得到子目录,构造目录树 
*
*@paramtutorials
*@paramtid
*@return*@see[类、类#方法、类#成员]*/
private Map childTreeHtml(List words, inttid)
{
Map map = new HashMap();
StringBuffer treeHtml= newStringBuffer();boolean hasChild = false;for (int i = 0; i < words.size(); i++)
{
Tutorial wordMap=words.get(i);int pid =wordMap.getPid();if (pid ==tid)
{
hasChild= true;
treeHtml.append("
treeHtml.append("style='display: none;'>").append("
appendTree(words, wordMap, treeHtml);
treeHtml.append("
"); 
 
}
}
map.put("treeHtml", treeHtml);
map.put("hasChild", hasChild);returnmap;
}