@Test public void testParseEtag() { RuntimeDelegate rd = RuntimeDelegate.getInstance(); HeaderDelegate<EntityTag> entityTagHeaderDelegate = rd.createHeaderDelegate(EntityTag.class); if (entityTagHeaderDelegate == null) { fail("EntityTag header delegate is not regestered in RuntimeDelegateImpl"); } String expectedEntityTagString = "12321-\"12321-\t123123"; EntityTag expectedWeekEntityTag = new EntityTag(expectedEntityTagString, true); EntityTag expectedStrongEntityTag = new EntityTag(expectedEntityTagString, false); String inputEntityTagString = "\"" + "12321-\\\"12321-\t123123" + "\""; EntityTag parsedWeakEntityTag = entityTagHeaderDelegate.fromString("W/" + inputEntityTagString); assertEquals(expectedWeekEntityTag, parsedWeakEntityTag); EntityTag parsedStrongEntityTag = entityTagHeaderDelegate.fromString(inputEntityTagString); assertEquals(expectedStrongEntityTag, parsedStrongEntityTag); try { entityTagHeaderDelegate.fromString(null); fail("EntityTag is null - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } try { entityTagHeaderDelegate.fromString("Not quoted Entity Tag"); fail("Invalid EntityTag - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } }
public EntityTag fromString(String eTag) throws IllegalArgumentException { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } eTag = eTag.trim(); boolean weak = false; if (eTag.startsWith(WEAK)) { eTag = eTag.substring(WEAK.length()); weak = true; } if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) { if ("*".equals(eTag)) { return new EntityTag("*"); } throw new IllegalArgumentException(Messages.getMessage("entityTagNotQuoted", eTag)); } eTag = eTag.substring(1, eTag.length() - 1); StringBuilder builder = null; for (int i = 0; i < eTag.length(); i++) { if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) { if (builder == null) { builder = new StringBuilder(eTag.length()); builder.append(eTag, 0, i); } } else { if (builder != null) { builder.append(eTag.charAt(i)); } } } if (builder != null) { eTag = builder.toString(); } return new EntityTag(eTag, weak); }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public EntityTag fromString(String eTag) throws IllegalArgumentException { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } eTag = eTag.trim(); boolean weak = false; if (eTag.startsWith(WEAK)) { eTag = eTag.substring(WEAK.length()); weak = true; } if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) { if ("*".equals(eTag)) { return new EntityTag("*"); } throw new IllegalArgumentException(Messages.getMessage("entityTagNotQuoted", eTag)); } eTag = eTag.substring(1, eTag.length() - 1); StringBuilder builder = null; for (int i = 0; i < eTag.length(); i++) { if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) { if (builder == null) { builder = new StringBuilder(eTag.length()); builder.append(eTag, 0, i); } } else { if (builder != null) { builder.append(eTag.charAt(i)); } } } if (builder != null) { eTag = builder.toString(); } return new EntityTag(eTag, weak); } }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public EntityTag fromString(String eTag) throws IllegalArgumentException { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } eTag = eTag.trim(); boolean weak = false; if (eTag.startsWith(WEAK)) { eTag = eTag.substring(WEAK.length()); weak = true; } if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) { if ("*".equals(eTag)) { return new EntityTag("*"); } throw new IllegalArgumentException(Messages.getMessage("entityTagNotQuoted", eTag)); } eTag = eTag.substring(1, eTag.length() - 1); StringBuilder builder = null; for (int i = 0; i < eTag.length(); i++) { if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) { if (builder == null) { builder = new StringBuilder(eTag.length()); builder.append(eTag, 0, i); } } else { if (builder != null) { builder.append(eTag.charAt(i)); } } } if (builder != null) { eTag = builder.toString(); } return new EntityTag(eTag, weak); }  }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public EntityTag fromString(String eTag) throws IllegalArgumentException { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } eTag = eTag.trim(); boolean weak = false; if (eTag.startsWith(WEAK)) { eTag = eTag.substring(WEAK.length()); weak = true; } if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) { if ("*".equals(eTag)) { return new EntityTag("*"); } throw new IllegalArgumentException(Messages.getMessage("entityTagNotQuoted", eTag)); } eTag = eTag.substring(1, eTag.length() - 1); StringBuilder builder = null; for (int i = 0; i < eTag.length(); i++) { if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) { if (builder == null) { builder = new StringBuilder(eTag.length()); builder.append(eTag, 0, i); } } else { if (builder != null) { builder.append(eTag.charAt(i)); } } } if (builder != null) { eTag = builder.toString(); } return new EntityTag(eTag, weak); }  EntityTag fromString(String eTag); String toString(EntityTag eTag); }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public EntityTag fromString(String eTag) throws IllegalArgumentException { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } eTag = eTag.trim(); boolean weak = false; if (eTag.startsWith(WEAK)) { eTag = eTag.substring(WEAK.length()); weak = true; } if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) { if ("*".equals(eTag)) { return new EntityTag("*"); } throw new IllegalArgumentException(Messages.getMessage("entityTagNotQuoted", eTag)); } eTag = eTag.substring(1, eTag.length() - 1); StringBuilder builder = null; for (int i = 0; i < eTag.length(); i++) { if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) { if (builder == null) { builder = new StringBuilder(eTag.length()); builder.append(eTag, 0, i); } } else { if (builder != null) { builder.append(eTag.charAt(i)); } } } if (builder != null) { eTag = builder.toString(); } return new EntityTag(eTag, weak); }  EntityTag fromString(String eTag); String toString(EntityTag eTag);  }