diff src/com/five_ten_sg/connectbot/transport/TN5250.java @ 12:6aaefb22d876 tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 18:41:36 -0700
parents f3b3bbd227b8
children b39bcf616a6f
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/transport/TN5250.java	Thu May 22 18:26:27 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/TN5250.java	Thu May 22 18:41:36 2014 -0700
@@ -25,6 +25,9 @@
 import java.util.List;
 import java.util.Map;
 
+import org.tn5250j.framework.tn5250.Screen5250;
+import org.tn5250j.framework.tn5250.tnvt;
+
 import com.five_ten_sg.connectbot.bean.HostBean;
 import com.five_ten_sg.connectbot.bean.PortForwardBean;
 import com.five_ten_sg.connectbot.service.TerminalBridge;
@@ -34,7 +37,6 @@
 import android.content.Context;
 import android.net.Uri;
 
-import org.tn5250j.framework.tn5250.tnvt;
 
 
 /**
@@ -57,6 +59,12 @@
 
     private boolean connected = false;
 
+    static final Pattern hostmask;
+    static {
+        hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE);
+    }
+
+
     public TN5250() {
        super();
    }
@@ -74,12 +82,41 @@
        return PROTOCOL;
    }
 
-   /**
-    * Encode the current transport into a URI that can be passed via intent calls.
-    * @return URI to host
-    */
-   public static Uri getUri(String input) {
-       return null;
+   public Uri getUri(String input) {
+        Matcher matcher = hostmask.matcher(input);
+
+        if (!matcher.matches())
+            return null;
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(PROTOCOL)
+        .append("://")
+        .append(matcher.group(1));
+        String portString = matcher.group(3);
+        int port = DEFAULT_PORT;
+
+        if (portString != null) {
+            try {
+                port = Integer.parseInt(portString);
+
+                if (port < 1 || port > 65535) {
+                    port = DEFAULT_PORT;
+                }
+            }
+            catch (NumberFormatException nfe) {
+                // Keep the default port
+            }
+        }
+
+        if (port != DEFAULT_PORT) {
+            sb.append(':');
+            sb.append(port);
+        }
+
+        sb.append("/#")
+        .append(Uri.encode(input));
+        Uri uri = Uri.parse(sb.toString());
+        return uri;
    }
 
    /**
@@ -373,7 +410,7 @@
     }
 
 
-    public static String getFormatHint(Context context) {
+    public String getFormatHint(Context context) {
         return String.format("%s:%s",
                              context.getString(R.string.format_hostname),
                              context.getString(R.string.format_port));