public static Iterator<RequestParameter> queryParser(final CharSequence s) { return queryParser(s, 0, s.length()); }
/** * Parse a dot separated name. * * @param s the sequence * @param from the from index * @param end the end index * @return the parsed identifiers * @throws IllegalArgumentException */ public static String[] parseName(CharSequence s, int from, int end) throws IllegalArgumentException { if (from < 0) { throw new IllegalArgumentException("From bound " + from + " cannot be negative"); } if (from > end) { throw new IllegalArgumentException("From bound " + from + " cannot be greater than the end bound " + end); } if (from == end) { return Name.EMPTY_STRING_ARRAY; } else { return parseName(0, s, from, end); } }
/** * Path parsing method and returns an array. The last two values of the array are the * * @param mode {@link #PARSE_CANONICAL} : rejects any '.' or '..' / {@link #PARSE_ANY} : accepts '.' or '..' * @param base the base path * @param padding the first index that will be written * @param path the path to parse * @param off the first char to parse * @return the parsed path as a String[] * @throws IllegalArgumentException if the path is not valid */ public static String[] parsePath(int mode, String[] base, int padding, String path, int off) throws IllegalArgumentException { return parsePath(mode, base, padding, path, off, 0); }
public static Map<String, RequestParameter> parseQuery(String s) { return parseQuery(s, 0, s.length()); }
public static Map<String, RequestParameter> parseQuery(String s) { return parseQuery(s, 0, s.length()); }
public static Iterator<RequestParameter> queryParser(final CharSequence s) { return queryParser(s, 0, s.length()); }
/** * Path parsing method and returns an array. The last two values of the array are the * * @param mode {@link #PARSE_CANONICAL} : rejects any '.' or '..' / {@link #PARSE_ANY} : accepts '.' or '..' * @param base the base path * @param padding the first index that will be written * @param path the path to parse * @param off the first char to parse * @return the parsed path as a String[] * @throws IllegalArgumentException if the path is not valid */ public static String[] parsePath(int mode, String[] base, int padding, String path, int off) throws IllegalArgumentException { return parsePath(mode, base, padding, path, off, 0); }
/** * Parse a dot separated name. * * @param s the sequence * @param from the from index * @param end the end index * @return the parsed identifiers * @throws IllegalArgumentException */ public static String[] parseName(CharSequence s, int from, int end) throws IllegalArgumentException { if (from < 0) { throw new IllegalArgumentException("From bound " + from + " cannot be negative"); } if (from > end) { throw new IllegalArgumentException("From bound " + from + " cannot be greater than the end bound " + end); } if (from == end) { return Name.EMPTY_STRING_ARRAY; } else { return parseName(0, s, from, end); } }
public static Map<String, RequestParameter> parseQuery(CharSequence s, int from, int to) { Map<String, RequestParameter> parameters = Collections.emptyMap(); Iterator<RequestParameter> parser = queryParser(s, from, to); while (parser.hasNext()) { RequestParameter current = parser.next(); if (parameters.isEmpty()) { parameters = new HashMap<String, RequestParameter>(); } RequestParameter parameter = parameters.get(current.getName()); if (parameter != null) { current = parameter.append(current); } parameters.put(current.getName(), current); } return parameters; }
public Path append(String path) throws NullPointerException, IllegalArgumentException { if (path == null) { throw new NullPointerException("No null path accepted"); } if (path.length() > 0 && path.charAt(0) == '/') { throw new IllegalArgumentException("Cannot append absolute path " + path); } String[] atoms = Lexers.parsePath(Lexers.PARSE_ANY, name.identifiers, name.size - 1, path, 0); return create(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); }
private static String[] parseName(int size, CharSequence s, int from, int end) { int next = Tools.indexOf(s, '.', from, end); String[] identifiers; if (next < 0) { if (from == end) { throw new IllegalArgumentException("Empty segment"); } identifiers = new String[size + 1]; identifiers[size] = s.subSequence(from, end).toString(); } else { if (next == from) { throw new IllegalArgumentException("Empty segment"); } identifiers = parseName(size + 1, s, next + 1, end); identifiers[size] = s.subSequence(from, next).toString(); } return identifiers; }
public static Map<String, RequestParameter> parseQuery(CharSequence s, int from, int to) { Map<String, RequestParameter> parameters = Collections.emptyMap(); Iterator<RequestParameter> parser = queryParser(s, from, to); while (parser.hasNext()) { RequestParameter current = parser.next(); if (parameters.isEmpty()) { parameters = new HashMap<String, RequestParameter>(); } RequestParameter parameter = parameters.get(current.getName()); if (parameter != null) { current = parameter.append(current); } parameters.put(current.getName(), current); } return parameters; }
public Path append(String path) throws NullPointerException, IllegalArgumentException { if (path == null) { throw new NullPointerException("No null path accepted"); } if (path.length() > 0 && path.charAt(0) == '/') { throw new IllegalArgumentException("Cannot append absolute path " + path); } String[] atoms = Lexers.parsePath(Lexers.PARSE_ANY, name.identifiers, name.size - 1, path, 0); return create(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); }
/** * Parse the name. * * @param s the char sequence to parse * @param from the index of the first char of the name * @param end the index of the char after the last char of the name * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s, int from, int end) throws IllegalArgumentException { if (end > s.length()) { throw new IllegalArgumentException("End bound " + end + " cannot be greater than the sequence length " + s.length()); } String[] segments = Lexers.parseName(s, from, end); if (segments.length == 0) { return EMPTY; } else { return new Name(s.subSequence(from, end).toString(), segments); } }
String query = req.getQueryString(); if (query != null) { for (Iterator<RequestParameter> i = Lexers.queryParser(query);i.hasNext();) { if (requestParameters.isEmpty()) { requestParameters = new HashMap<String, RequestParameter>();
int diff = pos - off; if (diff == 0) { return parsePath(mode, base, padding, path, off + 1, size); } else { if (diff == 1 && path.charAt(off) == '.') { case PARSE_ANY: return parsePath(mode, base, padding, path, off + 2, size); default: throw new AssertionError("Should not be here"); return parsePath(mode, base, padding, path, off + 3, size - 1); } else if (padding > 0) { return parsePath(mode, base, padding - 1, path, off + 3, size); } else { throw new IllegalArgumentException("Invalid path"); String[] ret = parsePath(mode, base, padding, path, pos + 1, size + 1); if (ret[at] == null) { ret[at] = path.substring(off, pos);
private static String[] parseName(int size, CharSequence s, int from, int end) { int next = Tools.indexOf(s, '.', from, end); String[] identifiers; if (next < 0) { if (from == end) { throw new IllegalArgumentException("Empty segment"); } identifiers = new String[size + 1]; identifiers[size] = s.subSequence(from, end).toString(); } else { if (next == from) { throw new IllegalArgumentException("Empty segment"); } identifiers = parseName(size + 1, s, next + 1, end); identifiers[size] = s.subSequence(from, next).toString(); } return identifiers; }
String query = req.getQueryString(); if (query != null) { for (Iterator<RequestParameter> i = Lexers.queryParser(query);i.hasNext();) { if (requestParameters.isEmpty()) { requestParameters = new HashMap<String, RequestParameter>();
int diff = pos - off; if (diff == 0) { return parsePath(mode, base, padding, path, off + 1, size); } else { if (diff == 1 && path.charAt(off) == '.') { case PARSE_ANY: return parsePath(mode, base, padding, path, off + 2, size); default: throw new AssertionError("Should not be here"); return parsePath(mode, base, padding, path, off + 3, size - 1); } else if (padding > 0) { return parsePath(mode, base, padding - 1, path, off + 3, size); } else { throw new IllegalArgumentException("Invalid path"); String[] ret = parsePath(mode, base, padding, path, pos + 1, size + 1); if (ret[at] == null) { ret[at] = path.substring(off, pos);
/** * Parse the name. * * @param s the char sequence to parse * @param from the index of the first char of the name * @param end the index of the char after the last char of the name * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s, int from, int end) throws IllegalArgumentException { if (end > s.length()) { throw new IllegalArgumentException("End bound " + end + " cannot be greater than the sequence length " + s.length()); } String[] segments = Lexers.parseName(s, from, end); if (segments.length == 0) { return EMPTY; } else { return new Name(s.subSequence(from, end).toString(), segments); } }