/** * Retrieve the value associated with the given name, or null if there * is no current association. * * @param name the parameter name * @return the paramter's value */ public String getParameter(String name) { return parameters.get(name); }
/** * Remove any value associated with the given name. * * @param name the parameter name */ public void removeParameter(String name) { parameters.remove(name); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
for (i = skipWhiteSpace(parameterList, 0); i < length && (c = parameterList.charAt(i)) == ';'; i = skipWhiteSpace(parameterList, i)) { int lastIndex; String name; i = skipWhiteSpace(parameterList, i); while ((i < length) && isTokenChar(parameterList.charAt(i))) i++; i = skipWhiteSpace(parameterList, i); i = skipWhiteSpace(parameterList, i); "Encountered unterminated quoted parameter value."); value = unquote(parameterList.substring(lastIndex, i)); } else if (isTokenChar(c)) { while (i < length && isTokenChar(parameterList.charAt(i))) i++; value = parameterList.substring(lastIndex, i);
AcceptHeaderEntry(MimeType mediaType) { MimeTypeParameterList parametersWithoutQ = mediaType.getParameters(); String qValue = parametersWithoutQ.get("q"); parametersWithoutQ.remove("q"); this.mediaType = mimeType(mediaType.getBaseType() + parametersWithoutQ.toString()); if (qValue == null) { quality = 1000; } else { quality = (int) (Float.parseFloat(qValue) * 1000); } }
/** * Constructs a new MimeTypeParameterList with the passed in data. * * @param parameterList an RFC 2045, 2046 compliant parameter list. */ public MimeTypeParameterList(String parameterList) throws MimeTypeParseException { parameters = new Hashtable(); // now parse rawdata parse(parameterList); }
/** * Set the value to be associated with the given name, replacing * any previous association. * * @param name the parameter name * @param value the paramter's value */ public void setParameter(String name, String value) { parameters.set(name, value); }
/** * Return a string representation of this object. */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.ensureCapacity(parameters.size() * 16); // heuristic: 8 characters per field Enumeration keys = parameters.keys(); while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); buffer.append("; "); buffer.append(key); buffer.append('='); buffer.append(quote((String)parameters.get(key))); } return buffer.toString(); }
/** * Default constructor. */ public MimeType() { primaryType = "application"; subType = "*"; parameters = new MimeTypeParameterList(); }
/** * A routine that knows how and when to quote and escape the given value. */ private static String quote(String value) { boolean needsQuotes = false; // check to see if we actually have to quote this thing int length = value.length(); for (int i = 0; (i < length) && !needsQuotes; i++) { needsQuotes = !isTokenChar(value.charAt(i)); } if (needsQuotes) { StringBuffer buffer = new StringBuffer(); buffer.ensureCapacity((int)(length * 1.5)); // add the initial quote buffer.append('"'); // add the properly escaped text for (int i = 0; i < length; ++i) { char c = value.charAt(i); if ((c == '\\') || (c == '"')) buffer.append('\\'); buffer.append(c); } // add the closing quote buffer.append('"'); return buffer.toString(); } else { return value; } }
for (i = skipWhiteSpace(parameterList, 0); i < length && (c = parameterList.charAt(i)) == ';'; i = skipWhiteSpace(parameterList, i)) { int lastIndex; String name; i = skipWhiteSpace(parameterList, i); while ((i < length) && isTokenChar(parameterList.charAt(i))) i++; i = skipWhiteSpace(parameterList, i); i = skipWhiteSpace(parameterList, i); "Encountered unterminated quoted parameter value."); value = unquote(parameterList.substring(lastIndex, i)); } else if (isTokenChar(c)) { while (i < length && isTokenChar(parameterList.charAt(i))) i++; value = parameterList.substring(lastIndex, i);
/** * Constructs a new MimeTypeParameterList with the passed in data. * * @param parameterList an RFC 2045, 2046 compliant parameter list. */ public MimeTypeParameterList(String parameterList) throws MimeTypeParseException { parameters = new Hashtable(); // now parse rawdata parse(parameterList); }
/** * Set the value to be associated with the given name, replacing * any previous association. * * @param name the parameter name * @param value the paramter's value */ public void setParameter(String name, String value) { parameters.set(name, value); }
/** * Return a string representation of this object. */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.ensureCapacity(parameters.size() * 16); // heuristic: 8 characters per field Enumeration keys = parameters.keys(); while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); buffer.append("; "); buffer.append(key); buffer.append('='); buffer.append(quote((String)parameters.get(key))); } return buffer.toString(); }
subType = rawdata.substring(slashIndex + 1).trim(). toLowerCase(Locale.ENGLISH); parameters = new MimeTypeParameterList(); } else if (slashIndex < semIndex) { subType = rawdata.substring(slashIndex + 1, semIndex).trim(). toLowerCase(Locale.ENGLISH); parameters = new MimeTypeParameterList(rawdata.substring(semIndex)); } else {
/** * A routine that knows how and when to quote and escape the given value. */ private static String quote(String value) { boolean needsQuotes = false; // check to see if we actually have to quote this thing int length = value.length(); for (int i = 0; (i < length) && !needsQuotes; i++) { needsQuotes = !isTokenChar(value.charAt(i)); } if (needsQuotes) { StringBuffer buffer = new StringBuffer(); buffer.ensureCapacity((int)(length * 1.5)); // add the initial quote buffer.append('"'); // add the properly escaped text for (int i = 0; i < length; ++i) { char c = value.charAt(i); if ((c == '\\') || (c == '"')) buffer.append('\\'); buffer.append(c); } // add the closing quote buffer.append('"'); return buffer.toString(); } else { return value; } }
for (i = skipWhiteSpace(parameterList, 0); i < length && (c = parameterList.charAt(i)) == ';'; i = skipWhiteSpace(parameterList, i)) { int lastIndex; String name; i = skipWhiteSpace(parameterList, i); while ((i < length) && isTokenChar(parameterList.charAt(i))) i++; i = skipWhiteSpace(parameterList, i); i = skipWhiteSpace(parameterList, i); "Encountered unterminated quoted parameter value."); value = unquote(parameterList.substring(lastIndex, i)); } else if (isTokenChar(c)) { while (i < length && isTokenChar(parameterList.charAt(i))) i++; value = parameterList.substring(lastIndex, i);
/** * Retrieve the value associated with the given name, or null if there * is no current association. * * @param name the parameter name * @return the paramter's value */ public String getParameter(String name) { return parameters.get(name); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }