AddressListField.java revision 96c5af40d639d629267794f4f0338a267ff94ce5
1/**************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 20package org.apache.james.mime4j.field; 21 22import org.apache.commons.logging.Log; 23import org.apache.commons.logging.LogFactory; 24import org.apache.james.mime4j.field.address.AddressList; 25import org.apache.james.mime4j.field.address.parser.ParseException; 26 27public class AddressListField extends Field { 28 private AddressList addressList; 29 private ParseException parseException; 30 31 protected AddressListField(String name, String body, String raw, AddressList addressList, ParseException parseException) { 32 super(name, body, raw); 33 this.addressList = addressList; 34 this.parseException = parseException; 35 } 36 37 public AddressList getAddressList() { 38 return addressList; 39 } 40 41 public ParseException getParseException() { 42 return parseException; 43 } 44 45 public static class Parser implements FieldParser { 46 private static Log log = LogFactory.getLog(Parser.class); 47 48 public Field parse(final String name, final String body, final String raw) { 49 AddressList addressList = null; 50 ParseException parseException = null; 51 try { 52 addressList = AddressList.parse(body); 53 } 54 catch (ParseException e) { 55 if (log.isDebugEnabled()) { 56 log.debug("Parsing value '" + body + "': "+ e.getMessage()); 57 } 58 parseException = e; 59 } 60 return new AddressListField(name, body, raw, addressList, parseException); 61 } 62 } 63} 64