/** * Returns the protocol component from the url string.For eg, "http" * * @param url the input url string. * @return the protocol component of the url string. */ public static String getProtocolfromUrl(String url) { if (StringUtility.isPopulated(url)) { int idx = url.indexOf("://"); if (idx > -1) { return url.substring(0, idx); } } return null; }
public static int getInt(String name, int defaultValue) { String rawValue = localProperties.getProperty(name); if (!StringUtility.isNullOrEmpty(rawValue)) { try { return Integer.parseInt(rawValue); } catch (NumberFormatException e) { } } return defaultValue; }
/** * Returns the server name component from the url string.For eg, "http" * * @param url the input url string. * @return the server name component of the url string. */ public static String getServerNamefromUrl(String url) { if (StringUtility.isPopulated(url)) { int idx1 = url.indexOf("://"); if (idx1 > -1) { int idx2 = url.indexOf('/', idx1 + 3); if (idx2 > -1) { return url.substring(idx1 + 3, idx2); } } } return null; }
/** * Returns the path component from the url string. * * @param url the input url string. * @return the path component of the url string. */ public static String getPathfromUrl(String url) { if (StringUtility.isPopulated(url)) { int idx = url.indexOf("://"); if (idx > -1) { idx = url.indexOf('/', idx + 3); if (idx > -1) { return url.substring(idx, url.length()); } } } return null; }
public static String getNonEmptyString(String name) throws SystemFailureException { String value = localProperties.getProperty(name); if (StringUtility.isNullOrEmpty(value)) throw new SystemFailureException("Could not get property '%s'", name); return value; }
@Test public void testTableOnly() { String answer = StringUtility.composeFullyQualifiedTableName(null, null, "table", '.'); assertEquals("table", answer); }
@Test public void testAllPresent() { String answer = StringUtility.composeFullyQualifiedTableName("catalog", "schema", "table", '.'); assertEquals("catalog.schema.table", answer); }
@Test public void testNoSchema() { String answer = StringUtility.composeFullyQualifiedTableName("catalog", null, "table", '.'); assertEquals("catalog..table", answer); }
@Test public void testNoCatalog() { String answer = StringUtility.composeFullyQualifiedTableName(null, "schema", "table", '.'); assertEquals("schema.table", answer); }