public static ContentDisposition buildFromString(String value) { // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1 for rules ParametersScanner scanner = new ParametersScanner(0, value); String firstAttribute = scanner.NextAttribute(); if (null == firstAttribute) { BaseException e = new BaseException(typeof(ContentDisposition), "null == firstAttribute; value = {0}", value); throw e; } String dispExtensionToken = null; if ("attachment".Equals(firstAttribute)) { // we leave _dispExtensionToken as null } else { dispExtensionToken = firstAttribute; } ContentDisposition answer = new ContentDisposition(value); answer._dispExtensionToken = dispExtensionToken; for( String attribute = scanner.NextAttribute(); null != attribute; attribute = scanner.NextAttribute() ) { log.debug(attribute, "attribute"); String attributeValue = scanner.nextValue(); log.debug(attributeValue, "attributeValue"); answer._dispositionParameters[attribute] = attributeValue; } return answer; }
public static MediaType buildFromString(String value) { int indexOfSlash = value.IndexOf("/"); if (-1 == indexOfSlash) { BaseException e = new BaseException(typeof(MediaType), "-1 == indexOfSlash; value = {0}", value); throw e; } MediaType answer = new MediaType(value); String type = value.Substring(0, indexOfSlash); // int startIndex, int length log.debug(type, "type"); answer._type = type; String remainder = value.Substring(indexOfSlash+1); log.debug(remainder, "remainder"); String subtype; { int indexOfSemiColon = remainder.IndexOf(";"); if (-1 == indexOfSemiColon) { subtype = remainder.Trim(); } else { subtype = remainder.Substring(0, indexOfSemiColon); // int startIndex, int length ParametersScanner scanner = new ParametersScanner(indexOfSemiColon, remainder); String attribute; while (null != (attribute = scanner.NextAttribute())) { log.debug(attribute, "attribute"); String attributeValue = scanner.nextValue(); log.debug(attributeValue, "attributeValue"); answer._parameters[attribute] = attributeValue; } } } log.debug(subtype, "subtype"); answer._subtype = subtype; return answer; }