2012年10月13日土曜日

SVNKitでShowLogするサンプル

SVNKit(http://svnkit.com/)を利用してSVNのログ表示を実行してみた。 こんな感じで書けばいけるようである。
import java.io.File;

import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;


public class SVNLogSample {
 private static class LogEntryHandler implements ISVNLogEntryHandler{

  @Override
  public void handleLogEntry(SVNLogEntry arg0) throws SVNException {
   System.out.print(arg0.getDate());
//   System.out.print(arg0.getChangedPaths());
   System.out.print(arg0.getAuthor());
   System.out.println(arg0.getMessage());
  }
  
 }
 private static final String SVN_USER="svnuser";
 private static final String SVN_PASS="svnuserpass";
 public static void main(String[] args) throws SVNException {
  new SVNLogSample().execute();
 }

 private void execute() throws SVNException {
  System.out.println("start");
  init();
  ISVNAuthenticationManager auth = SVNWCUtil.createDefaultAuthenticationManager(new File("tmp"),SVN_USER,SVN_PASS,false);
  SVNLogClient lc = new SVNLogClient(auth,null);
  SVNURL targetUrl=SVNURL.parseURIEncoded("svn://xxxxxxx");
  ISVNLogEntryHandler handler = new LogEntryHandler();
  String[] path = new String[]{"/path1","/path1"};
  lc.doLog(targetUrl,path,SVNRevision.HEAD, SVNRevision.HEAD, SVNRevision.create(0), true, true, 50, handler);
 }

 private void init() {
  DAVRepositoryFactory.setup();
  SVNRepositoryFactoryImpl.setup();
  FSRepositoryFactory.setup(); 
 }
}

SVNKitでSvnDiffのサンプルコード

SVNKit(http://svnkit.com/)を利用してSVNDiffを実行してみた。
こんな感じで書けば実行できるようである。
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.UnsupportedEncodingException;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.wc.ISVNDiffStatusHandler;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNDiffStatus;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
public class SVNDiffSample {
 private static class DiffStatusHandler implements ISVNDiffStatusHandler{
 @Override
 public void handleDiffStatus(SVNDiffStatus arg0) throws SVNException {
  System.out.print(arg0.getPath());
  System.out.print(":");
  System.out.println(arg0.getModificationType());
 }
}
 private static final String SVN_USER="svn_user";
 private static final String SVN_PASS="svn_pass";
 public static void main(String[] args) throws SVNException, UnsupportedEncodingException {
  new SVNDiffSample().execute();
 }
 private void execute() throws SVNException, UnsupportedEncodingException {
  System.out.println("start");
  init();
  ISVNAuthenticationManager auth = SVNWCUtil.createDefaultAuthenticationManager(new        File("tmp"),SVN_USER,SVN_PASS,false);
  SVNDiffClient lc = new SVNDiffClient(auth,null);
  SVNURL targetUrl=SVNURL.parseURIEncoded("svn://urlstring");
  ISVNDiffStatusHandler handler = new DiffStatusHandler();
  //lc.doDiffStatus(targetUrl, SVNRevision.create(revNo), targetUrl,SVNRevision.create(revNo),   true, true, handler);
  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  lc.doDiff(targetUrl, SVNRevision.create(revNo), targetUrl,SVNRevision.create(revNo),       SVNDepth.INFINITY, true, bao);
  System.out.println("SIZE:"+bao.size());
  System.out.println(bao.toString("MS932"));
 }
 private void init() {
  DAVRepositoryFactory.setup();
  SVNRepositoryFactoryImpl.setup();
  FSRepositoryFactory.setup();
 }
}

GWTでCookieを扱う

GWTでCookieを扱ってみた。

クライアント側のコード
import com.google.gwt.user.client.Cookies; 

略
  Cookies.setCookie("COOKIE_NAME", edUserName.getText());

サーバ側でこれらを取得する場合
Cookie[] cookies = getThreadLocalRequest().getCookies();
 if (cookies != null) {
  for (Cookie cookie : cookies) {
 System.out.println(cookie.getName()+cookie.getValue());
 } 
}