View Javadoc
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  package davmail.exchange.ews;
20  
21  import java.io.IOException;
22  import java.io.Writer;
23  
24  /**
25   * File Attachment.
26   */
27  public class FileAttachment {
28      protected String name;
29      protected String contentType;
30      protected String content;
31      protected String attachmentId;
32      protected boolean isContactPhoto;
33  
34      /**
35       * Default constructor
36       */
37      public FileAttachment() {
38          // empty constructor
39      }
40  
41      /**
42       * Build file attachment.
43       *
44       * @param name        attachment name
45       * @param contentType content type
46       * @param content     body as string
47       */
48      public FileAttachment(String name, String contentType, String content) {
49          this.name = name;
50          this.contentType = contentType;
51          this.content = content;
52      }
53  
54      /**
55       * Write XML content to writer.
56       *
57       * @param writer writer
58       * @throws IOException on error
59       */
60      public void write(Writer writer) throws IOException {
61          writer.write("<t:FileAttachment>");
62          if (name != null) {
63              writer.write("<t:Name>");
64              writer.write(name);
65              writer.write("</t:Name>");
66          }
67          if (contentType != null) {
68              writer.write("<t:ContentType>");
69              writer.write(contentType);
70              writer.write("</t:ContentType>");
71          }
72          if (isContactPhoto) {
73              writer.write("<t:IsContactPhoto>true</t:IsContactPhoto>");
74          }
75          if (content != null) {
76              writer.write("<t:Content>");
77              writer.write(content);
78              writer.write("</t:Content>");
79          }
80          writer.write("</t:FileAttachment>");
81      }
82  
83      /**
84       * Exchange 2010 only: set contact photo flag on attachment.
85       *
86       * @param isContactPhoto contact photo flag
87       */
88      public void setIsContactPhoto(boolean isContactPhoto) {
89          this.isContactPhoto = isContactPhoto;
90      }
91  
92  }