001    /**
002     * Copyright (c) 2000-2010 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 =
036                            APPS_URL.concat("/emailsettings/2.0/").concat(
037                                    gAuthenticator.getDomain());
038            }
039    
040            public void addSendAs(long userId, String fullName, String emailAddress)
041                    throws GoogleAppsException {
042    
043                    Document document = SAXReaderUtil.createDocument();
044    
045                    Element atomEntryElement = addAtomEntry(document);
046    
047                    addAppsProperty(atomEntryElement, "name", fullName);
048                    addAppsProperty(atomEntryElement, "address", emailAddress);
049                    addAppsProperty(
050                            atomEntryElement, "makeDefault", Boolean.TRUE.toString());
051    
052                    submitAdd(getEmailSettingsURL(userId).concat("/sendas"), document);
053            }
054    
055            protected String getEmailSettingsURL(long userId) {
056                    return emailSettingsURL.concat(StringPool.SLASH).concat(
057                            String.valueOf(userId));
058            }
059    
060            protected String emailSettingsURL;
061    
062    }