* @return the quality value of the mime type either calculated from the rules above or the actual value defined.
* @throws MimeException this is thrown if the mime type pattern is invalid.
*/
public static double getMimeQuality(String mimeType) throws MimeException{
if(mimeType == null) {
throw new MimeException("Invalid MimeType [" + mimeType + "].");
}
String [] parts = mimeSplitter.split(mimeType);
if(parts.length < 2) {
throw new MimeException("Invalid MimeType [" + mimeType + "].");
}
if(parts.length > 2) {
for(int i = 2; i < parts.length; i++) {
if(parts[i].trim().startsWith("q=")) {
// Get the number part
try {
// Get the quality factor
double d = Double.parseDouble(parts[i].split("=")[1].trim());
return d > 1.0 ? 1.0 : d;
}catch(NumberFormatException e) {
throw new MimeException("Invalid Mime quality indicator [" + parts[i].trim() + "]. Must be a valid double between 0 and 1");
}catch(Exception e) {
throw new MimeException("Error parsing Mime quality indicator.", e);
}
}
}
}
// No quality indicator so always assume its 1 unless a wild card is used