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.util.StringPool;
18  import com.liferay.portal.kernel.xml.Document;
19  import com.liferay.portal.kernel.xml.Element;
20  import com.liferay.portal.kernel.xml.SAXReaderUtil;
21  
22  /**
23   * <a href="GEmailSettingsManagerImpl.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class GEmailSettingsManagerImpl
28      extends GBaseManagerImpl implements GEmailSettingsManager {
29  
30      public GEmailSettingsManagerImpl(GoogleApps googleApps) {
31          super(googleApps);
32  
33          GAuthenticator gAuthenticator = googleApps.getGAuthenticator();
34  
35          emailSettingsURL =
36              APPS_URL.concat("/emailsettings/2.0/").concat(
37                  gAuthenticator.getDomain());
38      }
39  
40      public void addSendAs(long userId, String fullName, String emailAddress)
41          throws GoogleAppsException {
42  
43          Document document = SAXReaderUtil.createDocument();
44  
45          Element atomEntryElement = addAtomEntry(document);
46  
47          addAppsProperty(atomEntryElement, "name", fullName);
48          addAppsProperty(atomEntryElement, "address", emailAddress);
49          addAppsProperty(
50              atomEntryElement, "makeDefault", Boolean.TRUE.toString());
51  
52          submitAdd(getEmailSettingsURL(userId).concat("/sendas"), document);
53      }
54  
55      protected String getEmailSettingsURL(long userId) {
56          return emailSettingsURL.concat(StringPool.SLASH).concat(
57              String.valueOf(userId));
58      }
59  
60      protected String emailSettingsURL;
61  
62  }