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:org.alfresco.dataprep.CMISUtil.java
/** * Get cmis object by path//from www.j a va2s. c o m * * @param session {@link Session} the session * @param pathToItem String path to item * @return CmisObject cmis object */ public CmisObject getCmisObject(final Session session, String pathToItem) { try { if (!StringUtils.startsWith(pathToItem, "/")) { pathToItem = "/" + pathToItem; } if (StringUtils.endsWith(pathToItem, "/")) { pathToItem = StringUtils.removeEnd(pathToItem, "/"); } if (pathToItem.isEmpty()) { // set root folder pathToItem = "/"; } return session.getObjectByPath(pathToItem); } catch (CmisObjectNotFoundException nf) { throw new CmisRuntimeException("Path doesn't exist " + pathToItem); } }
From source file:org.alfresco.dataprep.CMISUtil.java
/** * Get cmis object by path// ww w. ja v a2s . c o m * * @param userName String user name * @param password String user password * @param pathToItem String path to item * @return CmisObject cmis object */ public CmisObject getCmisObject(final String userName, final String password, String pathToItem) { try { if (!StringUtils.startsWith(pathToItem, "/")) { pathToItem = "/" + pathToItem; } if (StringUtils.endsWith(pathToItem, "/")) { pathToItem = StringUtils.removeEnd(pathToItem, "/"); } Session session = getCMISSession(userName, password); return session.getObjectByPath(pathToItem); } catch (CmisObjectNotFoundException nf) { throw new CmisRuntimeException("Path doesn't exist " + pathToItem); } }
From source file:org.apache.atlas.web.rest.DiscoveryREST.java
private String escapeTypeName(String typeName) { String ret;/*w w w .j a v a2 s . co m*/ if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName, "`")) { ret = typeName; } else { ret = String.format("`%s`", typeName); } return ret; }
From source file:org.apache.fineract.infrastructure.dataexport.helper.DataExportUtils.java
/** * Searches for the CodeValueData object mapped to key similar to specified column value * //from w w w . j av a 2 s . c o m * @param codeValueMap * @param columnName * @param columnValue * @param mysqlDataType * @return AbstractMap.SimpleEntry object */ public static AbstractMap.SimpleEntry<String, MysqlDataType> replaceCodeValueIdWithValue( final HashMap<Long, CodeValueData> codeValueMap, final String columnName, String columnValue, MysqlDataType mysqlDataType) { if (columnName != null && StringUtils.isNotBlank(columnValue)) { if (StringUtils.endsWith(columnName, "_cv_id") || StringUtils.contains(columnName, "_cd_")) { Long codeValueId = null; try { codeValueId = Long.valueOf(columnValue); } catch (Exception e) { } CodeValueData codeValueData = codeValueMap.get(codeValueId); if (codeValueData != null) { columnValue = codeValueData.getName(); // change the data type from integer to string mysqlDataType = MysqlDataType.VARCHAR; } } else if (StringUtils.contains(columnName, "_cb_")) { final String[] csvToArray = StringUtils.split(columnValue, ","); if (csvToArray != null) { final String[] cleanCsvToArray = new String[csvToArray.length]; for (int i = 0; i < csvToArray.length; i++) { Long codeValueId = null; try { codeValueId = Long.valueOf(csvToArray[i]); } catch (Exception e) { } CodeValueData codeValueData = codeValueMap.get(codeValueId); cleanCsvToArray[i] = null; if (codeValueData != null) { cleanCsvToArray[i] = codeValueData.getName(); } } columnValue = StringUtils.join(cleanCsvToArray, ", "); } } } return new AbstractMap.SimpleEntry<String, MysqlDataType>(columnValue, mysqlDataType); }
From source file:org.apache.sling.nosql.generic.simple.provider.SimpleNoSqlAdapter.java
public boolean validPath(String path) { return !(StringUtils.contains(path, "/invalid/") || StringUtils.endsWith(path, "/invalid")); }
From source file:org.apache.struts2.osgi.FelixOsgiHost.java
protected List<String> getBundlesInDir(String dir) { List<String> bundleJars = new ArrayList<String>(); try {/*from w w w . ja v a 2 s .c o m*/ ResourceFinder finder = new ResourceFinder(); URL url = finder.find(dir); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); File[] bundles = bundlesDir.listFiles(new FilenameFilter() { public boolean accept(File file, String name) { return StringUtils.endsWith(name, ".jar"); } }); if (bundles != null && bundles.length > 0) { //add all the bundles to the list for (File bundle : bundles) { String externalForm = bundle.toURI().toURL().toExternalForm(); if (LOG.isDebugEnabled()) { LOG.debug("Adding bundle [#0]", externalForm); } bundleJars.add(externalForm); } } else if (LOG.isDebugEnabled()) { LOG.debug("No bundles found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) LOG.warn("Unable to read [#0] directory", dir); } else if (LOG.isWarnEnabled()) LOG.warn("The [#0] directory was not found", dir); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Unable load bundles from the [#0] directory", e, dir); } return bundleJars; }
From source file:org.asqatasun.crawler.CrawlerImpl.java
/** * Waiting for a better implementation, we parse here the html content * to detect the presence of the rel=canonical property. * @param content// w ww.j a v a2s . c o m * @return whether the current page defines a rel canonical Url and whether * this url is different from the current url. */ public final boolean isRelCanonicalPage(Content content) { // @TODO make this implementation cleaner if (!excludeRelCanonical) { return false; } if (!(content instanceof SSP)) { return false; } if (StringUtils.isBlank(((SSP) content).getSource())) { return false; } Elements relCanonical = Jsoup.parse(((SSP) content).getSource()).select(REL_CANONICAL_CSS_LIKE_QUERY); if (relCanonical.isEmpty() || relCanonical.size() > 1) { return false; } // At this step, we are sure that the rel canonical is defined and // is unique String href = relCanonical.first().attr("href"); if (href.equals(".")) { return false; } if (href.endsWith("/")) { href = href.substring(0, href.length() - 1); } if (href.startsWith("/")) { Elements base = Jsoup.parse(((SSP) content).getSource()).select(BASE_CSS_LIKE_QUERY); if (!base.isEmpty()) { if (StringUtils.endsWith(base.first().attr("href"), "/")) { href = StringUtils.join(base.first().attr("href"), href.substring(1)); } else { href = StringUtils.join(base.first().attr("href") + href); } LOGGER.debug("(BASE CASE) The concat href " + href); } else { URI contractUri; try { contractUri = new URI(content.getURI()); href = StringUtils.join(contractUri.getScheme(), "://", contractUri.getHost(), href); LOGGER.debug("(NORMAL CASE) The concat href " + href); } catch (URISyntaxException ex) { LOGGER.error("Error when creating uri object with url " + content.getURI()); } } } if (href.contains("//")) { href = href.substring(href.indexOf("//") + 2); } String currentUrl = content.getURI(); if (currentUrl.endsWith("/")) { currentUrl = currentUrl.substring(0, currentUrl.length() - 1); } if (currentUrl.contains("//")) { currentUrl = currentUrl.substring(currentUrl.indexOf("//") + 2); } if (currentUrl.equals(href)) { LOGGER.info("rel canonical present but points to itself " + content.getURI()); return false; } return true; }
From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java
/** * * @param elementHtml/*from ww w . j a v a 2 s .c o m*/ * @return */ private boolean isElementAutoClose(String elementHtml) { return StringUtils.endsWith(elementHtml, AUTO_CLOSE_TAG_OCCUR); }
From source file:org.bitbucket.mlopatkin.android.logviewer.TooltipGenerator.java
public String getTooltip() { StringBuilder result = new StringBuilder(text.length()); result.append("<html>"); String[] parts = splitWithHighlights(); boolean shouldHighlight = false; int pos = 0;//from w ww. j ava2s .c om for (String s : parts) { if (shouldHighlight) { result.append(SPAN_BEGIN); } String remain = s; while (pos + remain.length() > WIDTH) { int indexOfBr = WIDTH - pos; String onThisLine = remain.substring(0, indexOfBr); remain = remain.substring(indexOfBr); appendEnc(result, onThisLine); result.append(BR); pos = 0; } appendEnc(result, remain); pos += remain.length(); if (shouldHighlight) { result.append(SPAN_END); } shouldHighlight = !shouldHighlight; } if (StringUtils.endsWith(result, BR)) { result.setLength(result.length() - BR.length()); } if (StringUtils.endsWith(result, BR + SPAN_END)) { result.replace(result.length() - (BR + SPAN_END).length(), result.length(), SPAN_END); } result.append("</html>"); return result.toString(); }
From source file:org.blocks4j.reconf.client.constructors.MapConstructor.java
public Object construct(MethodData data) throws Throwable { Class<?> returnClass;/*w w w . j a v a2s .com*/ Type keyType = null; Type valueType = null; if (data.getReturnType() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) data.getReturnType(); returnClass = (Class<?>) parameterized.getRawType(); if (parameterized.getActualTypeArguments().length == 1) { Type first = parameterized.getActualTypeArguments()[0]; if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 2) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } if (parameterized.getActualTypeArguments()[0] instanceof TypeVariable) { keyType = first; valueType = parameterized.getActualTypeArguments()[1]; } else if (parameterized.getActualTypeArguments()[1] instanceof TypeVariable) { valueType = first; keyType = parameterized.getActualTypeArguments()[0]; } else { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } } } else { keyType = parameterized.getActualTypeArguments()[0]; valueType = parameterized.getActualTypeArguments()[1]; } } else if (data.getReturnType() instanceof Class) { returnClass = (Class<?>) data.getReturnType(); if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 2) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } keyType = parameterized.getActualTypeArguments()[0]; valueType = parameterized.getActualTypeArguments()[1]; } else { keyType = Object.class; valueType = Object.class; } } else { throw new IllegalArgumentException(msg.format("error.return", data.getMethod())); } if (returnClass.isInterface()) { returnClass = getDefaultImplementation(data, returnClass); } Constructor<?> constructor = returnClass.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); Map<Object, Object> mapInstance = (Map<Object, Object>) constructor .newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); if (null == data.getValue() || StringUtils.isEmpty(data.getValue())) { return mapInstance; } if ((!(keyType instanceof Class)) || (!StringUtils.startsWith(data.getValue(), "[") || !StringUtils.endsWith(data.getValue(), "]"))) { throw new IllegalArgumentException(msg.format("error.build", data.getValue(), data.getMethod())); } StringParser parser = new StringParser(data); for (Entry<String, String> each : parser.getTokensAsMap().entrySet()) { Object value = ObjectConstructorFactory.get(valueType) .construct(new MethodData(data.getMethod(), valueType, each.getValue())); mapInstance.put(ObjectConstructorFactory.get(keyType) .construct(new MethodData(data.getMethod(), keyType, each.getKey())), value); } return mapInstance; }