开发文件复制黏贴功能_第1页
开发文件复制黏贴功能_第2页
开发文件复制黏贴功能_第3页
开发文件复制黏贴功能_第4页
开发文件复制黏贴功能_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

文件复制功能一、目录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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论