~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar-browser-ftp/src/org/herac/tuxguitar/gui/tools/browser/ftp/TGBrowserDataImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.gui.tools.browser.ftp;
 
2
 
 
3
import org.herac.tuxguitar.gui.tools.browser.base.TGBrowserData;
 
4
import org.herac.tuxguitar.gui.tools.browser.ftp.utils.Base64Decoder;
 
5
import org.herac.tuxguitar.gui.tools.browser.ftp.utils.Base64Encoder;
 
6
 
 
7
public class TGBrowserDataImpl implements TGBrowserData{
 
8
        
 
9
        private static final String STRING_SEPARATOR = ";";
 
10
        
 
11
        private String host;
 
12
        private String path;
 
13
        private String username;
 
14
        private String password;
 
15
        
 
16
        public TGBrowserDataImpl(String host,String path,String username,String password){
 
17
                this.host = host;
 
18
                this.path = path;
 
19
                this.username = username;
 
20
                this.password = password;
 
21
        }
 
22
        
 
23
        public String getHost() {
 
24
                return this.host;
 
25
        }
 
26
        
 
27
        public String getPath() {
 
28
                return this.path;
 
29
        }
 
30
        
 
31
        public String getPassword() {
 
32
                return ((this.username != null && this.username.length() > 0)?this.password:"anonymous");
 
33
        }
 
34
        
 
35
        public String getUsername() {
 
36
                return ((this.username != null && this.username.length() > 0)?this.username:"anonymous");
 
37
        }
 
38
        
 
39
        public String getTitle(){
 
40
                return (getHost() + ":" + getPath());
 
41
        }
 
42
        
 
43
        public String toString(){
 
44
                String username = new String( Base64Encoder.encode( getUsername().getBytes() ) );
 
45
                String password = new String( Base64Encoder.encode( getPassword().getBytes() ) );
 
46
                return getHost() + STRING_SEPARATOR + getPath() + STRING_SEPARATOR + username + STRING_SEPARATOR + password;
 
47
        }
 
48
        
 
49
        public static TGBrowserData fromString(String string) {
 
50
                String[] data = string.split(STRING_SEPARATOR);
 
51
                if(data.length == 4){
 
52
                        String username = new String( Base64Decoder.decode( data[2].getBytes() ) );
 
53
                        String password = new String( Base64Decoder.decode( data[3].getBytes() ) );
 
54
                        return new TGBrowserDataImpl(data[0],data[1],username,password);
 
55
                }
 
56
                return null;
 
57
        }
 
58
}