mirror of https://github.com/Rekoe/rk_svnadmin
add
parent
8d8f6b625d
commit
343203e638
|
@ -15,7 +15,9 @@ import org.nutz.mvc.NutConfig;
|
|||
import org.nutz.mvc.Setup;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
|
||||
import com.rekoe.domain.Pj;
|
||||
import com.rekoe.domain.User;
|
||||
import com.rekoe.domain.Usr;
|
||||
import com.rekoe.service.UserService;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
|
@ -43,6 +45,8 @@ public class MvcSetup implements Setup {
|
|||
Dao dao = ioc.get(Dao.class);
|
||||
// dao.clear(OAuthUser.class);
|
||||
Daos.createTablesInPackage(dao, User.class.getPackage().getName(), false);
|
||||
Daos.migration(dao, Usr.class, true, true, false);
|
||||
Daos.migration(dao, Pj.class, true, true, false);
|
||||
if (0 == dao.count(User.class)) {
|
||||
FileSqlManager fm = new FileSqlManager("init_system_h2.sql");
|
||||
List<Sql> sqlList = fm.createCombo(fm.keys());
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ajax服务层返回的结果
|
||||
*/
|
||||
public class Ajax implements Serializable{
|
||||
/**
|
||||
* 序列化ID
|
||||
*/
|
||||
private static final long serialVersionUID = -545103916156321718L;
|
||||
/**
|
||||
* content type
|
||||
*/
|
||||
private String contentType;
|
||||
/**
|
||||
* 结果
|
||||
*/
|
||||
private String result;
|
||||
|
||||
/**
|
||||
* 默认构造函数
|
||||
*/
|
||||
public Ajax() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param contentType content type
|
||||
* @param result 结果
|
||||
*/
|
||||
public Ajax(String contentType,String result){
|
||||
this.contentType=contentType;
|
||||
this.result=result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return content type
|
||||
*/
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
/**
|
||||
* @param contentType content type
|
||||
*/
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
/**
|
||||
* @return 结果
|
||||
*/
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param result 结果
|
||||
*/
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
|
@ -5,12 +5,14 @@ import java.net.URLDecoder;
|
|||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
@ -21,11 +23,13 @@ import com.rekoe.common.page.Pagination;
|
|||
import com.rekoe.domain.Pj;
|
||||
import com.rekoe.domain.PjAuth;
|
||||
import com.rekoe.module.BaseAction;
|
||||
import com.rekoe.service.DefaultTreeService;
|
||||
import com.rekoe.service.ProjectAuthService;
|
||||
import com.rekoe.service.ProjectGroupService;
|
||||
import com.rekoe.service.ProjectService;
|
||||
import com.rekoe.service.RepositoryService;
|
||||
import com.rekoe.service.UsrService;
|
||||
import com.rekoe.utils.CommonUtils;
|
||||
import com.rekoe.utils.UsrProvider;
|
||||
|
||||
@IocBean
|
||||
|
@ -100,10 +104,10 @@ public class AdminProjectAct extends BaseAction {
|
|||
|
||||
@Inject
|
||||
private ProjectGroupService projectGroupService;
|
||||
|
||||
|
||||
@Inject
|
||||
private UsrService usrService;
|
||||
|
||||
|
||||
@At
|
||||
@Ok("fm:template.admin.project.pjauth")
|
||||
@RequiresPermissions({ "svn.project:view" })
|
||||
|
@ -129,8 +133,23 @@ public class AdminProjectAct extends BaseAction {
|
|||
req.setAttribute("list", list);
|
||||
req.setAttribute("pj", pj);
|
||||
req.setAttribute("pjreslist", projectAuthService.getResList(pj));
|
||||
req.setAttribute("pjgrlist",projectGroupService.getList(pj));
|
||||
req.setAttribute("pjgrlist", projectGroupService.getList(pj));
|
||||
req.setAttribute("usrList", usrService.getList());
|
||||
return pj;
|
||||
}
|
||||
|
||||
@Inject
|
||||
private DefaultTreeService treeService;
|
||||
|
||||
@At
|
||||
@Ok("raw")
|
||||
@RequiresPermissions({ "svn.project:view" })
|
||||
public String ajaxTreeService(HttpServletRequest req, HttpServletResponse response) {
|
||||
NutMap params = CommonUtils.getRequestParametersMap(req);
|
||||
com.rekoe.domain.Ajax ajax = treeService.execute(params);
|
||||
if (ajax != null) {
|
||||
return ajax.getResult();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.rekoe.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* ajax服务层接口
|
||||
*/
|
||||
public interface AjaxService {
|
||||
/**
|
||||
* html
|
||||
*/
|
||||
public static final String CONTENTTYPE_HTML="text/html; charset=UTF-8";
|
||||
/**
|
||||
* xml
|
||||
*/
|
||||
public static final String CONTENTTYPE_XML="text/xml; charset=UTF-8";
|
||||
/**
|
||||
* json
|
||||
*/
|
||||
public static final String CONTENTTYPE_JSON="application/json; charset=UTF-8";
|
||||
/**
|
||||
* javascript
|
||||
*/
|
||||
public static final String CONTENTTYPE_JAVASCRIPT="text/javascript; charset=UTF-8";
|
||||
/**
|
||||
* text
|
||||
*/
|
||||
public static final String CONTENTTYPE_TEXT="text/plain; charset=UTF-8";
|
||||
|
||||
/**
|
||||
* 执行逻辑
|
||||
* @param parameters 参数
|
||||
* @return 结果
|
||||
*/
|
||||
com.rekoe.domain.Ajax execute(Map<String,Object> parameters);
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.rekoe.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.rekoe.tree.entity.Tree;
|
||||
import com.rekoe.tree.service.TreeFactory;
|
||||
|
||||
|
||||
/**
|
||||
* 默认的树工厂类
|
||||
*
|
||||
*/
|
||||
@IocBean
|
||||
public class DefaultTreeFactory implements TreeFactory {
|
||||
|
||||
public Tree find(String id) {
|
||||
for(Tree tree:datas){
|
||||
if(tree.getId().equals(id)){
|
||||
//要给leaf设值
|
||||
if(tree.getId().equals(tree.getParentId())){
|
||||
tree.setLeaf(false);
|
||||
}else{
|
||||
tree.setLeaf(findChildren(tree.getId()).size()==0);
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Tree> findChildren(String parentId) {
|
||||
List<Tree> results = new ArrayList<Tree>();
|
||||
for(Tree tree:datas){
|
||||
if(parentId.equals(tree.getParentId())){
|
||||
//要给leaf设值
|
||||
if(tree.getId().equals(tree.getParentId())){
|
||||
tree.setLeaf(false);
|
||||
results.add(tree);
|
||||
return results;
|
||||
}else{
|
||||
tree.setLeaf(findChildren(tree.getId()).size()==0);
|
||||
results.add(tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static List<Tree> datas = new ArrayList<Tree>();
|
||||
static{
|
||||
/*
|
||||
* rep
|
||||
* |rep
|
||||
* | |rep
|
||||
* | |rep
|
||||
* |rep
|
||||
* |
|
||||
* rep
|
||||
* |
|
||||
*/
|
||||
datas.add(new Tree("rep","rep"));
|
||||
/*
|
||||
* com
|
||||
* |_dept
|
||||
* | |_dept user
|
||||
* | |_dept user
|
||||
* |_dept
|
||||
* |_com user
|
||||
* |_com user
|
||||
*
|
||||
*/
|
||||
// datas.add(new Tree("com",null));
|
||||
|
||||
// datas.add(new Tree("dept","com"));
|
||||
// datas.add(new Tree("user","com"));
|
||||
|
||||
// datas.add(new Tree("user","dept"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.rekoe.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.rekoe.tree.service.AbstractTreeService;
|
||||
|
||||
/**
|
||||
* 默认的树服务层
|
||||
*
|
||||
*/
|
||||
@IocBean(name = "treeService")
|
||||
public class DefaultTreeService extends AbstractTreeService implements AjaxService {
|
||||
|
||||
|
||||
public com.rekoe.domain.Ajax execute(Map<String, Object> parameters) {
|
||||
com.rekoe.domain.Ajax result = new com.rekoe.domain.Ajax();
|
||||
result.setContentType(CONTENTTYPE_HTML);
|
||||
result.setResult(this.getHTML(parameters));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -127,6 +127,7 @@ public class ProjectAuthService extends BaseService<PjAuth> {
|
|||
return list;
|
||||
}
|
||||
});
|
||||
dao().execute(sql);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.rekoe.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.tmatesoft.svn.core.SVNDirEntry;
|
||||
import org.tmatesoft.svn.core.SVNNodeKind;
|
||||
|
||||
import com.rekoe.tree.entity.Tree;
|
||||
import com.rekoe.tree.entity.TreeNode;
|
||||
import com.rekoe.tree.service.AbstractTreeNodeService;
|
||||
|
||||
/**
|
||||
* 仓库目录结构树节点服务层
|
||||
*
|
||||
*/
|
||||
@IocBean
|
||||
public class RepTreeNodeService extends AbstractTreeNodeService {
|
||||
|
||||
private static final String AND = "$AND$";
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private final Log LOG = Logs.get();
|
||||
|
||||
/**
|
||||
* 仓库服务层
|
||||
*/
|
||||
@Inject
|
||||
RepositoryService repositoryService;
|
||||
|
||||
@Override
|
||||
protected List<TreeNode> getTreeNodes(Tree parent, Map<String, Object> parameters) {
|
||||
List<TreeNode> results = new ArrayList<TreeNode>();
|
||||
String pj = (String) parameters.get("pj");
|
||||
String path = (String) parameters.get("path");
|
||||
path = StringUtils.replace(path, AND, "&");
|
||||
if (StringUtils.isBlank(pj)) {
|
||||
LOG.warn("pj id is blank ");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Collection<SVNDirEntry> entries = this.repositoryService.getDir(pj, path);
|
||||
if (entries == null) {
|
||||
return null;
|
||||
}
|
||||
for (SVNDirEntry svnDirEntry : entries) {
|
||||
TreeNode treeNode = new TreeNode(svnDirEntry.getName());
|
||||
treeNode.setLeaf(SVNNodeKind.FILE.equals(svnDirEntry.getKind()));// 叶子?
|
||||
treeNode.addParamete("pj", pj);
|
||||
if (path.endsWith("/")) {
|
||||
treeNode.addParamete("path", path + StringUtils.replace(svnDirEntry.getName(), "&", AND));
|
||||
} else {
|
||||
treeNode.addParamete("path", path + "/" + StringUtils.replace(svnDirEntry.getName(), "&", AND));
|
||||
}
|
||||
results.add(treeNode);
|
||||
}
|
||||
Collections.sort(results);// 排序
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
results.clear();
|
||||
TreeNode errorNode = new TreeNode(e.getMessage());
|
||||
errorNode.setLeaf(true);
|
||||
results.add(errorNode);
|
||||
return results;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.rekoe.tree.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 树
|
||||
*/
|
||||
public class Tree implements Serializable {
|
||||
/**
|
||||
* 序列化ID
|
||||
*/
|
||||
private static final long serialVersionUID = -785319127620330061L;
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* 父节点ID
|
||||
*/
|
||||
private String parentId;
|
||||
/**
|
||||
* 是否是叶子
|
||||
*/
|
||||
private boolean leaf;
|
||||
|
||||
/**
|
||||
* 默认构造函数
|
||||
*/
|
||||
public Tree() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param id
|
||||
* ID
|
||||
* @param parentId
|
||||
* 父节点ID
|
||||
* @param treeNodeService
|
||||
* 节点服务层
|
||||
*/
|
||||
public Tree(String id, String parentId) {
|
||||
this.id = id;
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ID
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* ID
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 父节点ID
|
||||
*/
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parentId
|
||||
* 父节点ID
|
||||
*/
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否是叶子
|
||||
*/
|
||||
public boolean isLeaf() {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param leaf
|
||||
* 是否是叶子
|
||||
*/
|
||||
public void setLeaf(boolean leaf) {
|
||||
this.leaf = leaf;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,214 @@
|
|||
package com.rekoe.tree.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* 树节点
|
||||
*/
|
||||
public class TreeNode implements Comparable<TreeNode>,Serializable{
|
||||
/**
|
||||
* 序列化ID
|
||||
*/
|
||||
private static final long serialVersionUID = -2006855434442859723L;
|
||||
/**
|
||||
* 节点显示的文字
|
||||
*/
|
||||
private String text;
|
||||
/**
|
||||
* 点击节点时的url链接
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 是否是叶子
|
||||
*/
|
||||
private boolean leaf;
|
||||
/**
|
||||
* 父节点
|
||||
*/
|
||||
private TreeNode parent;
|
||||
|
||||
/**
|
||||
* 叶子
|
||||
*/
|
||||
private List<TreeNode> children;
|
||||
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private Map<String,String> parameters;
|
||||
/**
|
||||
* 属性
|
||||
*/
|
||||
private Map<String,String> attributes;
|
||||
|
||||
/**
|
||||
* 默认构造函数
|
||||
*/
|
||||
public TreeNode() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param text 节点显示的文字
|
||||
*/
|
||||
public TreeNode(String text){
|
||||
this.text=text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 父节点
|
||||
*/
|
||||
public TreeNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent 父节点
|
||||
*/
|
||||
public void setParent(TreeNode parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 叶子
|
||||
*/
|
||||
public List<TreeNode> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param children 叶子
|
||||
*/
|
||||
public void setChildren(List<TreeNode> children) {
|
||||
if(children !=null){
|
||||
for (TreeNode treeNode : children) {
|
||||
treeNode.setParent(this);
|
||||
}
|
||||
}
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否是叶子
|
||||
*/
|
||||
public boolean isLeaf() {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param leaf 是否是叶子
|
||||
*/
|
||||
public void setLeaf(boolean leaf) {
|
||||
this.leaf = leaf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 参数
|
||||
*/
|
||||
public Map<String, String> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameters 参数
|
||||
*/
|
||||
public void setParameters(Map<String, String> parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 属性
|
||||
*/
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attributes 属性
|
||||
*/
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加一个参数
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public void addParamete(String key,String value){
|
||||
if(parameters == null){
|
||||
parameters = new HashMap<String,String>();
|
||||
}
|
||||
parameters.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加一个属性
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public void addAttribute(String key,String value){
|
||||
if(attributes == null){
|
||||
attributes = new HashMap<String,String>();
|
||||
}
|
||||
attributes.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 节点显示的文字
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text 节点显示的文字
|
||||
*/
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 点击节点时的url链接
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url 点击节点时的url链接
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int compareTo(TreeNode o) {
|
||||
if(this.isLeaf()){
|
||||
if(o.isLeaf()){
|
||||
if(this.getText() == null){
|
||||
return -1;
|
||||
}else{
|
||||
return this.getText().compareToIgnoreCase(o.getText());
|
||||
}
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
}else{
|
||||
if(o.isLeaf()){
|
||||
return -1;
|
||||
}else{
|
||||
if(this.getText() == null){
|
||||
return -1;
|
||||
}else{
|
||||
return this.getText().compareToIgnoreCase(o.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
package com.rekoe.tree.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import com.rekoe.tree.entity.Tree;
|
||||
import com.rekoe.tree.entity.TreeNode;
|
||||
|
||||
/**
|
||||
* 抽象树节点服务层
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTreeNodeService implements TreeNodeService {
|
||||
|
||||
public StringBuffer getHTML(Tree tree, Map<String, Object> parameters) {
|
||||
StringBuffer html = new StringBuffer();
|
||||
List<TreeNode> nodes = getTreeNodes(tree, parameters);
|
||||
if (nodes == null || nodes.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
html.append("<ul>");
|
||||
for (int i = 0; nodes != null && i < nodes.size(); i++) {
|
||||
TreeNode treeNode = nodes.get(i);
|
||||
html.append("<li");
|
||||
if (this.isLeaf(tree, treeNode)) {// 叶子
|
||||
if (i == nodes.size() - 1) {// last
|
||||
this.prepareAttribute(html, "class", "last");
|
||||
}
|
||||
} else {// 父节点
|
||||
if (i == nodes.size() - 1) {// last
|
||||
this.prepareAttribute(html, "class", "closed lastclosed");
|
||||
} else {
|
||||
this.prepareAttribute(html, "class", "closed");
|
||||
}
|
||||
this.prepareAttribute(html, TreeService.TREE_PARENTID_VAR, tree.getId());
|
||||
}
|
||||
|
||||
Map<String, Object> allParam = new HashMap<String, Object>();
|
||||
if (parameters != null) {
|
||||
allParam.putAll(parameters);
|
||||
}
|
||||
Map<String, String> treeNodeParameters = treeNode.getParameters();
|
||||
if (treeNodeParameters != null) {
|
||||
allParam.putAll(treeNodeParameters);
|
||||
}
|
||||
allParam.remove(TreeService.TREE_ID_VAR);
|
||||
allParam.remove(TreeService.TREE_PARENTID_VAR);
|
||||
prepareParameters(html, allParam);
|
||||
|
||||
if (treeNode.getUrl() != null) {
|
||||
this.prepareAttribute(html, "url", treeNode.getUrl());
|
||||
}
|
||||
Map<String, String> attributes = treeNode.getAttributes();
|
||||
if (attributes != null) {
|
||||
Iterator<String> attributeKeys = treeNode.getAttributes().keySet().iterator();
|
||||
while (attributeKeys.hasNext()) {
|
||||
String att = attributeKeys.next();
|
||||
prepareAttribute(html, att, treeNode.getAttributes().get(att));
|
||||
}
|
||||
}
|
||||
html.append(" >");
|
||||
if (this.isLeaf(tree, treeNode)) {
|
||||
html.append("<span class='file'>");
|
||||
} else {
|
||||
if (i == nodes.size() - 1) {// last folder
|
||||
html.append("<div class='hit closed-hit lastclosed-hit' onclick='$att(this);'></div>");
|
||||
} else {
|
||||
html.append("<div class='hit closed-hit' onclick='$att(this);'></div>");
|
||||
}
|
||||
html.append("<span class='folder' onclick='$att(this);'>");
|
||||
}
|
||||
html.append("<a href='javascript:void(0);' onclick='$atc(this)'>");
|
||||
html.append(StringEscapeUtils.escapeHtml4(treeNode.getText()));
|
||||
html.append("</a>");
|
||||
html.append("</span>");
|
||||
html.append("</li>");
|
||||
|
||||
}
|
||||
html.append("</ul>");
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子节点
|
||||
*
|
||||
* @param parent
|
||||
* 树
|
||||
* @param parameters
|
||||
* 参数
|
||||
* @return 子节点
|
||||
*/
|
||||
protected abstract List<TreeNode> getTreeNodes(Tree parent, Map<String, Object> parameters);
|
||||
|
||||
/**
|
||||
* 处理参数
|
||||
*
|
||||
* @param handlers
|
||||
* html
|
||||
* @param params
|
||||
* 参数
|
||||
*/
|
||||
protected void prepareParameters(StringBuffer handlers, Map<String, Object> params) {
|
||||
if (params == null)
|
||||
return;
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
Iterator<String> iterKeys = params.keySet().iterator();
|
||||
int count = 0;
|
||||
while (iterKeys.hasNext()) {
|
||||
if (count > 0)
|
||||
result.append("&");
|
||||
count++;
|
||||
|
||||
String key = iterKeys.next();
|
||||
Object value = params.get(key);
|
||||
if (value != null) {
|
||||
if (value instanceof String) {
|
||||
result.append(key).append("=").append(value.toString());
|
||||
} else if (value instanceof String[]) {
|
||||
String[] arrs = (String[]) value;
|
||||
for (String string : arrs) {
|
||||
if (string == null) {
|
||||
result.append(key).append("=");
|
||||
} else {
|
||||
result.append(key).append("=").append(string);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Not support parameter: " + key + "=" + value);// TODO
|
||||
}
|
||||
} else {
|
||||
result.append(key).append("=");
|
||||
}
|
||||
|
||||
}
|
||||
if (result.length() > 0) {
|
||||
this.prepareAttribute(handlers, "param", result.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an attribute if the value is not null, appending it to the the
|
||||
* given StringBuffer.
|
||||
*
|
||||
* @param handlers
|
||||
* The StringBuffer that output will be appended to.
|
||||
* @param name
|
||||
* 属性名称
|
||||
* @param value
|
||||
* 属性值
|
||||
*/
|
||||
protected void prepareAttribute(StringBuffer handlers, String name, Object value) {
|
||||
if (value != null) {
|
||||
handlers.append(" ");
|
||||
handlers.append(name);
|
||||
handlers.append("=\"");
|
||||
handlers.append(value);
|
||||
handlers.append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tree
|
||||
* 树
|
||||
* @param treeNode
|
||||
* 节点
|
||||
* @return 是否是叶子节点
|
||||
*/
|
||||
protected boolean isLeaf(Tree tree, TreeNode treeNode) {
|
||||
return treeNode.isLeaf() || tree.isLeaf();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.rekoe.tree.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.service.DefaultTreeFactory;
|
||||
import com.rekoe.service.RepTreeNodeService;
|
||||
import com.rekoe.tree.entity.Tree;
|
||||
|
||||
/**
|
||||
* 抽象树服务层
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTreeService implements TreeService {
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private static final org.nutz.log.Log LOG = Logs.get();
|
||||
|
||||
@Inject
|
||||
private DefaultTreeFactory defaultTreeFactory;
|
||||
|
||||
@Inject
|
||||
private RepTreeNodeService repTreeNodeService;
|
||||
public String getHTML(Map<String, Object> parameters) {
|
||||
try {
|
||||
String treeId = (String) parameters.get(TREE_ID_VAR);
|
||||
String parentId = (String) parameters.get(TREE_PARENTID_VAR);
|
||||
|
||||
if (StringUtils.isBlank(treeId) && StringUtils.isBlank(parentId)) {
|
||||
return null;
|
||||
}
|
||||
StringBuffer html = new StringBuffer();
|
||||
if (StringUtils.isNotBlank(parentId)) {
|
||||
// 找出所有的子树
|
||||
List<Tree> treeList = defaultTreeFactory.findChildren(parentId);
|
||||
for (Tree tree : treeList) {
|
||||
if (tree == null) {
|
||||
continue;
|
||||
}
|
||||
parseTree(html, tree, parameters);
|
||||
}
|
||||
} else if (StringUtils.isNotBlank(treeId)) {
|
||||
// 说明是第一层
|
||||
Tree tree = defaultTreeFactory.find(treeId);
|
||||
if (tree == null) {
|
||||
LOG.info("not found tree. id = " + treeId);
|
||||
return null;
|
||||
}
|
||||
parseTree(html, tree, parameters);
|
||||
}
|
||||
return html.toString();
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param treeHtml
|
||||
* html
|
||||
* @param tree
|
||||
* 树
|
||||
* @param parameters
|
||||
* 参数
|
||||
*/
|
||||
protected void parseTree(StringBuffer treeHtml, Tree tree, Map<String, Object> parameters) {
|
||||
StringBuffer html;
|
||||
try {
|
||||
html = repTreeNodeService.getHTML(tree, parameters);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
html = null;
|
||||
} finally {
|
||||
}
|
||||
if (html == null) {
|
||||
LOG.debug("not found tree html data." + tree);
|
||||
return;
|
||||
}
|
||||
treeHtml.append(html);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.rekoe.tree.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.rekoe.tree.entity.Tree;
|
||||
|
||||
/**
|
||||
* 树工厂类
|
||||
* @author <a href="mailto:yuanhuiwu@gmail.com">Huiwu Yuan</a>
|
||||
* @since 3.0.2
|
||||
*
|
||||
*/
|
||||
public interface TreeFactory {
|
||||
|
||||
/**
|
||||
* @param id 树ID
|
||||
* @return 查找树
|
||||
*/
|
||||
Tree find(String id);
|
||||
|
||||
/**
|
||||
* 查找子树
|
||||
*
|
||||
* @param parentId 父树ID
|
||||
* @return 树的子树
|
||||
*/
|
||||
List<Tree> findChildren(String parentId);
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.rekoe.tree.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.rekoe.tree.entity.Tree;
|
||||
|
||||
/**
|
||||
* 树节点服务层接口
|
||||
* @author <a href="mailto:yuanhuiwu@gmail.com">Huiwu Yuan</a>
|
||||
* @since 3.0.2
|
||||
*
|
||||
*/
|
||||
public interface TreeNodeService {
|
||||
|
||||
/**
|
||||
* 获取树节点的html
|
||||
* @param tree 树
|
||||
* @param parameters 参数
|
||||
* @return 树节点的html
|
||||
*/
|
||||
StringBuffer getHTML(Tree tree, Map<String, Object> parameters);
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.rekoe.tree.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 树服务层接口
|
||||
* @author <a href="mailto:yuanhuiwu@gmail.com">Huiwu Yuan</a>
|
||||
* @since 3.0.2
|
||||
*
|
||||
*/
|
||||
public interface TreeService {
|
||||
/**
|
||||
* 树ID
|
||||
*/
|
||||
public static final String TREE_ID_VAR = "treeId";
|
||||
/**
|
||||
* 树的父的ID
|
||||
*/
|
||||
public static final String TREE_PARENTID_VAR = "treeParentId";
|
||||
|
||||
/**
|
||||
* @param parameters 参数
|
||||
* @return 树的html
|
||||
*/
|
||||
String getHTML(Map<String, Object> parameters);
|
||||
}
|
|
@ -5,14 +5,9 @@
|
|||
<link href="${base}/res/common/css/jquery.treeview.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="${base}/res/common/css/jquery.ui.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="${base}/res/common/css/base.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="${base}/tinyeditor/style.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="${base}/thirdparty/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
|
||||
<script src="${base}/res/common/js/jquery.js?20160305" type="text/javascript"></script>
|
||||
<script src="${base}/res/common/js/jquery-ui-1.10.4.min.js" type="text/javascript"></script>
|
||||
<script src="${base}/res/common/js/jquery.ext.js" type="text/javascript"></script>
|
||||
<script src="${base}/tinyeditor/tinyeditor.js?20140529" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="${base}/thirdparty/kindeditor4/kindeditor-min.js"></script>
|
||||
<script type="text/javascript" src="${base}/thirdparty/kindeditor4/lang/zh_CN.js"></script>
|
||||
<script src="${base}/res/cms/js/admin.js?2016012002" type="text/javascript"></script>
|
||||
<script src="${base}/res/common/js/base.js?201400623" type="text/javascript"></script>
|
||||
<script src="${base}/res/common/js/pony.js" type="text/javascript"></script>
|
||||
|
|
|
@ -46,10 +46,10 @@ function freshTree(){
|
|||
var $p = $("#path");
|
||||
var p = $p.val();
|
||||
if(p==""){
|
||||
p="/";
|
||||
//p="/";
|
||||
$p.val(p);
|
||||
}else if(p.substring(0,1)!="/"){
|
||||
p = "/"+p;
|
||||
//p = "/"+p;
|
||||
$p.val(p);
|
||||
}
|
||||
var $r = $("#svnroot");
|
||||
|
|
Loading…
Reference in New Issue