Package org.apache.mina.proxy.utils
Class StringUtilities
- java.lang.Object
-
- org.apache.mina.proxy.utils.StringUtilities
-
public class StringUtilities extends java.lang.ObjectStringUtilities.java - Various methods to handle strings.- Since:
- MINA 2.0.0-M3
- Author:
- Apache MINA Project
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddValueToHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String key, java.lang.String value, boolean singleValued)Adds an header to the provided map of headers.static voidcopyDirective(java.util.Map<java.lang.String,java.lang.String> directives, java.lang.StringBuilder sb, java.lang.String directive)Copy the directive to theStringBuilderif not null.static java.lang.StringcopyDirective(java.util.Map<java.lang.String,java.lang.String> src, java.util.Map<java.lang.String,java.lang.String> dst, java.lang.String directive)Copy the directive from the source map to the destination map, if it's value isn't null.static java.lang.StringgetDirectiveValue(java.util.Map<java.lang.String,java.lang.String> directivesMap, java.lang.String directive, boolean mandatory)A directive is a parameter of the digest authentication process.static java.lang.StringgetSingleValuedHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String key)Returns the value of the named header.static booleanisLws(byte b)Is character a linear white space ? LWS = [CRLF] 1*( SP | HT ) Note that we're checking individual bytes instead of CRLFstatic java.util.Map<java.lang.String,java.lang.String>parseDirectives(byte[] buf)Parses digest-challenge string, extracting each token and value(s).static java.lang.StringstringTo8859_1(java.lang.String str)Used to convert username-value, passwd or realm to 8859_1 encoding if all chars in string are within the 8859_1 (Latin 1) encoding range.
-
-
-
Method Detail
-
getDirectiveValue
public static java.lang.String getDirectiveValue(java.util.Map<java.lang.String,java.lang.String> directivesMap, java.lang.String directive, boolean mandatory) throws javax.security.sasl.AuthenticationExceptionA directive is a parameter of the digest authentication process. Returns the value of a directive from the map. If mandatory is true and the value is null, then it throws anAuthenticationException.- Parameters:
directivesMap- the directive's mapdirective- the name of the directive we want to retrievemandatory- is the directive mandatory- Returns:
- the mandatory value as a String
- Throws:
javax.security.sasl.AuthenticationException- if mandatory is true and if directivesMap.get(directive) == null
-
copyDirective
public static void copyDirective(java.util.Map<java.lang.String,java.lang.String> directives, java.lang.StringBuilder sb, java.lang.String directive)Copy the directive to theStringBuilderif not null. (A directive is a parameter of the digest authentication process.)- Parameters:
directives- the directives mapsb- the output bufferdirective- the directive name to look for
-
copyDirective
public static java.lang.String copyDirective(java.util.Map<java.lang.String,java.lang.String> src, java.util.Map<java.lang.String,java.lang.String> dst, java.lang.String directive)Copy the directive from the source map to the destination map, if it's value isn't null. (A directive is a parameter of the digest authentication process.)- Parameters:
src- the source mapdst- the destination mapdirective- the directive name- Returns:
- the value of the copied directive
-
parseDirectives
public static java.util.Map<java.lang.String,java.lang.String> parseDirectives(byte[] buf) throws javax.security.sasl.SaslExceptionParses digest-challenge string, extracting each token and value(s). Each token is a directive.- Parameters:
buf- A non-null digest-challenge string.- Returns:
- A Map containing the aprsed directives
- Throws:
javax.security.sasl.SaslException- if the String cannot be parsed according to RFC 2831
-
isLws
public static boolean isLws(byte b)
Is character a linear white space ? LWS = [CRLF] 1*( SP | HT ) Note that we're checking individual bytes instead of CRLF- Parameters:
b- the byte to check- Returns:
- true if it's a linear white space
-
stringTo8859_1
public static java.lang.String stringTo8859_1(java.lang.String str) throws java.io.UnsupportedEncodingExceptionUsed to convert username-value, passwd or realm to 8859_1 encoding if all chars in string are within the 8859_1 (Latin 1) encoding range.- Parameters:
str- a non-null String- Returns:
- a non-null String containing the 8859_1 encoded string
- Throws:
java.io.UnsupportedEncodingException- if we weren't able to decode using the ISO 8859_1 encoding
-
getSingleValuedHeader
public static java.lang.String getSingleValuedHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String key)Returns the value of the named header. If it has multiple values then anIllegalArgumentExceptionis thrown- Parameters:
headers- the http headers mapkey- the key of the header- Returns:
- the value of the http header
-
addValueToHeader
public static void addValueToHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String key, java.lang.String value, boolean singleValued)Adds an header to the provided map of headers.- Parameters:
headers- the http headers mapkey- the name of the new header to addvalue- the value of the added headersingleValued- if true and the map already contains one value then it is replaced by the new value. Otherwise it simply adds a new value to this multi-valued header.
-
-