protected void setName(String name) { if (!StringUtils.hasText(name)) { throw new IllegalArgumentException("Cannot specify a null or empty name."); } this.name = name; }
/** * Returns the Cookie's calculated path setting. If the {@link javax.servlet.http.Cookie#getPath() path} is {@code null}, then the * {@code request}'s {@link javax.servlet.http.HttpServletRequest#getContextPath() context path} * will be returned. If getContextPath() is the empty string or null then the ROOT_PATH constant is returned. * * @param request the incoming HttpServletRequest * @return the path to be used as the path when the cookie is created or removed */ private String calculatePath(HttpServletRequest request) { String path = StringUtils.clean(getPath()); if (!StringUtils.hasText(path)) { path = StringUtils.clean(request.getContextPath()); } //fix for http://issues.apache.org/jira/browse/SHIRO-9: if (path == null) { path = ROOT_PATH; } log.trace("calculated path: {}", path); return path; }
/** * Splits the {@code delimited} string (delimited by the specified {@code separator} character) and returns the * delimited values as a {@code Set}. * <p/> * If either argument is {@code null}, this method returns {@code null}. * * @param delimited the string to split * @param separator the character that delineates individual tokens to split * @return the delimited values as a {@code Set}. * @since 1.2 */ public static Set<String> splitToSet(String delimited, String separator) { if (delimited == null || separator == null) { return null; } String[] split = split(delimited, separator.charAt(0)); return asSet(split); }
public void setAuthorizedHosts(String authorizedHosts) { if (!StringUtils.hasText(authorizedHosts)) { throw new IllegalArgumentException("authorizedHosts argument cannot be null or empty."); } String[] hosts = StringUtils.tokenizeToStringArray(authorizedHosts, ", \t"); for (String host : hosts) { //replace any periods with \\. to ensure the regex works: String periodsReplaced = host.replace(".", "\\."); //check for IPv4: String wildcardsReplaced = periodsReplaced.replace("*", IPV4_QUAD_REGEX); if (IPV4_PATTERN.matcher(wildcardsReplaced).matches()) { authorizedIps.put(host, wildcardsReplaced); } else { } } }
public static String[] split(String line, char delimiter, char beginQuoteChar, char endQuoteChar) { return split(line, delimiter, beginQuoteChar, endQuoteChar, false, true); }
/** * Sets the config path to be used to load a .ini file for configuration if a configuration is * not specified via the {@link #getConfig() config} attribute. * <p/> * This value is {@code null} by default, but it will be automatically set to the value of the * '{@code configPath}' {@code init-param} if it exists in the {@code FilterConfig} provided by the servlet * container at startup. * * @param configPath the config path to be used to load a .ini file for configuration if a configuration is * not specified via the {@link #getConfig() config} attribute. */ public void setConfigPath(String configPath) { this.configPath = StringUtils.clean(configPath); }
/** * Specifies a comma-delimited list of JNDI names to lookup, each one corresponding to a jndi-bound * {@link Realm Realm}. The Realms will be made available to the SecurityManager in the order * they are defined. * * @param commaDelimited a comma-delimited list of JNDI names, each representing the JNDI name used to * look up a corresponding jndi-bound Realm. * @throws IllegalStateException if the specified argument is null or the empty string. */ public void setJndiNames(String commaDelimited) throws IllegalStateException { String arg = StringUtils.clean(commaDelimited); if (arg == null) { String msg = "One or more comma-delimited jndi names must be specified for the " + getClass().getName() + " to locate Realms."; throw new IllegalStateException(msg); } String[] names = StringUtils.tokenizeToStringArray(arg, ","); setJndiNames(Arrays.asList(names)); }
/** * Assert that the given String is not empty; that is, * it must not be <code>null</code> and not the empty String. * <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre> * @param text the String to check * @param message the exception message to use if the assertion fails * @see StringUtils#hasLength */ public static void hasLength(String text, String message) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(message); } }
/** * Returns the specified array as a comma-delimited (',') string. * * @param array the array whose contents will be converted to a string. * @return the array's contents as a comma-delimited (',') string. * @since 1.0 */ public static String toString(Object[] array) { return toDelimitedString(array, ","); }
public static String[] split(String line, char delimiter) { return split(line, delimiter, DEFAULT_QUOTE_CHAR); }
/** * Convenience method that returns a request parameter value, first running it through * {@link StringUtils#clean(String)}. * * @param request the servlet request. * @param paramName the parameter name. * @return the clean param value, or null if the param does not exist or is empty. */ public static String getCleanParam(ServletRequest request, String paramName) { return StringUtils.clean(request.getParameter(paramName)); }
/** * Specifies a comma-delimited list of JNDI names to lookup, each one corresponding to a jndi-bound * {@link Realm Realm}. The Realms will be made available to the SecurityManager in the order * they are defined. * * @param commaDelimited a comma-delimited list of JNDI names, each representing the JNDI name used to * look up a corresponding jndi-bound Realm. * @throws IllegalStateException if the specified argument is null or the empty string. */ public void setJndiNames(String commaDelimited) throws IllegalStateException { String arg = StringUtils.clean(commaDelimited); if (arg == null) { String msg = "One or more comma-delimited jndi names must be specified for the " + getClass().getName() + " to locate Realms."; throw new IllegalStateException(msg); } String[] names = StringUtils.tokenizeToStringArray(arg, ","); setJndiNames(Arrays.asList(names)); }
/** * Assert that the given text does not contain the given substring. * <pre class="code">Assert.doesNotContain(name, "rod", "Name must not contain 'rod'");</pre> * @param textToSearch the text to search * @param substring the substring to find within the text * @param message the exception message to use if the assertion fails */ public static void doesNotContain(String textToSearch, String substring, String message) { if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.indexOf(substring) != -1) { throw new IllegalArgumentException(message); } }
private static String toString(String[] strings) { int len = strings != null ? strings.length : 0; if (len == 0) { return null; } return StringUtils.toDelimitedString(strings, " "); } }
public void setName(String name) { if (!StringUtils.hasText(name)) { throw new IllegalArgumentException("Name cannot be null/empty."); } this.name = name; }
/** * Split a string into a list of not empty and trimmed strings, delimiter is a comma. * * @param s the input string * @return the list of not empty and trimmed strings */ private List<String> split(String s) { List<String> list = new ArrayList<String>(); String[] elements = StringUtils.split(s, ','); if (elements != null && elements.length > 0) { for (String element : elements) { if (StringUtils.hasText(element)) { list.add(element.trim()); } } } return list; }
/** * Returns the Cookie's calculated path setting. If the * {@link javax.servlet.http.Cookie#getPath() path} is {@code null}, then * the {@code request}'s * {@link javax.servlet.http.HttpServletRequest#getContextPath() context * path} will be returned. If getContextPath() is the empty string or null * then the ROOT_PATH constant is returned. * * @param request * the incoming HttpServletRequest * @return the path to be used as the path when the cookie is created or * removed */ private String calculatePath(HttpServletRequest request) { String path = StringUtils.clean(getPath()); if (!StringUtils.hasText(path)) { if (Lang.isEmpty(request)) { return ROOT_PATH; } path = StringUtils.clean(request.getContextPath()); } // fix for http://issues.apache.org/jira/browse/SHIRO-9: if (path == null) { path = ROOT_PATH; } log.trace("calculated path: {}", path); return path; }
public static String[] split(String line) { return split(line, DEFAULT_DELIMITER_CHAR); }
private static String cleanName(String sectionName) { String name = StringUtils.clean(sectionName); if (name == null) { log.trace("Specified name was null or empty. Defaulting to the default section (name = \"\")"); name = DEFAULT_SECTION_NAME; } return name; }