版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
文件复制功能一、目录21.技术原理2.效果图预览3.实现步骤4.功能验证测试二、技术原理3(1)视图层:显示复制文件对话框(2)控制层:接收视图层的消息,向服务层发送文件复制参数,并将服务层返回的结果发送到视图层(3)服务层:调用swift服务对文件进行复制和粘贴,并将结果返回给控制层三、效果预览图4四、步骤实现5在cn/edu/sict/cloud/storage/service/SwiftStorageService.java添加如下代码public
booleancopyfile(Stringusername,List<Map<String,Object>>list){for(Map<String,Object>map:list){Stringpath=(String)map.get("path");Stringnewpath=(String)map.get("newpath");Stringname=(String)map.get("name");StringtisDir=(String)map.get("isDir");boolean
isDir="true".equals(tisDir)?true:false;SwiftDFSswiftdfs=newSwiftDFS();if(isDir){swiftdfs.copyDir(username+"/"+path,username+"/"+newpath);}else{swiftdfs.copyFile(username+"/"+path,username+"/"+newpath+name);}}return
true;}四、步骤实现6在cn/edu/sict/cloud/storage/service/SwiftStorageService.java添加如下代码/***取得路径下的所有文件夹*/publicListgetAllStoredDirectoryList(Stringusername,Stringpath,Stringupath){SwiftDFSswiftdfs=newSwiftDFS();Listlist=newArrayList();Stringup=null;if(path==null||path.equals("")){
up=username;}else{up=username+"/"+path;}list=swiftdfs.getDir(up);return
list;}四、步骤实现7在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码public
ListgetDir(Stringrpath){Mapmappath=getSplitPath(rpath);Stringpath=mappath.get("path").toString();Stringrootpath=mappath.get("rootPath").toString();List<?extendsSwiftObject>objs;objs=this.list(rootpath,path);Listlist=newArrayList();for(SwiftObjectswiftObject:objs){FileBeanfb=newFileBean();StringfilePath=swiftObject.getName();boolean
flag=this.isDirectory(filePath);fb.setName(this.getName(filePath));fb.setIsdirectory(flag);boolean
haschild=this.haschild(rootpath,filePath);fb.setHaschild(haschild);if(flag){fb.setPath(filePath);list.add(fb);}}return
list;}四、步骤实现8在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码private
booleanhaschild(Stringrootpath,Stringpath){List<?extendsSwiftObject>objs=this.list(rootpath,path);for(SwiftObjectswiftObject:objs){boolean
flag=this.isDirectory(swiftObject.getName());
if(flag){return
true;}}return
false;}四、步骤实现9在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码public
booleancopyDir(Stringrpath,Stringrnewpath){Mapmappath=getSplitPath(rpath);Stringrmpath=mappath.get("path").toString();Stringrootpath=mappath.get("rootPath").toString();Maprmappath=getSplitPath(rnewpath);Stringrnpath=rmappath.get("path").toString();int
len=rootpath.length();Stringpath=rmpath;Stringnewpath=rnpath;Stringname=rmpath.split("/")[rmpath.split("/").length-1];if(path.equals(newpath)){return
false;}this.copy(rootpath,rootpath,path,newpath+name+"/");copydirfile(rootpath,path,newpath,name,path);return
true;}四、步骤实现10在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码private
voidcopydirfile(Stringrootpath,Stringpath,Stringnewpath,Stringname,Stringepath){List<?extendsSwiftObject>objs=this.list(rootpath,path);for(SwiftObjectswiftObject:objs){if(swiftObject.isDirectory()){Stringcpath=swiftObject.getName();Stringtpath=cpath.substring(path.length());Stringtnewpath=newpath+name+"/"+tpath;//strs[1];this.copy(rootpath,rootpath,cpath,tnewpath);copydirfile(rootpath,path,newpath,name,cpath);}else{Stringtemppath=swiftObject.getName();if(temppath.endsWith("/")){continue;}Stringtpath=temppath.substring(path.length());Stringtnewpath=newpath+name+"/"+tpath;//strs[1];this.copy(rootpath,rootpath,temppath,tnewpath);}}}四、步骤实现11在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码public
booleancopyFile(Stringrpath,Stringrnewpath){Mapmappath=getSplitPath(rpath);Stringpath=mappath.get("path").toString();StringrootPath=mappath.get("rootPath").toString();Mapnmappath=getSplitPath(rnewpath);Stringnpath=nmappath.get("path").toString();Stringnrootpath=nmappath.get("rootPath").toString();boolean
isexist=this.isexist(nrootpath,npath);if(isexist){this.copy(rootPath,nrootpath,path,npath);return
true;}return
false;}四、步骤实现12在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码@RequestMapping("/copyfile")@ResponseBodypublicObjectcopyfile(HttpServletRequestrequest,HttpServletResponseresponse,@RequestBodyList<Map<String,Object>>list){Useruser=getSessionUser(request);boolean
flag=false;flag=storage.copyfile(user.getUsername(),list);return
newMessageBean(flag,flag?Constants.SUCCESS_8:Constants.ERROR_9);}四、步骤实现13在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码@RequestMapping("/homedir")@ResponseBodypublicObjecthomedir(HttpServletRequestrequest,HttpServletResponseresponse,Stringpath){Useruser=getSessionUser(request);Stringupath=request.getSession().getServletContext().getRealPath("/");Listlist=storage.getAllStoredDirectoryList(user.getUsername(),path,upath);return
newMessageBean(true,"",list);}四、步骤实现14在main.jsp中加入如下代码实现复制对话框<divclass="lb-copy"style="display:none;"><divclass="containerpl-266"><divclass="move-box-head"><p>复制文件</p><divclass="lb-closeContainer"><aclass="lb-closemove-lb-close"href="javascript:void(0);"><spanclass="glyphiconglyphicon-remove"></span></a></div></div><divclass="move-box"><divclass="move-box-content"><divclass="move-box-position"><div><pclass="move-position-head">选择复制到的位置</p><divclass="move-position-back"><ahref="javascript:void(0);"onclick="getdir1()">«返回</a></div></div><divclass="move-copy-filder"><divclass="myDiv"></div></div></div><buttonclass="btnbtn-primarymove-button"onclick="Copy();">提交</button></div></div></div></div>四、步骤实现15给复制按钮添加单击事件getdir1(),并在js中添加如下代码functiongetdir1(){vartmp='<divclass="col-md-3"style="margin-top:10px;">'+'<inputname="CheckS"type="radio"style="float:left"value="">'+'<ahref="javascript:void(0);"onclick="getdir()">'+'<imgsrc=assets/images/2.pngstyle="height:61px;width:61px">'+'<divstyle="height:21px;width:87px;overflow:hidden;text-overflow:ellipsis;font-size:10pt;margin-left:4px;">全部文件</div>'+'</a></div>';$(".myDiv").html(tmp);}四、步骤实现16增加getdir()方法,获取文件夹子目录下的所有文件夹functiongetdir(path){vardata={path:path};$.ajax({url:"homedir.action",type:"post",data:data,success:function(s){if(s.success){vararray=s.other;vartmp='<divstyle="margin-top:10px;">';for(vari=0;i<array.length;i++){if(array[i]['isdirectory']==true){if(array[i]['haschild']==true){tmp+='<divclass="col-md-3"style="margin-bottom:20px;"><inputname="CheckS"type="radio"style="float:left"value=\''+array[i]['path']+'\'><ahref="javascript:void(0);"onclick="getdir(\''+array[i]['path']+'\')"><imgsrc=assets/images/2.pngstyle="height:61px;width:61px"><divstyle="height:21px;width:87px;overflow:hidden;text-overflow:ellipsis;font-size:10pt;">'+array[i]['name']+'</div></a></div>';四、步骤实现17增加getdir()方法,获取文件夹子目录下的所有文件夹}else{tmp+='<divclass="col-md-3"style="margin-bottom:20px;">'+‘<inputname=“CheckS”type=“radio”style=“float:left”value=\’‘+array[i][’path‘]+’\‘><imgsrc=assets/images/2.pngstyle=“height:61px;width:61px”><divstyle=“height:21px;width:84%;overflow:hidden;text-overflow:ellipsis;font-size:10pt;margin-left:13px;">'+array[i]['name']+'</div></div>';}}}tmp+='</div>';$(".myDiv").html(tmp);}}});}四、步骤实现18给对话框的提交按钮添加单击事件Copy(),并在js中添加如下代码functionCopy(){varobjTable=document.getElementById("tab");vardata='[';varinput1=document.getElementsByName("CheckS");varnewpath;for(vari=0;i<input1.length;i++){if(input1[i].checked==true){newpath=$(input1[i]).val();}}if(newpath==undefined){alert("请选择复制位置");return;}//if(newpath==""){alert("请选择复制的位置");return;}for(vary=0;y<objTable.rows.length;y++){varcheckbox=objTable.rows[y].childNodes[1].childNodes[0].childNodes[5];if(checkbo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年中药购销员(中级)(理论知识)试题及答案
- 2025年大学人体断层解剖学(断层结构识别)试题及答案
- 2025年大学第四学年(历史学)世界近现代史综合测试试题及答案
- 2025年高职编导(影视编导)试题及答案
- 2025年大学生物(生物化学)试题及答案
- 2025年中职(舞蹈表演)舞蹈基本功试题及答案
- 2025年高职药品质量与安全(药品风险评估)试题及答案
- 2025年高职茶叶生产与应用(茶叶营销实务)试题及答案
- 2026年安徽审计职业学院高职单招职业适应性测试备考题库有答案解析
- 2026年贵州交通职业技术学院单招综合素质笔试模拟试题带答案解析
- 广东省深圳市南山区2023-2024学年四年级上学期数学期末教学质量监测试卷
- 【MOOC】生物化学与分子生物学-华中科技大学 中国大学慕课MOOC答案
- 地下室顶板堆载及回顶方案
- 广东省2024年修订医疗服务价格项目表
- 药品经营质量管理规范
- (人教2024版)数学四年级上册第8单元《数学广角-优化》大单元教学课件
- 临床生物化学检验练习题库(含答案)
- G -B- 15607-2023 涂装作业安全规程 粉末静电喷涂工艺安全(正式版)
- (正式版)SHT 3229-2024 石油化工钢制空冷式热交换器技术规范
- 2018年4月自考00265西方法律思想史试题及答案含解析
- 小红书创业计划书
评论
0/150
提交评论