public Object createServiceObjectWithServiceParam( ExchangeService srv) throws Exception { return new Contact(srv); } }, new ICreateServiceObjectWithAttachmentParam() {
/** * Binds to an existing contact and loads its first class property. * Calling this method results in a call to EWS. * * @param service the service * @param id the id * @return A Contact instance representing the contact corresponding to the * specified Id. * @throws Exception the exception */ public static Contact bind(ExchangeService service, ItemId id) throws Exception { return Contact.bind(service, id, PropertySet.getFirstClassProperties()); }
/** * 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); }
/** * Removes the contact's picture. * * @throws Exception the exception */ public void removeContactPicture() throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "RemoveContactPicture"); if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) { throw new PropertyException("The attachment collection must be loaded."); } internalRemoveContactPicture(); }
/** * Sets the middle name. * * @param value the new middle name * @throws Exception the exception */ public void setMiddleName(String value) throws Exception { this.getPropertyBag().setObjectFromPropertyDefinition( ContactSchema.MiddleName, value); }
/** * 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; }
/** * Initializes a new instance of the GroupMember class. * * @param contact The contact to link to. * @param emailAddressKey The contact's e-mail address to link to. * @throws Exception the exception */ public GroupMember(Contact contact, EmailAddressKey emailAddressKey) throws Exception { this(); EwsUtilities.validateParam(contact, "contact"); EmailAddress emailAddress = contact.getEmailAddresses() .getEmailAddress(emailAddressKey); this.setAddressInformation(new EmailAddress(emailAddress)); this.getAddressInformation().setId(contact.getId()); }
/** * Validates this instance. * * @throws ServiceVersionException the service version exception * @throws Exception the exception */ @Override public void validate() throws ServiceVersionException, Exception { super.validate(); Object fileAsMapping; OutParam<Object> outParam = new OutParam<Object>(); if (this.tryGetProperty(ContactSchema.FileAsMapping, outParam)) { fileAsMapping = outParam.getParam(); // FileAsMapping is extended by 5 new values in 2010 mode. Validate // that they are used according the version. EwsUtilities.validateEnumVersionValue( (FileAsMapping) fileAsMapping, this.getService() .getRequestedServerVersion()); } }
/** * Loads from XML. * * @param reader the reader * @throws Exception the exception */ protected void loadFromXml(EwsServiceXmlReader reader) throws Exception { reader.readStartElement(XmlNamespace.Types, XmlElementNames.Resolution); reader.readStartElement(XmlNamespace.Types, XmlElementNames.Mailbox); this.mailbox.loadFromXml(reader, XmlElementNames.Mailbox); reader.read(); if (reader.isStartElement(XmlNamespace.Types, XmlElementNames.Contact)) { this.contact = new Contact(this.owner.getSession()); this.contact.loadFromXml(reader, true /* clearPropertyBag */, PropertySet.FirstClassProperties, false /* summaryPropertiesOnly */); reader.readEndElement(XmlNamespace.Types, XmlElementNames.Resolution); } else { reader.ensureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.Resolution); } }
/** * 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); } } } }
/** * Gets the nick name of the contact. * * @return the nick name * @throws ServiceLocalException the service local exception */ public String getNickName() throws ServiceLocalException { return getPropertyBag().getObjectFromPropertyDefinition( ContactSchema.NickName); }
/** * Removes the contact's picture. * * @throws Exception the exception */ public void removeContactPicture() throws Exception { EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "RemoveContactPicture"); if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) { throw new PropertyException("The attachment collection must be loaded."); } internalRemoveContactPicture(); }
/** * 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; }
/** * Initializes a new instance of the GroupMember class. * * @param contact The contact to link to. * @param emailAddressKey The contact's e-mail address to link to. * @throws Exception the exception */ public GroupMember(Contact contact, EmailAddressKey emailAddressKey) throws Exception { this(); EwsUtilities.validateParam(contact, "contact"); EmailAddress emailAddress = contact.getEmailAddresses() .getEmailAddress(emailAddressKey); this.setAddressInformation(new EmailAddress(emailAddress)); this.getAddressInformation().setId(contact.getId()); }
/** * Validates this instance. * * @throws ServiceVersionException the service version exception * @throws Exception the exception */ @Override public void validate() throws ServiceVersionException, Exception { super.validate(); Object fileAsMapping; OutParam<Object> outParam = new OutParam<Object>(); if (this.tryGetProperty(ContactSchema.FileAsMapping, outParam)) { fileAsMapping = outParam.getParam(); // FileAsMapping is extended by 5 new values in 2010 mode. Validate // that they are used according the version. EwsUtilities.validateEnumVersionValue( (FileAsMapping) fileAsMapping, this.getService() .getRequestedServerVersion()); } }
/** * Loads from XML. * * @param reader the reader * @throws Exception the exception */ protected void loadFromXml(EwsServiceXmlReader reader) throws Exception { reader.readStartElement(XmlNamespace.Types, XmlElementNames.Resolution); reader.readStartElement(XmlNamespace.Types, XmlElementNames.Mailbox); this.mailbox.loadFromXml(reader, XmlElementNames.Mailbox); reader.read(); if (reader.isStartElement(XmlNamespace.Types, XmlElementNames.Contact)) { this.contact = new Contact(this.owner.getSession()); this.contact.loadFromXml(reader, true /* clearPropertyBag */, PropertySet.FirstClassProperties, false /* summaryPropertiesOnly */); reader.readEndElement(XmlNamespace.Types, XmlElementNames.Resolution); } else { reader.ensureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.Resolution); } }
/** * 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 nick name. * * @param value the new nick name * @throws Exception the exception */ public void setNickName(String value) throws Exception { this.getPropertyBag().setObjectFromPropertyDefinition( ContactSchema.NickName, value); }
/** * 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); }
public Object createServiceObjectWithAttachmentParam( ItemAttachment itemAttachment, boolean isNew) throws Exception { return new Contact(itemAttachment); } });