/** * Convenience method to return a Collection as a delimited (e.g. CSV) String. * E.g. useful for <code>toString()</code> implementations. * * @param coll * the Collection to display * @param delim * the delimiter to use (probably a ",") * @return the delimited String */ private static String collectionToDelimitedString(final Collection<String> coll, final String delim) { return collectionToDelimitedString(coll, delim, "", ""); }
/** * Take a String which is a delimited list and convert it to a String array. * <p> * A single delimiter can consists of more than one character: It will still * be considered as single delimiter string, rather than as bunch of potential * delimiter characters - in contrast to <code>tokenizeToStringArray</code>. * * @param str * the input String * @param delimiter * the delimiter between elements (this is a single delimiter, rather * than a bunch individual delimiter characters) * @return an array of the tokens in the list * @see #tokenizeToStringArray */ private static String[] delimitedListToStringArray(final String str, final String delimiter) { return delimitedListToStringArray(str, delimiter, null); }
/** * Check that the given String is neither <code>null</code> nor of length 0. * Note: Will return <code>true</code> for a String that purely consists of * whitespace. * * @param str * the String to check (may be <code>null</code>) * @return <code>true</code> if the String is not null and has length * @see #hasLength(CharSequence) */ private static boolean hasLength(final String str) { return hasLength((CharSequence) str); } }
return null; String pathToUse = replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR); final String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR); final List<String> pathElements = new LinkedList<String>(); return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
if ("".equals(delimiter)) { for (int i = 0; i < str.length(); i++) { result.add(deleteAny(str.substring(i, i + 1), charsToDelete)); int delPos = 0; while ((delPos = str.indexOf(delimiter, pos)) != -1) { result.add(deleteAny(str.substring(pos, delPos), charsToDelete)); pos = delPos + delimiter.length(); result.add(deleteAny(str.substring(pos), charsToDelete)); return toStringArray(result);
/** * Computes absolute url of the imported resource. * * @param relativeResourceUri uri of the resource containing the import statement. * @param importUrl found import url. * @return absolute url of the resource to import. */ private String computeAbsoluteUrl(final String relativeResourceUri, final String importUrl) { final String folder = WroUtil.getFullPath(relativeResourceUri); // remove '../' & normalize the path. final String absoluteImportUrl = StringUtils.cleanPath(folder + importUrl); return absoluteImportUrl; }
return null; String pathToUse = replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR); final String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR); final List<String> pathElements = new LinkedList<String>(); return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
if ("".equals(delimiter)) { for (int i = 0; i < str.length(); i++) { result.add(deleteAny(str.substring(i, i + 1), charsToDelete)); int delPos = 0; while ((delPos = str.indexOf(delimiter, pos)) != -1) { result.add(deleteAny(str.substring(pos, delPos), charsToDelete)); pos = delPos + delimiter.length(); result.add(deleteAny(str.substring(pos), charsToDelete)); return toStringArray(result);
/** * Computes absolute url of the imported resource. * * @param relativeResourceUri uri of the resource containing the import statement. * @param importUrl found import url. * @return absolute url of the resource to import. */ private String computeAbsoluteUrl(final String relativeResourceUri, final String importUrl) { final String folder = WroUtil.getFullPath(relativeResourceUri); // remove '../' & normalize the path. return StringUtils.cleanPath(folder + importUrl); }
final String computedImageLocation = cleanPath(cssUriFolder + processedImageUrl); LOG.debug("computedImageLocation: {}", computedImageLocation); return computedImageLocation;
/** * Check that the given String is neither <code>null</code> nor of length 0. * Note: Will return <code>true</code> for a String that purely consists of * whitespace. * * @param str * the String to check (may be <code>null</code>) * @return <code>true</code> if the String is not null and has length * @see #hasLength(CharSequence) */ private static boolean hasLength(final String str) { return hasLength((CharSequence) str); } }
/** * Convenience method to return a Collection as a delimited (e.g. CSV) String. * E.g. useful for <code>toString()</code> implementations. * * @param coll * the Collection to display * @param delim * the delimiter to use (probably a ",") * @return the delimited String */ private static String collectionToDelimitedString(final Collection<String> coll, final String delim) { return collectionToDelimitedString(coll, delim, EMPTY, EMPTY); }
/** * Take a String which is a delimited list and convert it to a String array. * <p> * A single delimiter can consists of more than one character: It will still * be considered as single delimiter string, rather than as bunch of potential * delimiter characters - in contrast to <code>tokenizeToStringArray</code>. * * @param str * the input String * @param delimiter * the delimiter between elements (this is a single delimiter, rather * than a bunch individual delimiter characters) * @return an array of the tokens in the list * @see #tokenizeToStringArray */ private static String[] delimitedListToStringArray(final String str, final String delimiter) { return delimitedListToStringArray(str, delimiter, null); }
/** * {@inheritDoc} */ public InputStream locate(final String uri) throws IOException { Validate.notNull(uri, "URI cannot be NULL!"); // replace prefix & clean path by removing '..' characters if exists and // normalizing the location to use. String location = StringUtils.cleanPath(uri.replaceFirst(PREFIX, "")).trim(); if (getWildcardStreamLocator().hasWildcard(location)) { try { return locateWildcardStream(uri, location); } catch (final IOException e) { if (location.contains("?")) { location = DefaultWildcardStreamLocator.stripQueryPath(location); LOG.debug("Trying fallback location: {}", location); } } } final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(location); if (is == null) { throw new IOException("Couldn't get InputStream from this resource: " + uri); } return is; }
/** * Delete any character in a given String. * * @param inString * the original String * @param charsToDelete * a set of characters to delete. E.g. "az\n" will delete 'a's, 'z's * and new lines. * @return the resulting String */ private static String deleteAny(final String inString, final String charsToDelete) { if (!hasLength(inString) || !hasLength(charsToDelete)) { return inString; } final StringBuffer out = new StringBuffer(); for (int i = 0; i < inString.length(); i++) { final char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { out.append(c); } } return out.toString(); }
final String computedImageLocation = cleanPath(cssUriFolder + processedImageUrl); LOG.debug("computedImageLocation: {}", computedImageLocation); return computedImageLocation;
/** * Delete any character in a given String. * * @param inString * the original String * @param charsToDelete * a set of characters to delete. E.g. "az\n" will delete 'a's, 'z's * and new lines. * @return the resulting String */ private static String deleteAny(final String inString, final String charsToDelete) { if (!hasLength(inString) || !hasLength(charsToDelete)) { return inString; } final StringBuffer out = new StringBuffer(); for (int i = 0; i < inString.length(); i++) { final char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { out.append(c); } } return out.toString(); }
/** * {@inheritDoc} */ public InputStream locate(final String uri) throws IOException { Validate.notNull(uri, "URI cannot be NULL!"); // replace prefix & clean path by removing '..' characters if exists and // normalizing the location to use. String location = StringUtils.cleanPath(uri.replaceFirst(PREFIX, "")).trim(); if (getWildcardStreamLocator().hasWildcard(location)) { try { return locateWildcardStream(uri, location); } catch (final IOException e) { if (location.contains("?")) { location = DefaultWildcardStreamLocator.stripQueryPath(location); LOG.debug("Trying fallback location: {}", location); } } } final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(location); if (is == null) { throw new IOException("Couldn't get InputStream from this resource: " + uri); } return is; }