001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
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    }