List of usage examples for java.lang String indexOf
public int indexOf(String str)
From source file:Main.java
public static String getDefaultNamespaceUri(URL xmlResource, String rootElementName) throws IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false);//from ww w . java2 s.co m DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(xmlResource.openStream()); NodeList nodes = document.getElementsByTagName(rootElementName); if (nodes == null || nodes.getLength() == 0) { throw new IllegalArgumentException("Root element \"" + rootElementName + "\" not found in xml \"" + xmlResource.toExternalForm() + "\"."); } for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); Node xmlns = node.getAttributes().getNamedItem("xmlns"); if (xmlns != null) { String value = xmlns.getNodeValue(); return value.substring(value.indexOf("=") + 1); } } return null; }
From source file:com.github.mybatis.repository.autoconfig.SpringBootVFS.java
private static String preserveSubpackageName(final URI uri, final String rootPath) { final String uriStr = uri.toString(); final int start = uriStr.indexOf(rootPath); return uriStr.substring(start); }
From source file:Main.java
/** * Get the non qualified tag name/*from w ww .j ava 2 s . co m*/ * * @param element element * * @return tag name */ public static String getLocalName(Node element) { String localName = element.getLocalName(); if (localName != null) { return localName; } String name = element.getNodeName(); int idx = name.indexOf(":"); if (idx >= 0) { name = name.substring(idx + 1); } return name; }
From source file:Main.java
public static String str_extr_betw(String lc_data, String lc_start_tag, String lc_end_tag) { String result = ""; int startLoc = lc_data.indexOf(lc_start_tag) + lc_start_tag.length(); int endLoc = lc_data.indexOf(lc_end_tag); // Common.Logit("startLoc=" + startLoc + " endloc=" + endLoc) ; result = lc_data.substring(startLoc, endLoc); return result; }
From source file:Main.java
public static String getVersionFromText(String reportText) { String start = "<chart version=\""; int index = reportText.indexOf(start); if (index == -1) { return null; }//from w ww . jav a 2 s. c o m index = index + start.length(); int lastIndex = reportText.indexOf("\"", index); if (lastIndex == -1) { return null; } else { return reportText.substring(index, lastIndex); } }
From source file:Main.java
public static String getValueFormURL(String url, String key) { key += "=";// w w w . j a v a2 s.co m if (url.contains(key)) { int aid = url.indexOf(key) + key.length(); if (url.indexOf("&", aid) != -1) { return url.substring(aid, url.indexOf("&", aid)); } else { return url.substring(aid, url.length()); } } else { return null; } }
From source file:Main.java
public static String getSize(long size) { if (size < 0) return null; String result = null;/*from ww w.ja v a 2s. c o m*/ if (size > 1024 * 1024 * 1024) { float f = (float) size / (1024 * 1024 * 1024); String s = String.valueOf(f); if (s.length() - s.indexOf(".") > 2) result = s.substring(0, s.indexOf(".") + 3); else result = s; return result + "GB"; } else if (size > 1024 * 1024) { float f = (float) size / (1024 * 1024); String s = String.valueOf(f); if (s.length() - s.indexOf(".") > 2) result = s.substring(0, s.indexOf(".") + 3); else result = s; return result + "MB"; } else if (size > 1024) { float f = (float) size / 1024; String s = String.valueOf(f); if (s.length() - s.indexOf(".") > 2) result = s.substring(0, s.indexOf(".") + 3); else result = s; return result + "KB"; } else if (size < 1024) { return String.valueOf(size) + "B"; } else return null; }
From source file:Main.java
public static String getRevisionIdSuffix(String revId) { validateRevisionId(revId);//from w w w . j av a2 s. c o m int dashPos = revId.indexOf("-"); if (dashPos >= 0) { return revId.substring(dashPos + 1); } else { throw new IllegalStateException("The revId id should be valid: " + revId); } }
From source file:Main.java
public static String getInstagramId(String in) { Uri uri = Uri.parse(in);/*from w w w. j av a2s . c om*/ final String host = uri.getHost(); if (TextUtils.isEmpty(host) == false && host.indexOf("instagram") >= 0) { return in; } return null; }
From source file:Main.java
public static String getVineId(String in) { Uri uri = Uri.parse(in);/* w w w . j a v a 2 s . co m*/ final String host = uri.getHost(); if (TextUtils.isEmpty(host) == false && host.indexOf("vine") >= 0) { return in; } return null; }