1 /* 2 * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway 3 * Copyright (C) 2010 Mickael Guessant 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 package davmail.exchange.ews; 21 22 import java.io.IOException; 23 import java.io.Writer; 24 import java.util.ArrayList; 25 26 /** 27 * Specific field update class to handle multiple attendee values 28 */ 29 public class MultiValuedFieldUpdate extends FieldUpdate { 30 ArrayList<String> values = new ArrayList<>(); 31 32 /** 33 * Create field update with value. 34 * 35 * @param fieldURI target field 36 */ 37 public MultiValuedFieldUpdate(FieldURI fieldURI) { 38 this.fieldURI = fieldURI; 39 } 40 41 /** 42 * Add single value 43 * 44 * @param value value 45 */ 46 public void addValue(String value) { 47 values.add(value); 48 } 49 50 /** 51 * Write field to request writer. 52 * 53 * @param itemType item type 54 * @param writer request writer 55 * @throws IOException on error 56 */ 57 @Override 58 public void write(String itemType, Writer writer) throws IOException { 59 String action; 60 //noinspection VariableNotUsedInsideIf 61 if (values.isEmpty()) { 62 action = "Delete"; 63 } else { 64 action = "Set"; 65 } 66 if (itemType != null) { 67 writer.write("<t:"); 68 writer.write(action); 69 writer.write(itemType); 70 writer.write("Field>"); 71 } 72 73 // do not try to set empty value on create 74 if (itemType != null || (!values.isEmpty())) { 75 StringBuilder buffer = new StringBuilder(); 76 ((UnindexedFieldURI)fieldURI).appendValues(buffer, itemType, values); 77 writer.write(buffer.toString()); 78 } 79 80 if (itemType != null) { 81 writer.write("</t:"); 82 writer.write(action); 83 writer.write(itemType); 84 writer.write("Field>"); 85 } 86 } 87 88 }