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:io.wcm.devops.conga.plugins.aem.crypto.CryptoString.java
/** * Checks if the given string contains an encrypted string. * @param text String to check/*w w w. j a v a2s . c o m*/ * @return true if string is assumed to be encrypted */ public static boolean isCryptoString(final String text) { // very simplified check - just check for start and end of curly braces. return text != null && text.length() > 2 && StringUtils.startsWith(text, "{") && StringUtils.endsWith(text, "}"); }
From source file:com.thinkbiganalytics.jobrepo.rest.controller.QueryUtils.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 *//*from w w w.j a va2 s . co m*/ public static 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; }
From source file:ch.cyberduck.core.URIEncoder.java
/** * URL encode a path//from w ww . ja va2 s . com * * @param p Path * @return URI encoded * @see java.net.URLEncoder#encode(String, String) */ public static String encode(final String p) { try { final StringBuilder b = new StringBuilder(); final StringTokenizer t = new StringTokenizer(p, "/"); if (!t.hasMoreTokens()) { return p; } if (StringUtils.startsWith(p, String.valueOf(Path.DELIMITER))) { b.append(Path.DELIMITER); } while (t.hasMoreTokens()) { b.append(URLEncoder.encode(t.nextToken(), "UTF-8")); if (t.hasMoreTokens()) { b.append(Path.DELIMITER); } } if (StringUtils.endsWith(p, String.valueOf(Path.DELIMITER))) { b.append(Path.DELIMITER); } // Because URLEncoder uses <code>application/x-www-form-urlencoded</code> we have to replace these // for proper URI percented encoding. return b.toString().replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } catch (UnsupportedEncodingException e) { return p; } }
From source file:com.norconex.collector.http.pipeline.importer.HttpImporterPipelineUtil.java
public static void enhanceHTTPHeaders(HttpMetadata metadata) { if (StringUtils.isNotBlank(metadata.getString(HttpMetadata.COLLECTOR_CONTENT_TYPE))) { return;//from w w w. ja v a 2s . com } String contentType = metadata.getString(HttpMetadata.HTTP_CONTENT_TYPE); if (StringUtils.isBlank(contentType)) { for (String key : metadata.keySet()) { if (StringUtils.endsWith(key, HttpMetadata.HTTP_CONTENT_TYPE)) { contentType = metadata.getString(key); } } } if (StringUtils.isNotBlank(contentType)) { String mimeType = contentType.replaceFirst("(.*?)(;.*)", "$1"); String charset = contentType.replaceFirst("(.*?)(; )(.*)", "$3"); charset = charset.replaceFirst("(charset=)(.*)", "$2"); metadata.addString(HttpMetadata.COLLECTOR_CONTENT_TYPE, mimeType); metadata.addString(HttpMetadata.COLLECTOR_CONTENT_ENCODING, charset); } }
From source file:com.github.helenusdriver.driver.ObjectNotFoundException.java
/** * Handles special case where a keyspace is not defined by throwing a * {@link ObjectNotFoundException} if the specified exception matches that * specific condition.//from w ww .j av a 2 s .c o m * * @author paouelle * * @param clazz the pojo class we queried * @param e the invalid query exception to handle * @throws ObjectNotFoundException if the keyspace is not found */ public static void handleKeyspaceNotFound(Class<?> clazz, InvalidQueryException e) throws ObjectNotFoundException { final String msg = e.getMessage(); if (StringUtils.startsWithIgnoreCase(msg, "keyspace ") && StringUtils.endsWith(msg, "does not exist")) { throw new ObjectNotFoundException(clazz, msg); } }
From source file:io.stallion.dataAccess.file.ListingEndpoints.java
public static void register() { for (ContentFolder config : Settings.instance().getFolders()) { if (config.isListingEnabled()) { String rootUrl = config.getListingRootUrl(); if (StringUtils.endsWith(rootUrl, "/")) { rootUrl = rootUrl.substring(0, rootUrl.length() - 1); }/*ww w.j av a 2 s.c om*/ EndpointsRegistry.instance().addResource(rootUrl, new ListingEndpoints(config)); } } }
From source file:com.github.ferstl.depgraph.dot.AttributeBuilder.java
public AttributeBuilder label(String label) { if (StringUtils.startsWith(label, "<") && StringUtils.endsWith(label, ">")) { this.attributes.put("label", label); return this; }//w ww. java2s.c o m return addAttribute("label", label); }
From source file:com.github.ferstl.depgraph.graph.dot.DotAttributeBuilder.java
public DotAttributeBuilder label(String label) { if (StringUtils.startsWith(label, "<") && StringUtils.endsWith(label, ">")) { this.attributes.put("label", label); return this; }// w ww . jav a 2s . c om return addAttribute("label", label); }
From source file:com.nridge.core.base.field.data.DataBeanBag.java
private static DataField reflectField(Object anObject, Field aField) throws NoSuchFieldException, IllegalAccessException { DataField dataField;/* ww w . jav a 2 s . c o m*/ String fieldName, fieldValue, fieldTitle; com.nridge.core.base.field.Field.Type fieldType; fieldName = aField.getName(); fieldTitle = com.nridge.core.base.field.Field.nameToTitle(fieldName); Class<?> classFieldType = aField.getType(); Object fieldObject = aField.get(anObject); if ((StringUtils.endsWith(classFieldType.getName(), "Integer")) || (StringUtils.endsWith(classFieldType.getName(), "int"))) { fieldType = com.nridge.core.base.field.Field.Type.Integer; fieldValue = fieldObject.toString(); dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue); } else if ((StringUtils.endsWith(classFieldType.getName(), "Float")) || (StringUtils.endsWith(classFieldType.getName(), "float"))) { fieldType = com.nridge.core.base.field.Field.Type.Float; fieldValue = fieldObject.toString(); dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue); } else if ((StringUtils.endsWith(classFieldType.getName(), "Double")) || (StringUtils.endsWith(classFieldType.getName(), "double"))) { fieldType = com.nridge.core.base.field.Field.Type.Double; fieldValue = fieldObject.toString(); dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue); } else if ((StringUtils.endsWith(classFieldType.getName(), "Boolean")) || (StringUtils.endsWith(classFieldType.getName(), "boolean"))) { fieldType = com.nridge.core.base.field.Field.Type.Boolean; fieldValue = fieldObject.toString(); dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue); } else if (StringUtils.endsWith(classFieldType.getName(), "Date")) { fieldType = com.nridge.core.base.field.Field.Type.Date; Date fieldDate = (Date) fieldObject; fieldValue = com.nridge.core.base.field.Field.dateValueFormatted(fieldDate, null); dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue); } else { fieldType = com.nridge.core.base.field.Field.Type.Text; if (fieldObject instanceof String[]) { String[] fieldValues = (String[]) fieldObject; dataField = new DataField(fieldType, fieldName, fieldTitle); dataField.setMultiValueFlag(true); dataField.setValues(fieldValues); } else if (fieldObject instanceof Collection) { ArrayList<String> fieldValues = (ArrayList<String>) fieldObject; dataField = new DataField(fieldType, fieldName, fieldTitle); dataField.setMultiValueFlag(true); dataField.setValues(fieldValues); } else { fieldValue = fieldObject.toString(); dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue); } } return dataField; }
From source file:kenh.expl.functions.EndsWith.java
public boolean process(String str, String suffix, boolean ignoreCase) { if (ignoreCase) return StringUtils.endsWithIgnoreCase(str, suffix); else//from w w w. jav a2s. co m return StringUtils.endsWith(str, suffix); }