Clover coverage report - Maven Clover report
Coverage timestamp: Sun Aug 20 2006 03:34:28 PDT
file stats: LOC: 135   Methods: 15
NCLOC: 83   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContentType.java 68.8% 88.9% 93.3% 85.1%
coverage coverage
 1    /**
 2    *
 3    * Copyright 2003-2004 The Apache Software Foundation
 4    *
 5    * Licensed under the Apache License, Version 2.0 (the "License");
 6    * you may not use this file except in compliance with the License.
 7    * You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    */
 17   
 18    package javax.mail.internet;
 19   
 20    // can be in the form major/minor; charset=jobby
 21   
 22    /**
 23    * @version $Rev: 381393 $ $Date: 2006-02-27 09:38:03 -0800 (Mon, 27 Feb 2006) $
 24    */
 25    public class ContentType {
 26    private ParameterList _list;
 27    private String _minor;
 28    private String _major;
 29   
 30  1 public ContentType() {
 31    // the Sun version makes everything null here.
 32    }
 33   
 34  4 public ContentType(String major, String minor, ParameterList list) {
 35  4 _major = major;
 36  4 _minor = minor;
 37  4 _list = list;
 38    }
 39   
 40  66 public ContentType(String type) throws ParseException {
 41    // get a token parser for the type information
 42  66 HeaderTokenizer tokenizer = new HeaderTokenizer(type, HeaderTokenizer.MIME);
 43   
 44    // get the first token, which must be an ATOM
 45  66 HeaderTokenizer.Token token = tokenizer.next();
 46  66 if (token.getType() != HeaderTokenizer.Token.ATOM) {
 47  1 throw new ParseException("Invalid content type");
 48    }
 49   
 50  65 _major = token.getValue();
 51   
 52    // the MIME type must be major/minor
 53  65 token = tokenizer.next();
 54  65 if (token.getType() != '/') {
 55  0 throw new ParseException("Invalid content type");
 56    }
 57   
 58   
 59    // this must also be an atom. Content types are not permitted to be wild cards.
 60  65 token = tokenizer.next();
 61  65 if (token.getType() != HeaderTokenizer.Token.ATOM) {
 62  0 throw new ParseException("Invalid content type");
 63    }
 64   
 65  65 _minor = token.getValue();
 66   
 67    // the remainder is parameters, which ParameterList will take care of parsing.
 68  65 String remainder = tokenizer.getRemainder();
 69  65 if (remainder != null) {
 70  65 _list = new ParameterList(remainder);
 71    }
 72    }
 73   
 74  6 public String getPrimaryType() {
 75  6 return _major;
 76    }
 77   
 78  6 public String getSubType() {
 79  6 return _minor;
 80    }
 81   
 82  21 public String getBaseType() {
 83  21 return _major + "/" + _minor;
 84    }
 85   
 86  14 public String getParameter(String name) {
 87  14 return (_list == null ? null : _list.get(name));
 88    }
 89   
 90  3 public ParameterList getParameterList() {
 91  3 return _list;
 92    }
 93   
 94  1 public void setPrimaryType(String major) {
 95  1 _major = major;
 96    }
 97   
 98  1 public void setSubType(String minor) {
 99  1 _minor = minor;
 100    }
 101   
 102  9 public void setParameter(String name, String value) {
 103  9 if (_list == null) {
 104  3 _list = new ParameterList();
 105    }
 106  9 _list.set(name, value);
 107    }
 108   
 109  0 public void setParameterList(ParameterList list) {
 110  0 _list = list;
 111    }
 112   
 113  16 public String toString() {
 114  16 if (_major == null || _minor == null) {
 115  0 return null;
 116    }
 117   
 118  16 return getBaseType() + (_list == null ? "" : _list.toString());
 119    }
 120   
 121  43 public boolean match(ContentType other) {
 122  43 return _major.equalsIgnoreCase(other._major)
 123    && (_minor.equalsIgnoreCase(other._minor)
 124    || _minor.equals("*")
 125    || other._minor.equals("*"));
 126    }
 127   
 128  32 public boolean match(String contentType) {
 129  32 try {
 130  32 return match(new ContentType(contentType));
 131    } catch (ParseException e) {
 132  2 return false;
 133    }
 134    }
 135    }