List of usage examples for org.apache.commons.lang StringUtils indexOf
public static int indexOf(String str, String searchStr)
Finds the first index within a String, handling null
.
From source file:org.apache.ranger.plugin.util.RangerPerfTracer.java
public static RangerPerfTracer getPerfTracer(Log logger, String tag) { String data = ""; String realTag = ""; if (tag != null) { int indexOfTagEndMarker = StringUtils.indexOf(tag, tagEndMarker); if (indexOfTagEndMarker != -1) { realTag = StringUtils.substring(tag, 0, indexOfTagEndMarker); data = StringUtils.substring(tag, indexOfTagEndMarker); } else {/*ww w. j a v a 2s . c om*/ realTag = tag; } } return RangerPerfTracerFactory.getPerfTracer(logger, realTag, data); }
From source file:org.bigmouth.nvwa.utils.url.URLDecoder.java
/** * URL???/*from w w w. ja v a 2 s.co m*/ * * @param <T> * @param url * ?URL? * <ul> * <li>http://www.big-mouth.cn/nvwa-utils/xml/decoder?id=123&json_data=bbb</li> * <li>/nvwa-utils/xml/decoder?id=123&json_data=bbb</li> * <li>id=123&json_data=bbb</li> * </li> * </ul> * @param cls * @return * @throws Exception */ public static <T> T decode(String url, Class<T> cls) throws Exception { if (StringUtils.isBlank(url)) return null; T t = cls.newInstance(); String string = null; if (StringUtils.contains(url, "?")) { string = StringUtils.substringAfter(url, "?"); } else { int start = StringUtils.indexOf(url, "?") + 1; string = StringUtils.substring(url, start); } Map<String, Object> attrs = Maps.newHashMap(); String[] kvs = StringUtils.split(string, "&"); for (String kv : kvs) { String[] entry = StringUtils.split(kv, "="); if (entry.length <= 1) { continue; } else if (entry.length == 2) { attrs.put(entry[0], entry[1]); } else { List<String> s = Lists.newArrayList(entry); s.remove(0); attrs.put(entry[0], StringUtils.join(s.toArray(new String[0]), "=")); } } Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { // if the field name is 'appId' String fieldName = field.getName(); String paramName = fieldName; if (field.isAnnotationPresent(Argument.class)) { paramName = field.getAnnotation(Argument.class).name(); } // select appId node Object current = attrs.get(paramName); if (null == current) { // select appid node current = attrs.get(paramName.toLowerCase()); } if (null == current) { // select APPID node current = attrs.get(paramName.toUpperCase()); } if (null == current) { // select app_id node String nodename = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(paramName), "_") .toLowerCase(); current = attrs.get(nodename); } if (null == current) { // select APP_ID node String nodename = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(paramName), "_") .toUpperCase(); current = attrs.get(nodename); } if (null != current) { String invokeName = StringUtils.join(new String[] { "set", StringUtils.capitalize(fieldName) }); try { MethodUtils.invokeMethod(t, invokeName, current); } catch (NoSuchMethodException e) { LOGGER.warn("NoSuchMethod-" + invokeName); } catch (IllegalAccessException e) { LOGGER.warn("IllegalAccess-" + invokeName); } catch (InvocationTargetException e) { LOGGER.warn("InvocationTarget-" + invokeName); } } } return t; }
From source file:org.bigmouth.nvwa.zookeeper.config.ZkPropertyPlaceholderConfigurer.java
private Properties convert(byte[] data) { Properties properties = new Properties(); String string = null;/*from w w w . j a va2 s . c o m*/ try { string = new String(data, "UTF-8"); } catch (UnsupportedEncodingException e) { string = new String(data); } if (StringUtils.isNotBlank(string)) { String[] items = StringUtils.split(string, ITEM_SPLIT); for (String item : items) { if (StringUtils.isBlank(item)) { continue; } if (StringUtils.startsWith(item, "#")) { continue; } int index = StringUtils.indexOf(item, PROPERTY_SPLIT); String key = StringUtils.substring(item, 0, index); String value = StringUtils.substring(item, index + 1); properties.put(StringUtils.trim(key), StringUtils.trim(value)); } } return properties; }
From source file:org.cesecore.certificates.ca.X509CA.java
/** * Constructs the SubjectAlternativeName extension that will end up on the generated certificate. * /*from w w w .j av a 2 s.c o m*/ * If the DNS values in the subjectAlternativeName extension contain parentheses to specify labels that should be redacted, the parentheses are removed and another extension * containing the number of redacted labels is added. * * @param subAltNameExt * @param publishToCT * @return An extension generator containing the SubjectAlternativeName extension and an extension holding the number of redacted labels if the certificate is to be published * to a CTLog * @throws IOException */ private ExtensionsGenerator getSubjectAltNameExtensionForCert(Extension subAltNameExt, boolean publishToCT) throws IOException { String subAltName = CertTools.getAltNameStringFromExtension(subAltNameExt); List<String> dnsValues = CertTools.getPartsFromDN(subAltName, CertTools.DNS); int[] nrOfRecactedLables = new int[dnsValues.size()]; boolean sanEdited = false; int i = 0; for (String dns : dnsValues) { if (StringUtils.contains(dns, "(") && StringUtils.contains(dns, ")")) { // if it contains parts that should be redacted // Remove the parentheses from the SubjectAltName that will end up on the certificate String certBuilderDNSValue = StringUtils.remove(dns, '('); certBuilderDNSValue = StringUtils.remove(certBuilderDNSValue, ')'); subAltName = StringUtils.replace(subAltName, dns, certBuilderDNSValue); sanEdited = true; if (publishToCT) { String redactedLable = StringUtils.substring(dns, StringUtils.indexOf(dns, "("), StringUtils.lastIndexOf(dns, ")") + 1); // tex. (top.secret).domain.se => redactedLable = (top.secret) aka. including the parentheses nrOfRecactedLables[i] = StringUtils.countMatches(redactedLable, ".") + 1; } } i++; } ExtensionsGenerator gen = new ExtensionsGenerator(); gen.addExtension(Extension.subjectAlternativeName, subAltNameExt.isCritical(), CertTools.getGeneralNamesFromAltName(subAltName)); // If there actually are redacted parts, add the extension containing the number of redacted lables to the certificate if (publishToCT && sanEdited) { ASN1EncodableVector v = new ASN1EncodableVector(); for (int val : nrOfRecactedLables) { v.add(new ASN1Integer(val)); } ASN1Encodable seq = new DERSequence(v); gen.addExtension(new ASN1ObjectIdentifier("1.3.6.1.4.1.11129.2.4.6"), false, seq); } return gen; }
From source file:org.cesecore.certificates.ca.X509CA.java
/** * Constructs the SubjectAlternativeName extension that will end up on the certificate published to a CTLog * /*from www . j a va 2 s .c o m*/ * If the DNS values in the subjectAlternativeName extension contain parentheses to specify labels that should be redacted, these labels will be replaced by the string "PRIVATE" * * @param subAltNameExt * @returnAn extension generator containing the SubjectAlternativeName extension * @throws IOException */ private ExtensionsGenerator getSubjectAltNameExtensionForCTCert(Extension subAltNameExt) throws IOException { String subAltName = CertTools.getAltNameStringFromExtension(subAltNameExt); List<String> dnsValues = CertTools.getPartsFromDN(subAltName, CertTools.DNS); for (String dns : dnsValues) { if (StringUtils.contains(dns, "(") && StringUtils.contains(dns, ")")) { // if it contains parts that should be redacted String redactedLable = StringUtils.substring(dns, StringUtils.indexOf(dns, "("), StringUtils.lastIndexOf(dns, ")") + 1); // tex. (top.secret).domain.se => redactedLable = (top.secret) aka. including the parentheses subAltName = StringUtils.replace(subAltName, redactedLable, "(PRIVATE)"); } } ExtensionsGenerator gen = new ExtensionsGenerator(); gen.addExtension(Extension.subjectAlternativeName, subAltNameExt.isCritical(), CertTools.getGeneralNamesFromAltName(subAltName).getEncoded()); return gen; }
From source file:org.cloudbyexample.dc.agent.command.ImageIdMatcher.java
public String findId(String line) { String id = null;//from w ww .jav a 2 s. c o m int matchIndex = StringUtils.indexOf(line, pattern); if (matchIndex > -1) { int start = matchIndex + pattern.length(); int end = line.length() - 4; id = StringUtils.substring(line, start, end); } return id; }
From source file:org.displaytag.tags.DataGridCustomiztionUtil.java
private static boolean isSelectBox(String title) { return StringUtils.indexOf(title, "<div>Select</div>") != -1; }
From source file:org.eclipse.wb.android.internal.support.DeviceManager.java
/** * @return the {@link DisplayMetrics} for given xVGA+dpi string or <code>null</code> if unknown. *///from www.java2 s . c o m public static DisplayMetrics getXvgaDpiMetrics(final String value) { int delimiter = StringUtils.indexOf(value, "/"); if (delimiter == -1) { return null; } String xvgaString = StringUtils.substring(value, 0, delimiter); String densityString = StringUtils.substring(value, delimiter + 1); Dimension resolution = parseXvga(xvgaString); DisplayMetrics metrics; if (resolution != null) { Density density = parseDensity(densityString); metrics = new DisplayMetricsImpl(resolution.width, resolution.height, density) { @Override public String getPrompt() { return value; } @Override public void setThis(IResource resource) { try { resource.setPersistentProperty(KEY_xVGA_DPI, value); } catch (Exception e) { DesignerPlugin.log(e); } }; }; } else { // unknown metrics = null; } return metrics; }
From source file:org.gaixie.micrite.common.search.SearchFactory.java
private static String[] detach(String str, char left, char right) { String string = str;//from w ww . j a va2s . co m if (string == null || string.equals("")) return null; List<String> list = new ArrayList<String>(); if (StringUtils.indexOf(string, left) == -1 || StringUtils.indexOf(string, right) == -1) throw new RasterFormatException("??: " + string); while (StringUtils.indexOf(string, left) >= 0 && StringUtils.indexOf(string, right) >= 0) { int il = StringUtils.indexOf(string, left); int ir = StringUtils.indexOf(string, right); if (il > ir) { string = StringUtils.substring(string, right + 1); continue; } list.add(StringUtils.substring(string, il + 1, ir)); string = StringUtils.substring(string, ir + 1); } return list.toArray(new String[list.size()]); }
From source file:org.gaixie.micrite.security.service.impl.LoginServiceImpl.java
public List<Map<String, Object>> loadChildNodes(User user, String node) { Set<Map<String, Object>> menu = new HashSet<Map<String, Object>>(); Set<Role> roles = user.getRoles(); String name, iconCls;// w w w. ja va 2s.c o m int order; for (Role role : roles) { List<Authority> auths = authorityDAO.findByRoleId(role.getId()); for (Authority auth : auths) { // "/"?menu if (StringUtils.indexOf(auth.getName(), "/") >= 0) { // if(auth.getName().matches("/CRM Modules/Customer List"))continue; if (auth.getState() != 0) continue; // /* // * ?????idtext ?User3??( // * "/N1/N2/N3" , "/N1/N4" "/N5" ) // * 3???split?token?"N1""N5" // * 2"N1"Set???add // * ?map?put?(url)???? N1: // * 1,2??substring"/N2/N3""N4"??split?"N2""N4" // * 3?????continue // */ if ("allModulesRoot".equals(node)) { // // if(auth.getName().matches("/Security Modules/User List")){ // String tmp1 = "/?/"; // auth.setName(tmp1); // } // if(auth.getName().matches("/Security Modules/Authority List")){ // String tmp2 = "/?/?"; // auth.setName(tmp2) ; // } // if(auth.getName().matches("/Security Modules/Role List")){ // String tmp3 ="/?/??"; // auth.setName(tmp3); // } name = auth.getName(); iconCls = auth.getIconCls1(); order = auth.getOrder1(); /* * "/"???? * /HTTP/HTTP POST * /MMS/HTTP MT/HTTP MT Top20 Cell */ } else if (StringUtils.indexOf(auth.getName(), node + "/") >= 0) { name = StringUtils.substringAfter(auth.getName(), node + "/"); iconCls = auth.getIconCls2(); order = auth.getOrder2(); } else continue; Map<String, Object> map = new HashMap<String, Object>(); String[] names = StringUtils.split(name, "/"); map.put("text", names[0]); map.put("id", "/" + names[0]); if (iconCls != null) map.put("iconCls", iconCls); map.put("sort", order); if (names.length > 1) { // ???url??name??node map.put("url", names[0]); map.put("leaf", false); } else { // "/"?"*"??extjs autoload map.put("url", StringUtils.substring(auth.getValue(), 1, auth.getValue().length() - 1)); map.put("leaf", true); } menu.add(map); } } } List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(menu); Collections.sort(list, new Comparator<Map<String, Object>>() { public int compare(Map<String, Object> o1, Map<String, Object> o2) { //return (o2.getValue() - o1.getValue()); return ((Integer) o1.get("sort")) - ((Integer) o2.get("sort")); } }); for (int i = 0; i < list.size(); i++) { list.get(i).remove("sort"); } // return menu; return list; }