public static String Explorer_Messsage_PlatformLogReboot;
public static String Remote_Message_EmptyName;
+ public static String Remote_Message_EmptyIp;
public static String Remote_Message_InvalidIp;
+ public static String Remote_Message_EmptyPort;
public static String Remote_Message_InvalidPort;
static
Explorer_Messsage_PlatformLogReboot = You must reboot this target to apply the change.
-Remote_Message_EmptyName = Name is empty.\nPlease input name.
+Remote_Message_EmptyName = Name is empty.\nPlease input name.
+Remote_Message_EmptyIp = IP address is empty.\nPlease input IP address.
Remote_Message_InvalidIp = IP address is invalid.\nPlease input proper IP address.
-Remote_Message_InvalidPort = port is invalid.\nPlease input proper port.
+Remote_Message_EmptyPort = port is empty.\nPlease input port.
+Remote_Message_InvalidPort = port is invalid.\nPlease input proper port.
\ No newline at end of file
import org.tizen.common.util.DialogUtil;
import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.HostUtil;
+import org.tizen.common.util.ValidationUtil;
import org.tizen.sdblib.util.IOUtil;
+import org.tizen.sdblib.util.StringUtil;
public class RemoteDeviceManagerDialog extends Dialog
{
private static final String sdbConnectCommand = InstallPathConfig.getSDBPath() + " connect ";
private static final String sdbDisconnectCommand = InstallPathConfig.getSDBPath() + " disconnect ";
-
- private static final String IPADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
- private static final String PORT_PATTERN = "^(6553[0-5]|655[0-2]\\d|65[0-4]\\d\\d|6[0-4]\\d{3}|[1-5]\\d{4}|[1-9]\\d{0,3}|0)$";
private static final String REMOTE_DEVICE_LIST_FILE = InstallPathConfig.getUserDataPath() + File.separator + "ide" + File.separator + "remote_device.list";
private Button newButton;
private boolean isValidRemoteDevice(String name, String ip, String port)
{
- if (!name.equals(""))
+ if (!StringUtil.isEmpty(name))
{
- Pattern ipPattern = Pattern.compile(IPADDRESS_PATTERN);
- Matcher ipMatcher = ipPattern.matcher(ip);
-
- if (ipMatcher.find())
+ if (!StringUtil.isEmpty(ip))
{
- Pattern portPattern = Pattern.compile(PORT_PATTERN);
- Matcher portMatcher = portPattern.matcher(port);
-
- if (portMatcher.find())
+ if (ValidationUtil.checkForIP(ip))
{
- return true;
+ if (!StringUtil.isEmpty(port))
+ {
+ if (ValidationUtil.checkForPort(port))
+ {
+ return true;
+ }
+ else
+ {
+ DialogUtil.openErrorDialog("\"" + port + "\" " + ConnectionUIMessages.Remote_Message_InvalidPort);
+ }
+ }
+ else
+ {
+ DialogUtil.openErrorDialog(ConnectionUIMessages.Remote_Message_EmptyPort);
+ }
}
else
{
- DialogUtil.openErrorDialog("\"" + port + "\" " + ConnectionUIMessages.Remote_Message_InvalidPort);
+ DialogUtil.openErrorDialog("\"" + ip + "\" " + ConnectionUIMessages.Remote_Message_InvalidIp);
}
}
else
{
- DialogUtil.openErrorDialog("\"" + ip + "\" " + ConnectionUIMessages.Remote_Message_InvalidIp);
+ DialogUtil.openErrorDialog(ConnectionUIMessages.Remote_Message_EmptyIp);
}
}
else
private static final String REGEX_FILEURI = "([a-zA-Z0-9\\-_\\.!\\~\\*'\\(\\);\\?\\@\\&=\\+$,]|(%[a-fA-F0-9]{2}))*"; //$NON-NLS-1$
private static final String REGEX_VERSION = "[0-9]{1,3}\\.[0-9]{1,3}(\\.[0-9]{1,5})?"; //$NON-NLS-1$
private static final String REGEX_APPWIDGETID = "[0-9a-zA-Z]{10}\\.[0-9a-zA-Z]{1,52}\\.[0-9a-zA-Z]{1,}"; //$NON-NLS-1$
+ private static final String REGEX_IPADDRESS = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; //$NON-NLS-1$
+ private static final String REGEX_PORT = "^(6553[0-5]|655[0-2]\\d|65[0-4]\\d\\d|6[0-4]\\d{3}|[1-5]\\d{4}|[1-9]\\d{0,3}|0)$"; //$NON-NLS-1$
public static final String WIDGET_CONTENT_FILE_EXTENSIONS[] = { ".html", ".htm", ".xhtml", ".xht", ".svg" }; // http://www.w3.org/TR/widgets/#default-start-files
public static final String WIDGET_ICON_FILE_EXTENSIONS[] = { ".png", ".gif", ".jpg", ".ico" }; // http://www.w3.org/TR/widgets/#default-icons
}
/**
+ * Checking for IP address.
+ *
+ * @param ip
+ * @return {@code true} if id is valid IP
+ */
+ public static boolean checkForIP( String ip ) {
+ Pattern pattern = Pattern.compile( REGEX_IPADDRESS );
+ Matcher matcher = pattern.matcher( ip );
+ return matcher.matches();
+ }
+
+ /**
+ * Checking for port
+ *
+ * @param port
+ * @return {@code true} if id is valid port
+ */
+ public static boolean checkForPort( String port ) {
+ Pattern pattern = Pattern.compile( REGEX_PORT );
+ Matcher matcher = pattern.matcher( port );
+ return matcher.matches();
+ }
+
+ /**
* Checking for Widget icon file extension.
*
* @param Icon file name
assertFalse( "Failed for \"" + id + "\"", ValidationUtil.checkForFileURI( id ) );
}
}
+
+ /**
+ * Test {@link ValidationUtil#checkForIP(String value)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see {@link ValidationUtil#checkForIP(String value)}
+ */
+ @Test
+ public void test_checkForIP() throws Exception {
+ final String[] validedIPs = { "1.1.1.1", "11.11.11.11", "111.111.111.111", "255.255.255.255", "123.234.123.0" };
+ for ( String ip : validedIPs ) {
+ assertTrue( "Failed for \"" + ip + "\"", ValidationUtil.checkForIP( ip ) );
+ }
+
+ final String[] invalidedIPs = {"300.100.100.100", "1.1.1.1.1", "0.0.0.-1", "1.1.1.256", "a.1.1.1" };
+ for ( String ip : invalidedIPs) {
+ assertFalse( "Failed for \"" + ip + "\"", ValidationUtil.checkForIP( ip ) );
+ }
+ }
+
+ /**
+ * Test {@link ValidationUtil#checkForPort(String value)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see {@link ValidationUtil#checkForPort(String value)}
+ */
+ @Test
+ public void test_checkForPort() throws Exception {
+ final String[] validedPorts = { "0", "1", "12", "123", "1234", "65535" };
+ for ( String port : validedPorts ) {
+ assertTrue( "Failed for \"" + port + "\"", ValidationUtil.checkForPort( port ) );
+ }
+
+ final String[] invalidedPorts = {"-1", "a", "2a", "65536", "123456" };
+ for ( String port : invalidedPorts ) {
+ assertFalse( "Failed for \"" + port + "\"", ValidationUtil.checkForPort( port ) );
+ }
+ }
}