本文整理汇总了Java中org.apache.shiro.util.StringUtils.clean方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.clean方法的具体用法?Java StringUtils.clean怎么用?Java StringUtils.clean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.clean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readValue
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
public String readValue(HttpServletRequest request, HttpServletResponse ignored) {
String name = getName();
String value = null;
javax.servlet.http.Cookie cookie = getCookie(request, name);
if (cookie != null) {
// Validate that the cookie is used at the correct place.
String path = StringUtils.clean(getPath());
if (path != null && !pathMatches(path, request.getRequestURI())) {
log.warn("Found '{}' cookie at path '{}', but should be only used for '{}'", new Object[] { name, request.getRequestURI(), path});
} else {
value = cookie.getValue();
log.debug("Found '{}' cookie value [{}]", name, value);
}
} else {
log.trace("No '{}' cookie value", name);
}
return value;
}
示例2: toMapProps
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
private static Map<String, String> toMapProps(String content) {
Map<String, String> props = new LinkedHashMap<String, String>();
String line;
StringBuilder lineBuffer = new StringBuilder();
Scanner scanner = new Scanner(content);
while (scanner.hasNextLine()) {
line = StringUtils.clean(scanner.nextLine());
if (isContinued(line)) {
//strip off the last continuation backslash:
line = line.substring(0, line.length() - 1);
lineBuffer.append(line);
continue;
} else {
lineBuffer.append(line);
}
line = lineBuffer.toString();
lineBuffer = new StringBuilder();
String[] kvPair = splitKeyValue(line);
props.put(kvPair[0], kvPair[1]);
}
return props;
}
示例3: calculatePath
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
* 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;
}
示例4: setParts
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected void setParts(String wildcardString, boolean caseSensitive) {
wildcardString = StringUtils.clean(wildcardString);
if (wildcardString == null || wildcardString.isEmpty()) {
throw new IllegalArgumentException("Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.");
}
if (!caseSensitive) {
wildcardString = wildcardString.toLowerCase();
}
List<String> parts = CollectionUtils.asList(wildcardString.split(PART_DIVIDER_TOKEN));
this.parts = new ArrayList<Set<String>>();
for (String part : parts) {
Set<String> subparts = CollectionUtils.asSet(part.split(SUBPART_DIVIDER_TOKEN));
if (subparts.isEmpty()) {
throw new IllegalArgumentException("Wildcard string cannot contain parts with only dividers. Make sure permission strings are properly formatted.");
}
this.parts.add(subparts);
}
if (this.parts.isEmpty()) {
throw new IllegalArgumentException("Wildcard string cannot contain only dividers. Make sure permission strings are properly formatted.");
}
}
示例5: setJndiNames
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
* 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));
}
示例6: cleanName
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
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;
}
示例7: addSection
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
private void addSection(String name, StringBuilder content) {
if (content.length() > 0) {
String contentString = content.toString();
String cleaned = StringUtils.clean(contentString);
if (cleaned != null) {
Section section = new Section(name, contentString);
if (!section.isEmpty()) {
sections.put(name, section);
}
}
}
}
示例8: load
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
* Loads the INI-formatted text backed by the given Scanner. This implementation will close the
* scanner after it has finished loading.
*
* @param scanner the {@code Scanner} from which to read the INI-formatted text
*/
public void load(Scanner scanner) {
String sectionName = DEFAULT_SECTION_NAME;
StringBuilder sectionContent = new StringBuilder();
while (scanner.hasNextLine()) {
String rawLine = scanner.nextLine();
String line = StringUtils.clean(rawLine);
if (line == null || line.startsWith(COMMENT_POUND) || line.startsWith(COMMENT_SEMICOLON)) {
//skip empty lines and comments:
continue;
}
String newSectionName = getSectionName(line);
if (newSectionName != null) {
//found a new section - convert the currently buffered one into a Section object
addSection(sectionName, sectionContent);
//reset the buffer for the new section:
sectionContent = new StringBuilder();
sectionName = newSectionName;
if (log.isDebugEnabled()) {
log.debug("Parsing " + SECTION_PREFIX + sectionName + SECTION_SUFFIX);
}
} else {
//normal line - add it to the existing content buffer:
sectionContent.append(rawLine).append("\n");
}
}
//finish any remaining buffered content:
addSection(sectionName, sectionContent);
}
示例9: getSectionName
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected static String getSectionName(String line) {
String s = StringUtils.clean(line);
if (isSectionHeader(s)) {
return cleanName(s.substring(1, s.length() - 1));
}
return null;
}
示例10: splitKeyValue
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected static String[] splitKeyValue(String keyValueLine) {
String line = StringUtils.clean(keyValueLine);
if (line == null) {
return null;
}
StringBuilder keyBuffer = new StringBuilder();
StringBuilder valueBuffer = new StringBuilder();
boolean buildingKey = true; //we'll build the value next:
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
if (buildingKey) {
if (isKeyValueSeparatorChar(c) && !isCharEscaped(line, i)) {
buildingKey = false;//now start building the value
} else {
keyBuffer.append(c);
}
} else {
if (valueBuffer.length() == 0 && isKeyValueSeparatorChar(c) && !isCharEscaped(line, i)) {
//swallow the separator chars before we start building the value
} else {
valueBuffer.append(c);
}
}
}
String key = StringUtils.clean(keyBuffer.toString());
String value = StringUtils.clean(valueBuffer.toString());
if (key == null || value == null) {
String msg = "Line argument must contain a key and a value. Only one string token was found.";
throw new IllegalArgumentException(msg);
}
log.trace("Discovered key/value pair: {} = {}", key, value);
return new String[]{key, value};
}
示例11: toNameConfigPair
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
* Based on the given filter chain definition token (e.g. 'foo' or 'foo[bar, baz]'), this will return the token
* as a name/value pair, removing any brackets as necessary. Examples:
* <table>
* <tr>
* <th>Input</th>
* <th>Result</th>
* </tr>
* <tr>
* <td>{@code foo}</td>
* <td>returned[0] == {@code foo}<br/>returned[1] == {@code null}</td>
* </tr>
* <tr>
* <td>{@code foo[bar, baz]}</td>
* <td>returned[0] == {@code foo}<br/>returned[1] == {@code bar, baz}</td>
* </tr>
* </table>
* @param token the filter chain definition token
* @return A name/value pair representing the filter name and a (possibly null) config value.
* @throws ConfigurationException if the token cannot be parsed
* @since 1.2
* @see <a href="https://issues.apache.org/jira/browse/SHIRO-205">SHIRO-205</a>
*/
protected String[] toNameConfigPair(String token) throws ConfigurationException {
try {
String[] pair = token.split("\\[", 2);
String name = StringUtils.clean(pair[0]);
if (name == null) {
throw new IllegalArgumentException("Filter name not found for filter chain definition token: " + token);
}
String config = null;
if (pair.length == 2) {
config = StringUtils.clean(pair[1]);
//if there was an open bracket, it assumed there is a closing bracket, so strip it too:
config = config.substring(0, config.length() - 1);
config = StringUtils.clean(config);
//backwards compatibility prior to implementing SHIRO-205:
//prior to SHIRO-205 being implemented, it was common for end-users to quote the config inside brackets
//if that config required commas. We need to strip those quotes to get to the interior quoted definition
//to ensure any existing quoted definitions still function for end users:
if (config != null && config.startsWith("\"") && config.endsWith("\"")) {
String stripped = config.substring(1, config.length() - 1);
stripped = StringUtils.clean(stripped);
//if the stripped value does not have any internal quotes, we can assume that the entire config was
//quoted and we can use the stripped value.
if (stripped != null && stripped.indexOf('"') == -1) {
config = stripped;
}
//else:
//the remaining config does have internal quotes, so we need to assume that each comma delimited
//pair might be quoted, in which case we need the leading and trailing quotes that we stripped
//So we ignore the stripped value.
}
}
return new String[]{name, config};
} catch (Exception e) {
String msg = "Unable to parse filter chain definition token: " + token;
throw new ConfigurationException(msg, e);
}
}
示例12: isSectionHeader
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected static boolean isSectionHeader(String line) {
String s = StringUtils.clean(line);
return s != null && s.startsWith(SECTION_PREFIX) && s.endsWith(SECTION_SUFFIX);
}
示例13: toNameConfigPair
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
private String[] toNameConfigPair(String token) throws ConfigurationException {
try {
String[] pair = token.split("\\[", 2);
String name = StringUtils.clean(pair[0]);
if (name == null) {
throw new IllegalArgumentException("Filter name not found for doFilter chain definition token: " + token);
}
String config = null;
if (pair.length == 2) {
config = StringUtils.clean(pair[1]);
//if there was an open bracket, it assumed there is a closing bracket, so strip it too:
config = config.substring(0, config.length() - 1);
config = StringUtils.clean(config);
//backwards compatibility prior to implementing SHIRO-205:
//prior to SHIRO-205 being implemented, it was common for end-users to quote the config inside brackets
//if that config required commas. We need to strip those quotes to get to the interior quoted definition
//to ensure any existing quoted definitions still function for end users:
if (config != null && config.startsWith("\"") && config.endsWith("\"")) {
String stripped = config.substring(1, config.length() - 1);
stripped = StringUtils.clean(stripped);
//if the stripped value does not have any internal quotes, we can assume that the entire config was
//quoted and we can use the stripped value.
if (stripped != null && stripped.indexOf('"') == -1) {
config = stripped;
}
//else:
//the remaining config does have internal quotes, so we need to assume that each comma delimited
//pair might be quoted, in which case we need the leading and trailing quotes that we stripped
//So we ignore the stripped value.
}
}
return new String[]{name, config};
} catch (Exception e) {
String msg = "Unable to parse doFilter chain definition token: " + token;
throw new ConfigurationException(msg, e);
}
}
示例14: getInitParam
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
* Returns the value for the named {@code init-param}, or {@code null} if there was no {@code init-param}
* specified by that name.
*
* @param paramName the name of the {@code init-param}
* @return the value for the named {@code init-param}, or {@code null} if there was no {@code init-param}
* specified by that name.
*/
protected String getInitParam(String paramName) {
FilterConfig config = getFilterConfig();
if (config != null) {
return StringUtils.clean(config.getInitParameter(paramName));
}
return null;
}
示例15: setConfigPath
import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
* 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);
}