List of usage examples for org.apache.commons.lang3 StringUtils endsWith
public static boolean endsWith(final CharSequence str, final CharSequence suffix)
Check if a CharSequence ends with a specified suffix.
null s are handled without exceptions.
From source file:com.joint.base.util.excel.ImportExcel.java
/** * ??/* w ww . ja v a 2s .c o m*/ * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); }; }); //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // If is dict type, get dict value if (StringUtils.isNotBlank(ef.dictType())) { //val = DictUtils.getDictValue(val.toString(), ef.dictType(), ""); //log.debug("Dictionary type value: ["+i+","+colunm+"] " + val); } // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { Reflections.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } Reflections.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:com.ottogroup.bi.streaming.operator.json.statsd.StatsdExtractedMetricsReporter.java
/** * Extract and reports a execution time value * @param metricCfg //from w w w. j a v a 2s . co m * The field configuration providing information on how to access and export content from JSON. Value is expected not to be null * @param json * The {@link JSONObject} to extract information from. Value is expected not to be null */ protected void reportTime(final StatsdMetricConfig metricCfg, final JSONObject json) { String path = null; if (metricCfg.getDynamicPathPrefix() != null) { try { String dynPathPrefix = this.jsonUtils.getTextFieldValue(json, metricCfg.getDynamicPathPrefix().getPath(), false); if (StringUtils.isNotBlank(dynPathPrefix)) path = dynPathPrefix + (!StringUtils.endsWith(dynPathPrefix, ".") ? "." : "") + metricCfg.getPath(); else path = metricCfg.getPath(); } catch (Exception e) { // do nothing path = metricCfg.getPath(); } } else { path = metricCfg.getPath(); } if (metricCfg.getJsonRef().getContentType() == JsonContentType.INTEGER) { try { final Integer value = this.jsonUtils.getIntegerFieldValue(json, metricCfg.getJsonRef().getPath()); if (value != null) this.statsdClient.recordExecutionTime(path, value.longValue()); } catch (Exception e) { // do nothing } } else if (metricCfg.getJsonRef().getContentType() == JsonContentType.TIMESTAMP) { try { final Date value = this.jsonUtils.getDateTimeFieldValue(json, metricCfg.getJsonRef().getPath(), metricCfg.getJsonRef().getConversionPattern()); if (value != null) this.statsdClient.recordExecutionTimeToNow(path, value.getTime()); } catch (Exception e) { // do nothing } } else { // } }
From source file:com.surevine.gateway.scm.IncomingProcessorImpl.java
private Path findFileEndsWith(final Collection<Path> paths, final String endsWith) { for (final Path entry : paths) { final String lastPath = entry.getName(entry.getNameCount() - 1).toString(); if (StringUtils.endsWith(lastPath, endsWith)) { return entry; }/*from ww w.j ava2s . co m*/ } return null; }
From source file:io.wcm.handler.richtext.impl.RichTextRewriteContentHandlerImpl.java
/** * Support legacy data structures where link metadata is stored as JSON fragment in rel attribute. * @param pResourceProps Valuemap to write link metadata to * @param element Link element/*from www . j a v a 2s .c o m*/ */ private void getAnchorLegacyMetadataFromRel(ValueMap pResourceProps, Element element) { // Check href attribute - do not change elements with no href or links to anchor names String href = element.getAttributeValue("href"); String linkWindowTarget = element.getAttributeValue("target"); if (href == null || href.startsWith("#")) { return; } // get link metadata from rel element JSONObject metadata = null; String metadataString = element.getAttributeValue("rel"); if (StringUtils.isNotEmpty(metadataString)) { try { metadata = new JSONObject(metadataString); } catch (JSONException ex) { RichTextHandlerImpl.log.debug("Invalid link metadata: " + metadataString, ex); } } if (metadata == null) { metadata = new JSONObject(); } // transform link metadata to virtual JCR resource with JCR properties JSONArray metadataPropertyNames = metadata.names(); if (metadataPropertyNames != null) { for (int i = 0; i < metadataPropertyNames.length(); i++) { String metadataPropertyName = metadataPropertyNames.optString(i); // check if value is array JSONArray valueArray = metadata.optJSONArray(metadataPropertyName); if (valueArray != null) { // store array values List<String> values = new ArrayList<String>(); for (int j = 0; j < valueArray.length(); j++) { values.add(valueArray.optString(j)); } pResourceProps.put(metadataPropertyName, values.toArray(new String[values.size()])); } else { // store simple value Object value = metadata.opt(metadataPropertyName); if (value != null) { pResourceProps.put(metadataPropertyName, value); } } } } // detect link type LinkType linkType = null; String linkTypeString = pResourceProps.get(LinkNameConstants.PN_LINK_TYPE, String.class); for (Class<? extends LinkType> candidateClass : linkHandlerConfig.getLinkTypes()) { LinkType candidate = AdaptTo.notNull(adaptable, candidateClass); if (StringUtils.isNotEmpty(linkTypeString)) { if (StringUtils.equals(linkTypeString, candidate.getId())) { linkType = candidate; break; } } else if (candidate.accepts(href)) { linkType = candidate; break; } } if (linkType == null) { // skip further processing if link type was not detected return; } // workaround: strip off ".html" extension if it was added automatically by the RTE if (linkType instanceof InternalLinkType || linkType instanceof MediaLinkType) { String htmlSuffix = "." + FileExtension.HTML; if (StringUtils.endsWith(href, htmlSuffix)) { href = StringUtils.substringBeforeLast(href, htmlSuffix); } } // store link reference (property depending on link type) pResourceProps.put(linkType.getPrimaryLinkRefProperty(), href); pResourceProps.put(LinkNameConstants.PN_LINK_WINDOW_TARGET, linkWindowTarget); }
From source file:com.nike.cerberus.auth.connector.onelogin.OneLoginAuthConnector.java
/** * Builds the full URL for preforming an operation against Vault. * * @param path Path for the requested operation * @return Full URL to execute a request against *//* w ww . j a va 2 s .com*/ protected HttpUrl buildUrl(final String path) { String baseUrl = oneloginApiUri.toString(); if (!StringUtils.endsWith(baseUrl, "/")) { baseUrl += "/"; } return HttpUrl.parse(baseUrl + path); }
From source file:ching.icecreaming.action.ResourceDescriptors.java
private boolean searchFilter(String searchField, String searchOper, String searchString, Object object1) { boolean result1 = true; String string1 = null;//www.jav a2 s. com Integer integer1 = null; java.sql.Timestamp timestamp1 = null; org.joda.time.DateTime dateTime1 = null, dateTime2 = null; DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); java.util.Date date1 = null; if (object1 instanceof String) { string1 = (String) object1; switch (searchOper) { case "eq": result1 = StringUtils.equals(string1, searchString); break; case "ne": result1 = !StringUtils.equals(string1, searchString); break; case "bw": result1 = StringUtils.startsWith(string1, searchString); break; case "bn": result1 = !StringUtils.startsWith(string1, searchString); break; case "ew": result1 = StringUtils.endsWith(string1, searchString); break; case "en": result1 = !StringUtils.endsWith(string1, searchString); break; case "cn": result1 = StringUtils.contains(string1, searchString); break; case "nc": result1 = !StringUtils.contains(string1, searchString); break; case "nu": result1 = StringUtils.isBlank(string1); break; case "nn": result1 = StringUtils.isNotBlank(string1); break; case "in": case "ni": case "lt": case "le": case "gt": case "ge": default: break; } } else if (object1 instanceof Integer) { if (NumberUtils.isNumber(searchString)) { integer1 = (Integer) object1; switch (searchOper) { case "eq": result1 = (NumberUtils.toInt(searchString, 0) == integer1.intValue()); break; case "ne": result1 = (NumberUtils.toInt(searchString, 0) != integer1.intValue()); break; case "lt": result1 = (NumberUtils.toInt(searchString, 0) > integer1.intValue()); break; case "le": result1 = (NumberUtils.toInt(searchString, 0) >= integer1.intValue()); break; case "gt": result1 = (NumberUtils.toInt(searchString, 0) < integer1.intValue()); break; case "ge": result1 = (NumberUtils.toInt(searchString, 0) <= integer1.intValue()); break; case "bw": case "bn": case "ew": case "en": case "cn": case "nc": case "in": case "ni": case "nu": case "nn": default: break; } } } else if (object1 instanceof java.sql.Timestamp || object1 instanceof java.util.Date) { if (object1 instanceof java.sql.Timestamp) { timestamp1 = (java.sql.Timestamp) object1; dateTime1 = new org.joda.time.DateTime(timestamp1.getTime()); } else if (object1 instanceof java.util.Date) { date1 = (java.util.Date) object1; if (date1 != null) dateTime1 = new org.joda.time.DateTime(date1); } try { dateTime2 = dateTimeFormatter.parseDateTime(searchString); } catch (java.lang.IllegalArgumentException exception1) { dateTime2 = null; } if (dateTime2 != null && dateTime1 != null) { switch (searchOper) { case "eq": result1 = dateTime1.equals(dateTime2); break; case "ne": result1 = !dateTime1.equals(dateTime2); break; case "lt": result1 = dateTime1.isBefore(dateTime2); break; case "le": result1 = (dateTime1.isBefore(dateTime2) || dateTime1.equals(dateTime2)); break; case "gt": result1 = dateTime1.isAfter(dateTime2); break; case "ge": result1 = (dateTime1.isAfter(dateTime2) || dateTime1.equals(dateTime2)); break; case "bw": case "bn": case "ew": case "en": case "cn": case "nc": case "in": case "ni": break; case "nu": result1 = (timestamp1 == null); break; case "nn": result1 = (timestamp1 != null); break; default: break; } } } return !result1; }
From source file:com.pidoco.juri.JURI.java
/** * <pre>/* w w w .ja va 2 s. com*/ * "".addRawPath("") -> "" * "/".addRawPath("") -> "/" * "".addRawPath("/") -> "/" * "a".addRawPath("") -> "a/" * "a".addRawPath("b") -> "a/b" * "/".addRawPath("/") -> "/" * </pre> */ public static String concatRawPaths(CharSequence left, CharSequence right) { boolean needsSeparator = false; boolean rightStartsWithSlash = StringUtils.startsWith(right, "/"); int rightStart = 0; if (left.length() > 0) { if (StringUtils.endsWith(left, "/")) { if (rightStartsWithSlash) { rightStart = 1; } } else { if (!rightStartsWithSlash) { needsSeparator = true; } } } return left + (needsSeparator ? "/" : "") + right.subSequence(rightStart, right.length()); }
From source file:com.mirth.connect.server.Mirth.java
private String getWebServerUrl(String prefix, String host, int port, String contextPath) { if (StringUtils.equals(host, "0.0.0.0") || StringUtils.equals(host, "::")) { try {/*from w ww.j a va2 s .co m*/ host = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { host = "localhost"; } } else if (StringUtils.isEmpty(host)) { host = "localhost"; } if (!StringUtils.startsWith(contextPath, "/")) { contextPath = "/" + contextPath; } if (!StringUtils.endsWith(contextPath, "/")) { contextPath = contextPath + "/"; } return prefix + host + ":" + port + contextPath; }
From source file:com.nike.cerberus.service.SafeDepositBoxService.java
/** * Deletes all of the secrets from Vault stored at the safe deposit box's path. * * @param path path to start deleting at. *//*from w w w . ja v a 2s.c o m*/ private void deleteAllSecrets(final String path) { try { String fixedPath = path; if (StringUtils.endsWith(path, "/")) { fixedPath = StringUtils.substring(path, 0, StringUtils.lastIndexOf(path, "/")); } final VaultListResponse listResponse = vaultAdminClient.list(fixedPath); final List<String> keys = listResponse.getKeys(); if (keys == null || keys.isEmpty()) { return; } for (final String key : keys) { if (StringUtils.endsWith(key, "/")) { final String fixedKey = StringUtils.substring(key, 0, key.lastIndexOf("/")); deleteAllSecrets(fixedPath + "/" + fixedKey); } else { vaultAdminClient.delete(fixedPath + "/" + key); } } } catch (VaultClientException vce) { throw ApiException.newBuilder().withApiErrors(DefaultApiError.SERVICE_UNAVAILABLE) .withExceptionCause(vce).withExceptionMessage("Failed to delete secrets from Vault.").build(); } }
From source file:com.thinkbiganalytics.jobrepo.rest.controller.JobsRestController.java
/** * This will evaluate the {@code incomingFilter} and append/set the value including the {@code defaultFilter} and return a new String with the updated filter */// w w w . jav a2 s . c o m private String ensureDefaultFilter(String incomingFilter, String defaultFilter) { String filter = incomingFilter; if (StringUtils.isBlank(filter) || !StringUtils.containsIgnoreCase(filter, defaultFilter)) { if (StringUtils.isNotBlank(filter)) { if (StringUtils.endsWith(filter, ",")) { filter += defaultFilter; } else { filter += "," + defaultFilter; } } else { filter = defaultFilter; } } return filter; }