예제 #1
0
 /** Parses a media type from a string such as <tt>text/html;charset=utf-8;q=0.9</tt>. */
 public static MediaRangeSpec parseType(String mediaType) {
   MediaRangeSpec m = parseRange(mediaType);
   if (m == null || m.isWildcardType() || m.isWildcardSubtype()) {
     return null;
   }
   return m;
 }
예제 #2
0
 public int getPrecedence(MediaRangeSpec range) {
   if (range.isWildcardType()) {
     return 1;
   }
   if (!range.type.equals(type)) {
     return 0;
   }
   if (range.isWildcardSubtype()) {
     return 2;
   }
   if (!range.subtype.equals(subtype)) {
     return 0;
   }
   if (range.getParameterNames().isEmpty()) {
     return 3;
   }
   int result = 3;
   for (int i = 0; i < range.getParameterNames().size(); i++) {
     String name = (String) range.getParameterNames().get(i);
     String value = range.getParameter(name);
     if (!value.equals(getParameter(name))) {
       return 0;
     }
     result++;
   }
   return result;
 }