001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.googleapps;
016    
017    import com.liferay.portal.kernel.googleapps.GEmailSettingsManager;
018    import com.liferay.portal.kernel.googleapps.GoogleAppsException;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.xml.Document;
021    import com.liferay.portal.kernel.xml.Element;
022    import com.liferay.portal.kernel.xml.SAXReaderUtil;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class GEmailSettingsManagerImpl
028            extends GBaseManagerImpl implements GEmailSettingsManager {
029    
030            public GEmailSettingsManagerImpl(GoogleApps googleApps) {
031                    super(googleApps);
032    
033                    GAuthenticator gAuthenticator = googleApps.getGAuthenticator();
034    
035                    emailSettingsURL = APPS_URL.concat(
036                            "/emailsettings/2.0/").concat(gAuthenticator.getDomain());
037            }
038    
039            public void addSendAs(long userId, String fullName, String emailAddress)
040                    throws GoogleAppsException {
041    
042                    Document document = SAXReaderUtil.createDocument();
043    
044                    Element atomEntryElement = addAtomEntry(document);
045    
046                    addAppsProperty(atomEntryElement, "name", fullName);
047                    addAppsProperty(atomEntryElement, "address", emailAddress);
048                    addAppsProperty(
049                            atomEntryElement, "makeDefault", Boolean.TRUE.toString());
050    
051                    submitAdd(getEmailSettingsURL(userId).concat("/sendas"), document);
052            }
053    
054            protected String getEmailSettingsURL(long userId) {
055                    return emailSettingsURL.concat(StringPool.SLASH).concat(
056                            String.valueOf(userId));
057            }
058    
059            protected String emailSettingsURL;
060    
061    }