日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

svn客户端 java_svn纯java客户端SVNKit学习整理(转)

發(fā)布時(shí)間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 svn客户端 java_svn纯java客户端SVNKit学习整理(转) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

http://www.iteye.com/topic/688217

http://blog.csdn.net/feiren127/article/details/7551782

把svnkit.jar添加到項(xiàng)目中,用于實(shí)現(xiàn)svn功能。?把jackson-all-1.6.2.jar添加到項(xiàng)目中,用于顯示樹列表。把javaee.ar添加到項(xiàng)目中。

新建一個(gè)類(SVNUtil.class)實(shí)現(xiàn)svn功能

private?String?svnRoot;

private?String?userName;

private?String?password;

private?SVNRepository?repository;

/***

*?構(gòu)造方法

*?@param?svnRoot

*?????????????svn根目錄

*/

public?SVNUtil(String svnRoot) {

this.svnRoot=svnRoot;

}

/***

*?構(gòu)造方法

*?@param?svnRoot

*?????????????svn根目錄

*?@param?userName

*?????????????登錄用戶名

*?@param?password

*?????????????登錄密碼

*/

public?SVNUtil(String svnRoot, String userName, String password) {

this.svnRoot=svnRoot;

this.userName=userName;

this.password=password;

}

/***

*?通過不同的協(xié)議初始化版本庫(kù)

*/

private?static?void?setupLibrary() {

//?對(duì)于使用http://和https://

DAVRepositoryFactory.setup();

//對(duì)于使用svn:/ /和svn+xxx:/ /

SVNRepositoryFactoryImpl.setup();

//對(duì)于使用file://

FSRepositoryFactory.setup();

}

每次連接庫(kù)都進(jìn)行登陸驗(yàn)證

/***

*?登錄驗(yàn)證

*?@return

*/

public?boolean?login(){

setupLibrary();

try{

//創(chuàng)建庫(kù)連接

repository=SVNRepositoryFactory.create(SVNURL.parseURIEncoded(this.svnRoot));

//身份驗(yàn)證

ISVNAuthenticationManager authManager = SVNWCUtil

.createDefaultAuthenticationManager(this.userName,

this.password);

//創(chuàng)建身份驗(yàn)證管理器

repository.setAuthenticationManager(authManager);

return?true;

}?catch(SVNException svne){

svne.printStackTrace();

return?false;

}

}

下面的方法實(shí)現(xiàn)查詢給定路徑下的條目列表功能

/***

*

*?@param?path

*?@return?查詢給定路徑下的條目列表

*?@throws?SVNException

*/

@SuppressWarnings("rawtypes")

public?List listEntries(String path)

