package com.dy.pipIrrWebFile.fm; import java.util.ArrayList; import java.util.List; public class DyFileSvConf { public static class Group{ public List list ; public Group(){ this.list = new ArrayList() ; } public void add(Vo vo)throws Exception{ if(vo == null){ throw new Exception("出错,预加入集合Vo为空了!") ; } if(list.size() > 0){ for(Vo lvo : list){ lvo.checkEqual(vo) ; } this.list.add(vo) ; }else{ this.list.add(vo) ; } } public void check() throws Exception{ Integer startV = 0 ; doCheck(startV) ; } private void doCheck(Integer startV) throws Exception{ boolean find = false ; for(Vo vo : list){ if(vo.hashStart.intValue() == startV.intValue()){ startV = vo.hashEnd + 1; find = true ; break ; } } if(!find){ throw new Exception("严重错误,未发现哈希值为" + startV + "文件服务器!") ; } if(startV.intValue() <= 65535){ doCheck(startV) ; } } } public static class Vo{ public String id ;//id或名称 public String fileSysAbsolutePath; //文件名称的哈希值对应的文件最终存储绝对路径中的根目录,在配置文件中配置 public String fileSysRelativePath; //文件名称的哈希值对应的文件最终存储相对路径的目录,在配置文件中配置 public String restUrl;//文件系统路径 public String webUrl ;//下载文档的web路径 public String webDownloadPath ;//下载文档的Controller的相对路径 public Integer hashStart ;//哈希值启始值(包含) public Integer hashEnd ;//哈希值截止值(包含) public Vo(){} public Vo(String id, String fileSysAbsolutePath, String fileSysBasePath, String restUrl, String webUrl, String webDownloadPath, Integer hashStart, Integer hashEnd)throws Exception{ this.id = id ; this.fileSysAbsolutePath = fileSysAbsolutePath ; this.fileSysRelativePath = fileSysBasePath ; this.restUrl = restUrl ; this.webUrl = webUrl ; this.webDownloadPath = webDownloadPath ; this.hashStart = hashStart ; this.hashEnd = hashEnd ; if(this.id == null || this.id.trim().equals("")){ throw new Exception("出错,id为空了!") ; }else{ this.id = this.id.trim() ; } if(this.fileSysAbsolutePath == null || this.fileSysAbsolutePath.trim().equals("")){ throw new Exception("出错,fileSysAbsolutePath为空了!") ; }else{ this.fileSysAbsolutePath = this.fileSysAbsolutePath.trim() ; this.fileSysAbsolutePath = this.fileSysAbsolutePath.replaceAll("\\\\", "/") ; if(!this.fileSysAbsolutePath.endsWith("/")){ this.fileSysAbsolutePath = this.fileSysAbsolutePath + "/" ; } } if(this.fileSysRelativePath == null || this.fileSysRelativePath.trim().equals("")){ throw new Exception("出错,fileSysBasePath为空了!") ; }else{ this.fileSysRelativePath = this.fileSysRelativePath.trim() ; } if(this.webUrl == null || this.webUrl.trim().equals("")){ throw new Exception("出错,webUrl为空了!") ; }else{ this.webUrl = this.webUrl.trim() ; if(!this.webUrl.endsWith("/") && !this.webUrl.endsWith("\\")){ this.webUrl += "/" ; } } if(this.webDownloadPath == null || this.webDownloadPath.trim().equals("")){ throw new Exception("出错,webDownloadPath!") ; } if(this.hashStart == null){ throw new Exception("出错,hashStart为空了!") ; }else if(this.hashStart.intValue() < 0){ throw new Exception("出错,hashStart小于0了!") ; }else if(this.hashStart.intValue() > 65535){ throw new Exception("出错,hashStart大于65535了!") ; } if(this.hashEnd == null){ throw new Exception("出错,hashEnd为空了!") ; }else if(this.hashEnd.intValue() < 0){ throw new Exception("出错,hashEnd小于0了!") ; }else if(this.hashEnd.intValue() > 65535){ throw new Exception("出错,hashEnd大于65535了!") ; } if(this.hashEnd < this.hashStart){ throw new Exception("出错,hashEnd小于hashStart了!") ; } } public String toString(){ return "id=" + id + "\n" + "fileSysAbsolutePath=" + fileSysAbsolutePath + "\n" + "fileSysBasePath=" + fileSysRelativePath + "\n" + "restUrl=" + restUrl + "\n" + "webUrl=" + webUrl + "\n" + "webDownloadPath=" + webDownloadPath + "\n" + "hashStart=" + hashStart + "\n" + "hashEnd=" + hashEnd ; } private boolean checkEqual(Vo vo)throws Exception{ if(this.id.equalsIgnoreCase(vo.id)){ throw new Exception("出错,id有重复!") ; } if(this.hashStart.intValue() == vo.hashStart.intValue()){ throw new Exception("出错,hashStart有重复!") ; } if(this.hashEnd.intValue() == vo.hashEnd.intValue()){ throw new Exception("出错,hashEnd有重复!") ; } if(this.hashStart.intValue() == vo.hashEnd.intValue()){ throw new Exception("出错,hashStart与hashEnd有重复!") ; } if(this.hashEnd.intValue() == vo.hashStart.intValue()){ throw new Exception("出错,hashEnd与hashStart有重复!") ; } return true ; } } }