/** Get a mime type from the registry or create a new one if not available. */ public static MimeType getOrCreate(String type, String subtype) { for (MimeType t : get(type, subtype)) return t; return mimeType(type, subtype); }
/** * Returns a mime type for the given type and subtype, e. g. <code>video/mj2</code>. * * @param mimeType * the mime type * @return the corresponding mime type */ public static MimeType parseMimeType(String mimeType) { final Matcher m = MIME_TYPE_PATTERN.matcher(mimeType); if (!m.matches()) throw new IllegalArgumentException("Malformed mime type '" + mimeType + "'"); final String type = m.group(1); final String subtype = m.group(2); for (MimeType t : mimeTypes) { if (t.getType().equals(type) && t.getSubtype().equals(subtype)) return t; } return mimeType(type, subtype); }
@Override public void endElement(String uri, String localName, String name) throws SAXException { super.endElement(uri, localName, name); if ("Type".equals(name)) { type = getContent(); return; } else if ("Description".equals(name)) { description = getContent(); return; } if ("Extensions".equals(name)) { extensions = getContent(); return; } else if ("MimeType".equals(name)) { String[] t = type.split("/"); MimeType mimeType = mimeType(t[0].trim(), t[1].trim(), mlist(extensions.split(",")).bind(Options.<String> asList().o(Strings.trimToNone)).value(), Collections.<MimeType> nil(), option(description), none(""), none("")); registry.add(mimeType); } }