@Test public void parsePathWithAttribute() { String header = "/bar/foo;version=1.0.0"; List<PathElement> list = HeaderParser.parseHeader(header); assertThat(list.size(), is(1)); PathElement element = list.get(0); assertThat(element.getName(), is("/bar/foo")); assertThat(element.getAttribute("version"), is("1.0.0")); }
public static List<PathElement> parseHeader(String header) { List<PathElement> elements = new ArrayList<PathElement>(); if (header == null || header.trim().length() == 0) { return elements; } String[] clauses = header.split(","); for (String clause : clauses) { String[] tokens = clause.split(";"); if (tokens.length < 1) { throw new IllegalArgumentException("Invalid header clause: " + clause); } PathElement elem = new PathElement(tokens[0].trim()); elements.add(elem); for (int i = 1; i < tokens.length; i++) { int pos = tokens[i].indexOf('='); if (pos != -1) { if (pos > 0 && tokens[i].charAt(pos - 1) == ':') { String name = tokens[i].substring(0, pos - 1).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addDirective(name, value); } else { String name = tokens[i].substring(0, pos).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addAttribute(name, value); } } else { elem = new PathElement(tokens[i].trim()); elements.add(elem); } } } return elements; }
HeaderParser { public static List<PathElement> parseHeader(String header) { List<PathElement> elements = new ArrayList<PathElement>(); if (header == null || header.trim().length() == 0) { return elements; } String[] clauses = header.split(","); for (String clause : clauses) { String[] tokens = clause.split(";"); if (tokens.length < 1) { throw new IllegalArgumentException("Invalid header clause: " + clause); } PathElement elem = new PathElement(tokens[0].trim()); elements.add(elem); for (int i = 1; i < tokens.length; i++) { int pos = tokens[i].indexOf('='); if (pos != -1) { if (pos > 0 && tokens[i].charAt(pos - 1) == ':') { String name = tokens[i].substring(0, pos - 1).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addDirective(name, value); } else { String name = tokens[i].substring(0, pos).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addAttribute(name, value); } } else { elem = new PathElement(tokens[i].trim()); elements.add(elem); } } } return elements; } }
HeaderParser { public static List<PathElement> parseHeader(String header) { List<PathElement> elements = new ArrayList<PathElement>(); if (header == null || header.trim().length() == 0) { return elements; } String[] clauses = header.split(","); for (String clause : clauses) { String[] tokens = clause.split(";"); if (tokens.length < 1) { throw new IllegalArgumentException("Invalid header clause: " + clause); } PathElement elem = new PathElement(tokens[0].trim()); elements.add(elem); for (int i = 1; i < tokens.length; i++) { int pos = tokens[i].indexOf('='); if (pos != -1) { if (pos > 0 && tokens[i].charAt(pos - 1) == ':') { String name = tokens[i].substring(0, pos - 1).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addDirective(name, value); } else { String name = tokens[i].substring(0, pos).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addAttribute(name, value); } } else { elem = new PathElement(tokens[i].trim()); elements.add(elem); } } } return elements; }  }
HeaderParser { public static List<PathElement> parseHeader(String header) { List<PathElement> elements = new ArrayList<PathElement>(); if (header == null || header.trim().length() == 0) { return elements; } String[] clauses = header.split(","); for (String clause : clauses) { String[] tokens = clause.split(";"); if (tokens.length < 1) { throw new IllegalArgumentException("Invalid header clause: " + clause); } PathElement elem = new PathElement(tokens[0].trim()); elements.add(elem); for (int i = 1; i < tokens.length; i++) { int pos = tokens[i].indexOf('='); if (pos != -1) { if (pos > 0 && tokens[i].charAt(pos - 1) == ':') { String name = tokens[i].substring(0, pos - 1).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addDirective(name, value); } else { String name = tokens[i].substring(0, pos).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addAttribute(name, value); } } else { elem = new PathElement(tokens[i].trim()); elements.add(elem); } } } return elements; }  static List<PathElement> parseHeader(String header); }
HeaderParser { public static List<PathElement> parseHeader(String header) { List<PathElement> elements = new ArrayList<PathElement>(); if (header == null || header.trim().length() == 0) { return elements; } String[] clauses = header.split(","); for (String clause : clauses) { String[] tokens = clause.split(";"); if (tokens.length < 1) { throw new IllegalArgumentException("Invalid header clause: " + clause); } PathElement elem = new PathElement(tokens[0].trim()); elements.add(elem); for (int i = 1; i < tokens.length; i++) { int pos = tokens[i].indexOf('='); if (pos != -1) { if (pos > 0 && tokens[i].charAt(pos - 1) == ':') { String name = tokens[i].substring(0, pos - 1).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addDirective(name, value); } else { String name = tokens[i].substring(0, pos).trim(); String value = tokens[i].substring(pos + 1).trim(); elem.addAttribute(name, value); } } else { elem = new PathElement(tokens[i].trim()); elements.add(elem); } } } return elements; }  static List<PathElement> parseHeader(String header);  }