package cn.com.css.misps.onlinegraph.web.action;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.com.css.common.action.BaseAction;
import cn.com.css.misps.onlinegraph.bean.TreeDataBean;
import cn.com.css.misps.onlinegraph.bean.TreeNode;
import cn.com.css.misps.onlinegraph.service.ITreeDataService;
import cn.com.css.misps.onlinegraph.service.impl.TreeDataServiceImpl;
import cn.com.css.misps.onlinegraph.util.ProductsStorageUtils;
/**
* @brief TreeDataAction.java 用于控制左侧的树形结构
* @attention
* @author 涂作权
* @date 2014-2-20
* @note begin modify by null
*/
@SuppressWarnings("serial")
@Scope("prototype")
@Controller
public class TreeDataAction extends BaseAction {
// 根目录的文件结构
private List<TreeNode> treeList;
private String path;
// 文件夹内的文件夹集合
private List<TreeNode> treeNodeList;
/**
* \brief 通过这个方法获得属性结构的json
*
* @return
* @attention 通过这个方法主要是生成树形结构
* @author 涂作权
* @date 2014-2-24
* @note begin modify by null
*/
public String treeNodes() {
treeList = new ArrayList<TreeNode>();
// 获得配置的micaps文件绝对路径
ITreeDataService treeDataService = new TreeDataServiceImpl();
TreeDataBean treeDataBean = treeDataService
.getFileInfo(ProductsStorageUtils.micapsAbsolutePath);
TreeNode treeNode = new TreeNode();
treeNode.setId(treeDataBean.getFilePath());
treeNode.setText(treeDataBean.getFileName());
treeNode.setChildren(new ArrayList<TreeNode>());
if (treeDataBean.getInnerFileNum() > 0) {
treeNode.setState("closed");
}
treeList.add(treeNode);
return "treeNodes";
}
/**
* \brief 通过这个方法可以得到指定节点下含有的树集合
*
* @return
* @attention
* @author 涂作权
* @date 2014-2-24
* @note begin modify by null
*/
public String treeNodeList() {
treeNodeList = new ArrayList<TreeNode>();
ITreeDataService treeDataService = new TreeDataServiceImpl();
// 要注意的是这里的id值不是数值,而是一个路径值。应为每个文件所在的路径肯定是唯一的
List<TreeDataBean> treeDataBeans = treeDataService.getFoldersList(path);
// 将这里的面的是文件夹的现在树形结构中
for (TreeDataBean treeDataBean : treeDataBeans) {
if (treeDataBean.getInnerFileNum() > 0) {
TreeNode treeNode = new TreeNode();
treeNode.setId(treeDataBean.getFilePath());
treeNode.setText(treeDataBean.getFileName());
treeNode.setChildren(new ArrayList<TreeNode>());
treeNode.setState("closed");
treeNodeList.add(treeNode);
}
}
return "treeNodeList";
}
/**
* @return the treeList
*/
public List<TreeNode> getTreeList() {
return treeList;
}
/**
* @param treeList the treeList to set
*/
public void setTreeList(List<TreeNode> treeList) {
this.treeList = treeList;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the treeNodeList
*/
public List<TreeNode> getTreeNodeList() {
return treeNodeList;
}
/**
* @param treeNodeList the treeNodeList to set
*/
public void setTreeNodeList(List<TreeNode> treeNodeList) {
this.treeNodeList = treeNodeList;
}
}
package cn.com.css.misps.onlinegraph.web.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.com.css.common.action.BaseAction;
import cn.com.css.misps.onlinegraph.bean.TreeDataBean;
import cn.com.css.misps.onlinegraph.service.ITreeDataService;
import cn.com.css.misps.onlinegraph.service.impl.TreeDataServiceImpl;
import cn.com.css.misps.onlinegraph.util.ProductsStorageUtils;
/**
* @brief FileInfoAction.java 通过这个类查看文件夹下的文件信息
* @attention
* @author 涂作权
* @date 2014-2-25
* @note begin modify by null
*/
@SuppressWarnings("serial")
@Scope("prototype")
@Controller
public class FileInfoAction extends BaseAction {
private static int Num = 10;
private int total;
private List<Object> rows;
private String path;
/**
* \brief 根目录文件信息
*
* @return
* @attention
* @author 涂作权
* @date 2014-2-25
* @note begin modify by null
*/
public String rootFolderFileInfo() {
this.rows = new ArrayList<Object>();
ITreeDataService treeDataService = new TreeDataServiceImpl();
// 如果path为空,显示的是根目录的文件信息
List<TreeDataBean> list = treeDataService.getAllFileList(ProductsStorageUtils.micapsAbsolutePath);
//注意要将rows的内容放到map集合中
for (int i = 0; i < list.size(); i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("fileName", list.get(i).getFileName());
map.put("filePath", list.get(i).getFilePath());
map.put("lastModified", list.get(i).getLastModified());
map.put("fileType", list.get(i).getFileType());
map.put("fileSize", list.get(i).getFileSize());
rows.add(map);
}
//这里表示的是总条数
this.total = rows.size();
return SUCCESS;
}
/**
* \brief 通过此方法返回指定文件夹下的文件信息
*
* @return
* @attention
* @author 涂作权
* @date 2014-2-25
* @note begin modify by null
*/
// public String folderFileInfoList() {
// rows = new ArrayList<Object>();
// ITreeDataService treeDataService = new TreeDataServiceImpl();
//
// // 如果path为空,显示的是根目录的文件信息
// rows = treeDataService.getAllFileList(path);
//
// total = rows.size();
//
// return "folderFileInfoList";
// }
/**
* @return the num
*/
public static int getNum() {
return Num;
}
/**
* @param num the num to set
*/
public static void setNum(int num) {
Num = num;
}
/**
* @return the total
*/
public int getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(int total) {
this.total = total;
}
/**
* @return the rows
*/
public List<Object> getRows() {
return rows;
}
/**
* @param rows the rows to set
*/
public void setRows(List<Object> rows) {
this.rows = rows;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
// //文件记录数
// private Integer total = 0;
// // 指定文件下的文件信息
// private List<TreeDataBean> rows;
// //文件夹路径
// private String path;
//
// /**
// * \brief 根目录文件信息
// *
// * @return
// * @attention
// * @author 涂作权
// * @date 2014-2-25
// * @note begin modify by null
// */
// public String rootFolderFileInfo() {
// rows = new ArrayList<TreeDataBean>();
// ITreeDataService treeDataService = new TreeDataServiceImpl();
//
// // 如果path为空,显示的是根目录的文件信息
// rows = treeDataService
// .getAllFileList(ProductsStorageUtils.micapsAbsolutePath);
//
// total = rows.size();
//
// return "rootFolderFileInfo";
// }
//
// /**
// * \brief 通过此方法返回指定文件夹下的文件信息
// *
// * @return
// * @attention
// * @author 涂作权
// * @date 2014-2-25
// * @note begin modify by null
// */
// public String folderFileInfoList() {
// rows = new ArrayList<TreeDataBean>();
// ITreeDataService treeDataService = new TreeDataServiceImpl();
//
// // 如果path为空,显示的是根目录的文件信息
// rows = treeDataService.getAllFileList(path);
//
// total = rows.size();
//
// return "folderFileInfoList";
// }
//
// /**
// * @return the total
// */
// public Integer getTotal() {
// return total;
// }
//
// /**
// * @param total the total to set
// */
//
// public void setTotal(Integer total) {
// this.total = total;
// }
//
// /**
// * @return the rows
// */
// public List<TreeDataBean> getRows() {
// return rows;
// }
//
// /**
// * @param rows the rows to set
// */
//
// public void setRows(List<TreeDataBean> rows) {
// this.rows = rows;
// }
//
// /**
// * @return the path
// */
// public String getPath() {
// return path;
// }
//
// /**
// * @param path the path to set
// */
//
// public void setPath(String path) {
// this.path = path;
// }
}
对应配置:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="system_onlinegraph" namespace="/onlinegraph" extends="global-struts-default">
<action name="onlinegraph_*" class="cn.com.css.misps.onlinegraph.web.action.OnlineGraphAction" method="{1}">
<result name="onLineGraphUI">/portal/graph_online.jsp</result>
<result name="generateGraph">/portal/graph_online.jsp</result>
<result name="onLineGraph">/portal/extras/serviceForm.jsp</result>
<result name="SUCCESS" type="json"></result>
<result name="treeProducts">/portal/extras/treeProducts.jsp</result>
<result name="ERROR" type="json"></result>
</action>
<action name="treeDataAction_*" class="cn.com.css.misps.onlinegraph.web.action.TreeDataAction" method="{1}">
<result name="treeNodes" type="json">
<param name="root">treeList</param>
</result>
<result name="treeNodeList" type="json">
<param name="root">treeNodeList</param>
</result>
</action>
<action name="fileInfoAction_*" class="cn.com.css.misps.onlinegraph.web.action.FileInfoAction" method="{1}">
<result type="json"></result>
</action>
</package>
</struts>
可参考的配置:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="system_onlinegraph" namespace="/onlinegraph" extends="global-struts-default">
<action name="onlinegraph_*" class="cn.com.css.misps.onlinegraph.web.action.OnlineGraphAction" method="{1}">
<result name="onLineGraphUI">/portal/graph_online.jsp</result>
<result name="generateGraph">/portal/graph_online.jsp</result>
<result name="onLineGraph">/portal/extras/serviceForm.jsp</result>
<result name="SUCCESS" type="json"></result>
<result name="treeProducts">/portal/extras/treeProducts.jsp</result>
<result name="ERROR" type="json"></result>
</action>
<action name="treeDataAction_*" class="cn.com.css.misps.onlinegraph.web.action.TreeDataAction" method="{1}">
<result name="treeNodes" type="json">
<param name="root">treeList</param>
</result>
<result name="treeNodeList" type="json">
<param name="root">treeNodeList</param>
</result>
</action>
<action name="fileInfoAction_*" class="cn.com.css.misps.onlinegraph.web.action.FileInfoAction" method="{1}">
<result name="rootFolderFileInfo" type="json">
<param name="excludeProperties">path,rows\[\d+\]\.innerFileNum,rows\[\d+\]\.parentPath</param>
</result>
<result name="folderFileInfoList" type="json">
<param name="excludeProperties">path,rows\[\d+\]\.innerFileNum,rows\[\d+\]\.parentPath</param>
</result>
</action>
</package>
</struts>