/** * Removes the picture from local attachment collection. * * @throws Exception the exception */ private void internalRemoveContactPicture() throws Exception { // Iterates in reverse order to remove file attachments that have // IsContactPhoto set to true. for (int index = this.getAttachments().getCount() - 1; index >= 0; index--) { FileAttachment fileAttachment = (FileAttachment) this .getAttachments().getPropertyAtIndex(index); if (fileAttachment != null) { if (fileAttachment.isContactPhoto()) { this.getAttachments().remove(fileAttachment); } } } }
/** * Sets the contact's picture using the specified file. * * @param fileName the new contact picture * @throws Exception the exception */ public void setContactPicture(String fileName) throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture"); internalRemoveContactPicture(); FileAttachment fileAttachment = getAttachments().addFileAttachment( new File(fileName).getName(), fileName); fileAttachment.setIsContactPhoto(true); }
/** * Sets the contact's picture using the specified byte array. * * @param content the new contact picture * @throws Exception the exception */ public void setContactPicture(byte[] content) throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture"); internalRemoveContactPicture(); FileAttachment fileAttachment = getAttachments().addFileAttachment( ContactPictureName, content); fileAttachment.setIsContactPhoto(true); }
/** * Sets the contact's picture using the specified stream. * * @param contentStream the new contact picture * @throws Exception the exception */ public void setContactPicture(InputStream contentStream) throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture"); internalRemoveContactPicture(); FileAttachment fileAttachment = getAttachments().addFileAttachment( ContactPictureName, contentStream); fileAttachment.setIsContactPhoto(true); }
/** * Retrieves the file attachment that holds the contact's picture. * * @return The file attachment that holds the contact's picture. * @throws ServiceLocalException the service local exception */ public FileAttachment getContactPictureAttachment() throws ServiceLocalException { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "GetContactPictureAttachment"); if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) { throw new PropertyException("The attachment collection must be loaded."); } for (Attachment fileAttachment : this.getAttachments()) { if (fileAttachment instanceof FileAttachment) { if (((FileAttachment) fileAttachment).isContactPhoto()) { return (FileAttachment) fileAttachment; } } } return null; }
/** * Removes the picture from local attachment collection. * * @throws Exception the exception */ private void internalRemoveContactPicture() throws Exception { // Iterates in reverse order to remove file attachments that have // IsContactPhoto set to true. for (int index = this.getAttachments().getCount() - 1; index >= 0; index--) { FileAttachment fileAttachment = (FileAttachment) this .getAttachments().getPropertyAtIndex(index); if (fileAttachment != null) { if (fileAttachment.isContactPhoto()) { this.getAttachments().remove(fileAttachment); } } } }
/** * Sets the contact's picture using the specified file. * * @param fileName the new contact picture * @throws Exception the exception */ public void setContactPicture(String fileName) throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture"); internalRemoveContactPicture(); FileAttachment fileAttachment = getAttachments().addFileAttachment( new File(fileName).getName(), fileName); fileAttachment.setIsContactPhoto(true); }
/** * Sets the contact's picture using the specified byte array. * * @param content the new contact picture * @throws Exception the exception */ public void setContactPicture(byte[] content) throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture"); internalRemoveContactPicture(); FileAttachment fileAttachment = getAttachments().addFileAttachment( ContactPictureName, content); fileAttachment.setIsContactPhoto(true); }
/** * Sets the contact's picture using the specified stream. * * @param contentStream the new contact picture * @throws Exception the exception */ public void setContactPicture(InputStream contentStream) throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture"); internalRemoveContactPicture(); FileAttachment fileAttachment = getAttachments().addFileAttachment( ContactPictureName, contentStream); fileAttachment.setIsContactPhoto(true); }
/** * Retrieves the file attachment that holds the contact's picture. * * @return The file attachment that holds the contact's picture. * @throws ServiceLocalException the service local exception */ public FileAttachment getContactPictureAttachment() throws ServiceLocalException { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "GetContactPictureAttachment"); if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) { throw new PropertyException("The attachment collection must be loaded."); } for (Attachment fileAttachment : this.getAttachments()) { if (fileAttachment instanceof FileAttachment) { if (((FileAttachment) fileAttachment).isContactPhoto()) { return (FileAttachment) fileAttachment; } } } return null; }