1 36 package org.columba.ristretto.parser; 37 38 import java.util.regex.Matcher ; 39 import java.util.regex.Pattern ; 40 41 import org.columba.ristretto.message.MimeType; 42 43 48 public class MimeTypeParser { 49 50 private static final Pattern mimetypePattern = Pattern.compile("([^/\\s]+)/([^\\s;]+)"); 51 52 private MimeTypeParser() { 53 } 54 55 64 public static MimeType parse(CharSequence mimeType ) throws ParserException { 65 if( mimeType == null ) throw new ParserException( "Input is null"); 66 Matcher matcher = mimetypePattern.matcher(mimeType); 67 if( matcher.find() ) { 68 return new MimeType( matcher.group(1).toLowerCase(), matcher.group(2).toLowerCase()); 69 } else throw new ParserException(); 70 } 71 72 } 73 | Popular Tags |