/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
while (hasChar()) { paramName = parseToken(new char[] {'=', separator}); paramValue = null; if (hasChar() && (chars[pos] == '=')) { paramValue = parseQuotedToken(new char[] {separator}); if (hasChar() && (chars[pos] == separator)) {
/** * Extracts a list of {@link NameValuePair}s from the given array of * characters. * * @param chars the array of characters that contains a sequence of * name/value pairs * * @return a list of {@link NameValuePair}s */ public List parse(final char[] chars, char separator) { if (chars == null) { return new ArrayList(); } return parse(chars, 0, chars.length, separator); }
public QueryParser() { this.parser = new ParameterParser(); }
/** * Extracts a list of {@link NameValuePair}s from the given string. * * @param str the string that contains a sequence of name/value pairs * @return a list of {@link NameValuePair}s * */ public List parse(final String str, char separator) { if (str == null) { return new ArrayList(); } return parse(str.toCharArray(), separator); }
/** Parse out a token until any of the given terminators * is encountered. Special characters in quoted tokens * are escaped. */ private String parseQuotedToken(final char[] terminators) { char ch; i1 = pos; i2 = pos; boolean quoted = false; boolean charEscaped = false; while (hasChar()) { ch = chars[pos]; if (!quoted && isOneOf(ch, terminators)) { break; } if (!charEscaped && ch == '"') { quoted = !quoted; } charEscaped = (!charEscaped && ch == '\\'); i2++; pos++; } return getToken(true); }
/** * Constructor with array of characters. * * @param chars the array of characters * @param offset - the initial offset. * @param length - the length. * * @since 3.0 */ public HeaderElement(char[] chars, int offset, int length) { this(); if (chars == null) { return; } ParameterParser parser = new ParameterParser(); List params = parser.parse(chars, offset, length, ';'); if (params.size() > 0) { NameValuePair element = (NameValuePair) params.remove(0); setName(element.getName()); setValue(element.getValue()); if (params.size() > 0) { this.parameters = (NameValuePair[]) params.toArray(new NameValuePair[params.size()]); } } }
while (hasChar()) { paramName = parseToken(new char[] {'=', separator}); paramValue = null; if (hasChar() && (chars[pos] == '=')) { paramValue = parseQuotedToken(new char[] {separator}); if (hasChar() && (chars[pos] == separator)) {
/** * Extracts a list of {@link NameValuePair}s from the given array of * characters. * * @param chars the array of characters that contains a sequence of * name/value pairs * * @return a list of {@link NameValuePair}s */ public List parse(final char[] chars, char separator) { if (chars == null) { return new ArrayList(); } return parse(chars, 0, chars.length, separator); }
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
while (hasChar()) { paramName = parseToken(new char[] {'=', separator}); paramValue = null; if (hasChar() && (chars[pos] == '=')) { paramValue = parseQuotedToken(new char[] {separator}); if (hasChar() && (chars[pos] == separator)) {
/** * Extracts a list of {@link NameValuePair}s from the given array of * characters. * * @param chars the array of characters that contains a sequence of * name/value pairs * * @return a list of {@link NameValuePair}s */ public List parse(final char[] chars, char separator) { if (chars == null) { return new ArrayList(); } return parse(chars, 0, chars.length, separator); }
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
while (hasChar()) { paramName = parseToken(new char[] {'=', separator}); paramValue = null; if (hasChar() && (chars[pos] == '=')) { paramValue = parseQuotedToken(new char[] {separator}); if (hasChar() && (chars[pos] == separator)) {
/** * Extracts a list of {@link NameValuePair}s from the given array of * characters. * * @param chars the array of characters that contains a sequence of * name/value pairs * * @return a list of {@link NameValuePair}s */ public List parse(final char[] chars, char separator) { if (chars == null) { return new ArrayList(); } return parse(chars, 0, chars.length, separator); }
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }