source: greenstone3/trunk/src/java/org/greenstone/admin/gui/MatWorkingCopy.java@ 18268

Last change on this file since 18268 was 18268, checked in by cc108, 15 years ago

this file replaces WorkingCopy

File size: 3.9 KB
Line 
1package org.greenstone.admin.gui;
2
3import java.io.File;
4
5import javax.swing.JFrame;
6import javax.swing.JOptionPane;
7import javax.swing.JTextArea;
8
9import org.tmatesoft.svn.core.SVNException;
10import org.tmatesoft.svn.core.SVNURL;
11import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
12import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
13import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
14import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
15import org.tmatesoft.svn.core.wc.SVNClientManager;
16import org.tmatesoft.svn.core.wc.SVNRevision;
17import org.tmatesoft.svn.core.wc.SVNUpdateClient;
18import org.tmatesoft.svn.core.wc.SVNWCUtil;
19import org.tmatesoft.svn.core.wc.ISVNEventHandler;
20
21public class MatWorkingCopy {
22
23 private static SVNClientManager ourClientManager;
24 private static ISVNEventHandler myMatUpdateEventHandler;
25 public static boolean suc = true;
26 JTextArea messageTextArea;
27
28
29 public void Download(JTextArea messageArea,String svnURL, String destination, String extensionName) throws SVNException {
30
31 messageTextArea = messageArea;
32 setupLibrary();
33 SVNURL repositoryURL = null;
34 try {
35 repositoryURL = SVNURL.parseURIEncoded(svnURL);
36 } catch (SVNException e) {
37 e.printStackTrace();
38 }
39 String name = "";
40 String password = "";
41 String myMatWorkingCopyPath = destination;
42
43
44 SVNURL url = repositoryURL;
45
46 myMatUpdateEventHandler = new MatUpdateEventHandler(messageTextArea, destination, extensionName);
47
48 DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
49
50 ourClientManager = SVNClientManager.newInstance(options, name, password);
51
52 ourClientManager.getUpdateClient().setEventHandler(myMatUpdateEventHandler);
53
54 File wcDir = new File(myMatWorkingCopyPath);
55 if (wcDir.exists()) {
56
57 Object[] option = {"Remove it!","Keep it!"};
58 int n = JOptionPane.showOptionDialog(new JFrame(),"The folder '"+ wcDir.getAbsolutePath() + "' already exists!","Attention",
59 JOptionPane.YES_NO_CANCEL_OPTION,
60 JOptionPane.QUESTION_MESSAGE,
61 null,
62 option,
63 option[0]);
64
65 if(n == 0){
66 deleteDir(wcDir);
67 }
68 else{return;}
69 }
70 wcDir.mkdirs();
71
72 messageTextArea.append("Checking out a working copy from '" + url + "'...\n");
73
74 try {
75 checkout(url, SVNRevision.HEAD, wcDir, true);
76 } catch (SVNException svne) {
77 error("error while checking out a working copy for the location '"
78 + url + "'", svne);
79 }
80
81 }
82
83 private static boolean deleteDir(File dir) {
84
85 if (dir.isDirectory()) {
86 String[] children = dir.list();
87 for (int i=0; i<children.length; i++) {
88 boolean success = deleteDir(new File(dir, children[i]));
89 if (!success) {
90 return false;
91 }
92 }
93 }
94 return dir.delete();
95 }
96
97 private static void setupLibrary() {
98
99 DAVRepositoryFactory.setup();
100
101 SVNRepositoryFactoryImpl.setup();
102
103 FSRepositoryFactory.setup();
104 }
105
106 private static void checkout(SVNURL url,
107 SVNRevision revision, File destPath, boolean isRecursive)
108 throws SVNException {
109
110 SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
111
112 updateClient.setIgnoreExternals(false);
113
114 long x = updateClient.doCheckout(url, destPath, revision, revision, isRecursive);
115
116 }
117
118 public boolean getStatus(){
119 return suc;
120 }
121
122 private static void error(String message, Exception e){
123 System.err.println(message+(e!=null ? ": "+e.getMessage() : ""));
124 JOptionPane.showMessageDialog(new JFrame(),Mat.DownloadErrorMsg);
125 suc = false;
126 }
127}
Note: See TracBrowser for help on using the repository browser.