1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.googleapps;
16  
17  import com.liferay.portal.kernel.googleapps.GEmailSettingsManager;
18  import com.liferay.portal.kernel.googleapps.GoogleAppsException;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.xml.Document;
21  import com.liferay.portal.kernel.xml.Element;
22  import com.liferay.portal.kernel.xml.SAXReaderUtil;
23  
24  /**
25   * <a href="GEmailSettingsManagerImpl.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class GEmailSettingsManagerImpl
30      extends GBaseManagerImpl implements GEmailSettingsManager {
31  
32      public GEmailSettingsManagerImpl(GoogleApps googleApps) {
33          super(googleApps);
34  
35          GAuthenticator gAuthenticator = googleApps.getGAuthenticator();
36  
37          emailSettingsURL =
38              APPS_URL.concat("/emailsettings/2.0/").concat(
39                  gAuthenticator.getDomain());
40      }
41  
42      public void addSendAs(long userId, String fullName, String emailAddress)
43          throws GoogleAppsException {
44  
45          Document document = SAXReaderUtil.createDocument();
46  
47          Element atomEntryElement = addAtomEntry(document);
48  
49          addAppsProperty(atomEntryElement, "name", fullName);
50          addAppsProperty(atomEntryElement, "address", emailAddress);
51          addAppsProperty(
52              atomEntryElement, "makeDefault", Boolean.TRUE.toString());
53  
54          submitAdd(getEmailSettingsURL(userId).concat("/sendas"), document);
55      }
56  
57      protected String getEmailSettingsURL(long userId) {
58          return emailSettingsURL.concat(StringPool.SLASH).concat(
59              String.valueOf(userId));
60      }
61  
62      protected String emailSettingsURL;
63  
64  }