Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/transport/TransportFactory.java @ 428:b525a8141923
strip some debug code
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sun, 14 Dec 2014 19:02:48 -0800 |
parents | 77ac18bc1b2f |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot.transport; | |
19 | |
20 import java.util.HashMap; | |
21 import java.util.Map; | |
22 | |
23 import com.five_ten_sg.connectbot.bean.HostBean; | |
24 import com.five_ten_sg.connectbot.util.HostDatabase; | |
25 import android.content.Context; | |
26 import android.net.Uri; | |
27 import android.util.Log; | |
28 | |
29 | |
30 /** | |
31 * @author Kenny Root | |
32 * | |
33 */ | |
34 public class TransportFactory { | |
35 private static final String TAG = "ConnectBot.TransportFactory"; | |
36 | |
37 private static String[] transportNames = { | |
38 SSH.getProtocolName(), | |
11 | 39 TN5250.getProtocolName(), |
0 | 40 Telnet.getProtocolName(), |
41 Local.getProtocolName(), | |
42 }; | |
43 | |
44 /** | |
45 * @param protocol | |
46 * @return | |
47 */ | |
48 public static AbsTransport getTransport(String protocol) { | |
49 if (SSH.getProtocolName().equals(protocol)) { | |
50 return new SSH(); | |
51 } | |
11 | 52 else if (TN5250.getProtocolName().equals(protocol)) { |
53 return new TN5250(); | |
54 } | |
0 | 55 else if (Telnet.getProtocolName().equals(protocol)) { |
56 return new Telnet(); | |
57 } | |
58 else if (Local.getProtocolName().equals(protocol)) { | |
59 return new Local(); | |
60 } | |
61 else { | |
62 return null; | |
63 } | |
64 } | |
65 | |
13 | 66 public static Uri getUri(String protocol, String input) { |
0 | 67 Log.d("TransportFactory", String.format( |
13 | 68 "Attempting to discover URI for protocol=%s on input=%s", |
69 protocol, input)); | |
11 | 70 AbsTransport t = getTransport(protocol); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
71 |
11 | 72 if (t == null) return null; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
73 |
11 | 74 return t.getUri(input); |
0 | 75 } |
76 | |
77 public static String[] getTransportNames() { | |
78 return transportNames; | |
79 } | |
80 | |
81 public static boolean isSameTransportType(AbsTransport a, AbsTransport b) { | |
82 if (a == null || b == null) | |
83 return false; | |
84 | |
85 return a.getClass().equals(b.getClass()); | |
86 } | |
87 | |
88 public static boolean canForwardPorts(String protocol) { | |
11 | 89 AbsTransport t = getTransport(protocol); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
90 |
11 | 91 if (t == null) return false; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
92 |
11 | 93 return t.canForwardPorts(); |
0 | 94 } |
95 | |
96 /** | |
97 * @param protocol text name of protocol | |
98 * @param context | |
99 * @return expanded format hint | |
100 */ | |
101 public static String getFormatHint(String protocol, Context context) { | |
11 | 102 AbsTransport t = getTransport(protocol); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
103 |
11 | 104 if (t == null) return "???"; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
105 |
11 | 106 return t.getFormatHint(context); |
0 | 107 } |
108 | |
109 /** | |
110 * @param hostdb Handle to HostDatabase | |
111 * @param uri URI to target server | |
112 * @return HostBean or null | |
113 */ | |
114 public static HostBean findHost(HostDatabase hostdb, Uri uri) { | |
115 AbsTransport transport = getTransport(uri.getScheme()); | |
116 Map<String, String> selection = new HashMap<String, String>(); | |
117 transport.getSelectionArgs(uri, selection); | |
118 | |
119 if (selection.size() == 0) { | |
120 Log.e(TAG, String.format("Transport %s failed to do something useful with URI=%s", | |
121 uri.getScheme(), uri.toString())); | |
122 throw new IllegalStateException("Failed to get needed selection arguments"); | |
123 } | |
124 | |
125 return hostdb.findHost(selection); | |
126 } | |
127 } |