Clover coverage report - Maven Clover report
Coverage timestamp: Sun Aug 20 2006 04:01:04 PDT
file stats: LOC: 110   Methods: 10
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContentDisposition.java 64.3% 86.2% 100% 83%
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    // http://www.faqs.org/rfcs/rfc2183.html
 21   
 22    /**
 23    * @version $Rev: 381393 $ $Date: 2006-02-27 09:38:03 -0800 (Mon, 27 Feb 2006) $
 24    */
 25    public class ContentDisposition {
 26    private String _disposition;
 27    private ParameterList _list;
 28   
 29  1 public ContentDisposition() {
 30  1 setDisposition(null);
 31  1 setParameterList(null);
 32    }
 33   
 34  7 public ContentDisposition(String disposition) throws ParseException {
 35    // get a token parser for the type information
 36  7 HeaderTokenizer tokenizer = new HeaderTokenizer(disposition, HeaderTokenizer.MIME);
 37   
 38    // get the first token, which must be an ATOM
 39  7 HeaderTokenizer.Token token = tokenizer.next();
 40  7 if (token.getType() != HeaderTokenizer.Token.ATOM) {
 41  0 throw new ParseException("Invalid content disposition");
 42    }
 43   
 44  7 _disposition = token.getValue();
 45   
 46    // the remainder is parameters, which ParameterList will take care of parsing.
 47  7 String remainder = tokenizer.getRemainder();
 48  7 if (remainder != null) {
 49  7 _list = new ParameterList(remainder);
 50    }
 51    }
 52   
 53  1 public ContentDisposition(String disposition, ParameterList list) {
 54  1 setDisposition(disposition);
 55  1 setParameterList(list);
 56    }
 57   
 58  6 public String getDisposition() {
 59  6 return _disposition;
 60    }
 61   
 62  7 public String getParameter(String name) {
 63  7 if (_list == null) {
 64  0 return null;
 65    } else {
 66  7 return _list.get(name);
 67    }
 68    }
 69   
 70  4 public ParameterList getParameterList() {
 71  4 return _list;
 72    }
 73   
 74  3 public void setDisposition(String string) {
 75  3 _disposition = string;
 76    }
 77   
 78  2 public void setParameter(String name, String value) {
 79  2 if (_list == null) {
 80  0 _list = new ParameterList();
 81    }
 82  2 _list.set(name, value);
 83    }
 84   
 85  2 public void setParameterList(ParameterList list) {
 86  2 if (list == null) {
 87  1 _list = new ParameterList();
 88    } else {
 89  1 _list = list;
 90    }
 91    }
 92   
 93  5 public String toString() {
 94    // it is possible we might have a parameter list, but this is meaningless if
 95    // there is no disposition string. Return a failure.
 96  5 if (_disposition == null) {
 97  1 return null;
 98    }
 99   
 100   
 101    // no parameter list? Just return the disposition string
 102  4 if (_list == null) {
 103  0 return _disposition;
 104    }
 105   
 106    // format this for use on a Content-Disposition header, which means we need to
 107    // account for the length of the header part too.
 108  4 return _disposition + _list.toString(21 + _disposition.length());
 109    }
 110    }