throws?SVNException {

Collection entries =?repository.getDir(path, -1,?null,

(Collection)?null);

Iterator iterator = entries.iterator();

List svns =?new?ArrayList();

while?(iterator.hasNext()) {

SVNDirEntry entry = (SVNDirEntry) iterator.next();

SVN svn =?new?SVN();

svn.setCommitMessage(entry.getCommitMessage());

svn.setDate(entry.getDate());

svn.setKind(entry.getKind().toString());

svn.setName(entry.getName());

svn.setRepositoryRoot(entry.getRepositoryRoot().toString());

svn.setRevision(entry.getRevision());

svn.setSize(entry.getSize()/1024);

svn.setUrl(path.equals("") ??"/"+entry.getName() : path +"/"+entry.getName());

svn.setAuthor(entry.getAuthor());

svn.setState(svn.getKind() ==?"file"?null:"closed");

svns.add(svn);

}

新建一個(gè)SVNServlet

添加一個(gè)方法用于把java對(duì)象轉(zhuǎn)換為json字符串

/**

*?將java對(duì)象轉(zhuǎn)換為json字符串

*

*?@param?obj

*????????????:可以為map,list,javaBean等

*?@return?json字符串

*?@createTime?2010-11-23?下午07:42:58

*/

public?static?String object2Json(Object obj) {

try?{

StringWriter sw =?new?StringWriter();

JsonGenerator gen =?new?JsonFactory().createJsonGenerator(sw);

mapper.writeValue(gen, obj);

gen.close();

return?sw.toString();

}?catch?(Exception e) {

e.printStackTrace();

}

return?null;

}

protected?void?doGet(HttpServletRequest request,

HttpServletResponse response)?throws?ServletException, IOException {

//?TODO?Auto-generated method stub

this.doPost(request, response);

}

protected?void?doPost(HttpServletRequest request,

HttpServletResponse response)?throws?ServletException, IOException {

//?TODO?Auto-generated method stub

Object svns =?null;

request.setCharacterEncoding("UTF-8");

response.setCharacterEncoding("UTF-8");

String path = request.getParameter("pid");

String url =?"svn://localhost/svndemo1";

String usrName =?"usrName";

String password =?"password";

if?(path ==?null) {

path =?"";

}

path =?new?String(path.getBytes("ISO-8859-1"),"UTF-8");

String type = request.getParameter("type");

PrintWriter out = response.getWriter();

try?{

SVNUtil svnUtil =?new?SVNUtil(url, usrName, password);

if?(svnUtil.login()) {

/*用于查詢歷史記錄

if?("history".equals(type)) {

List svnl = svnUtil.getHistory(path);

HashMap sv =?new?HashMap();

sv.put("total", svnl.size());

sv.put("rows", svnl);

svns = sv;

}?else?{*/

svns = svnUtil.listEntries(path);

//}

//把java對(duì)象轉(zhuǎn)換成json字符串

String json = SVNServlet.object2Json(svns);

out.print(json);

}?else?{

System.out.println("驗(yàn)證失敗");

}

}?catch?(SVNException ex) {

ex.printStackTrace();

}

out.flush();

out.close();

}

新建一個(gè)index.jsp用戶顯示版本數(shù)列表,頁(yè)面顯示我使用了jquery-easyui模板

pageEncoding="utf-8"%>

String path = request.getContextPath();

String basePath = request.getScheme() +?"://"

+ request.getServerName() +?":"?+ request.getServerPort()

+ path +?"/";

%>

html?PUBLIC?"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

">

SVN

href="plugs/themes/default/easyui.css">

$(function() {

$(‘#test‘).treegrid({

title :?‘SVN列表‘,

nowrap :?false,

rownumbers :?true,

collapsible :?false,

url :?‘svn?pid=‘,

idField :?‘url‘,

treeField :?‘url‘,

frozenColumns : [ [ {

title :?‘路徑‘,

field :?‘url‘,

width : 350,

formatter :?function(value) {

return?‘‘?+ decodeURI(value.substr(value.lastIndexOf("/"))) +?‘‘;

}

} ] ],

columns : [ [ {

field :?‘name‘,

title :?‘名稱‘,

width : 120

}, {

field :?‘size‘,

title :?‘文件大小(KB)‘,

width : 80,

rowspan : 2

}, {

field :?‘revision‘,

title :?‘版本號(hào)‘,

width : 80,

rowspan : 2

}, {

field :?‘a(chǎn)uthor‘,

title :?‘作者‘,

width : 100,

rowspan : 2

}, {

field :?‘date‘,

title :?‘修改日期‘,

width : 130,

rowspan : 2

}, {

field :?‘commitMessage‘,

title :?‘注釋‘,

width : 150,

rowspan : 2

}, {

field :?‘kind‘,

title :?‘操作‘,

width : 120,

align :?‘center‘,

rowspan : 2,

formatter :?function(value) {

return?value==‘file‘???‘下載歷史版本‘?:?‘‘;

}

}] ],

onBeforeExpand :?function(row, param) {

$(this).treegrid(‘options‘).url =?‘svn?pid=‘+encodeURI(decodeURI(row.url));

}

});

});

function?download(){

setTimeout(function(){

var?node = $(‘#test‘).treegrid(‘getSelected‘);

if(node !=null)

window.open("download?url="+encodeURI(decodeURI(node.url))+"&size="+node.size+"&name="+encodeURI(decodeURI(node.name))+"&revision="+node.revision);

},200);

}

function?viewHistory(){

setTimeout(function(){

var?node = $(‘#test‘).treegrid(‘getSelected‘);

if(node !=?null) {

window.open("history.jsp?uri="+encodeURI(decodeURI(node.url)),"_blank","height=400,width=700,status=yes,toolbar=no,menubar=no,location=no");

}

}, 200);

}

原文:http://www.cnblogs.com/softidea/p/4267762.html

總結(jié)

以上是生活随笔為你收集整理的svn客户端 java_svn纯java客户端SVNKit学习整理(转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。