⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appsforyourdomainclient.java

📁 google的gdata api包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      if (nextLink != null) {        retrieveUrl = new URL(nextLink.getHref());      }    } while (nextLink != null);    return allNicknames;  }  /**   * Deletes a nickname.   *   * @param nickname The nickname you wish to delete.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public void deleteNickname(String nickname)      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Deleting nickname '" + nickname + "'.");    URL deleteUrl = new URL(domainUrlBase + "nickname/" 	+ SERVICE_VERSION + "/" + nickname);    nicknameService.delete(deleteUrl);  }  /**   * Creates an empty email list.   *   * @param emailList The name of the email list you wish to create.   * @return An EmailListEntry object of the newly created email list.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListEntry createEmailList(String emailList)       throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Creating email list '" + emailList + "'.");    EmailListEntry entry = new EmailListEntry();    EmailList emailListExtension = new EmailList();    emailListExtension.setName(emailList);    entry.addExtension(emailListExtension);    URL insertUrl = new URL(domainUrlBase + "emailList/" + SERVICE_VERSION);    return emailListService.insert(insertUrl, entry);  }  /**   * Retrieves all email lists in which the recipient is subscribed. Recipient   * can be given as a username or an email address of a hosted user.   *   * @param recipient The email address or username of the recipient.   * @return An EmailListFeed object containing the email lists.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListFeed retrieveEmailLists(String recipient)      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Retrieving email lists for '" + recipient + "'.");    URL feedUrl = new URL(domainUrlBase + "emailList/"        + SERVICE_VERSION);    AppsForYourDomainQuery query = new AppsForYourDomainQuery(feedUrl);    query.setRecipient(recipient);    return emailListService.query(query, EmailListFeed.class);  }  /**   * Retrieves all email lists in domain.  This method may be very slow for   * domains with a large number of email lists.  Any changes to email lists,   * including creations and deletions, which are made after this method is   * called may or may not be included in the Feed which is returned.   *   * @return A EmailListFeed object of the retrieved email lists.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListFeed retrieveAllEmailLists()      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Retrieving all email lists.");    URL retrieveUrl = new URL(domainUrlBase + "emailList/"        + SERVICE_VERSION + "/");    EmailListFeed allEmailLists = new EmailListFeed();    EmailListFeed currentPage;    Link nextLink;    do {      currentPage = emailListService.getFeed(retrieveUrl, EmailListFeed.class);      allEmailLists.getEntries().addAll(currentPage.getEntries());      nextLink = currentPage.getLink(Link.Rel.NEXT, Link.Type.ATOM);      if (nextLink != null) {        retrieveUrl = new URL(nextLink.getHref());      }    } while (nextLink != null);    return allEmailLists;  }  /**   * Retrieves one page (100) of email lists in domain.  Any changes to   * email lists, including creations and deletions, which are made after   * this method is called may or may not be included in the Feed which is   * returned.  If the optional startEmailListName parameter is specified, one   * page of email lists is returned which have names at or after   * startEmailListName as per ASCII value ordering with case-insensitivity.   * A value of null or empty string indicates you want results from the   * beginning of the list.   *   * @param startEmailListName The starting point of the page (optional).   * @return A EmailListFeed object of the retrieved email lists.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListFeed retrievePageOfEmailLists(String startEmailListName)      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Retrieving one page of email lists"        + (startEmailListName != null 	  ? " starting at " + startEmailListName 	  : "")        + ".");    URL retrieveUrl = new URL(	domainUrlBase + "emailList/" + SERVICE_VERSION + "/");    AppsForYourDomainQuery query = new AppsForYourDomainQuery(retrieveUrl);    query.setStartEmailListName(startEmailListName);    return emailListService.query(query, EmailListFeed.class);  }  /**   * Retrieves an email list.     *   * @param emailList The name of the email list you want to retrieve.   * @return An EmailListEntry object of the retrieved email list.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListEntry retrieveEmailList(String emailList)      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Retrieving email list '" + emailList + "'.");    URL retrieveUrl = new URL(domainUrlBase + "emailList/" 	+ SERVICE_VERSION + "/" +  emailList);    return emailListService.getEntry(retrieveUrl, EmailListEntry.class);  }  /**   * Deletes an email list.   *   * @param emailList The email list you with to delete.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public void deleteEmailList(String emailList)      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Attempting to delete emailList '" + emailList + "'.");    URL deleteUrl = new URL(domainUrlBase + "emailList/" 	+ SERVICE_VERSION + "/" + emailList);    emailListService.delete(deleteUrl);  }  /**   * Retrieves all recipients in an email list.  This method may be very slow   * for email lists with a large number of recipients.  Any changes to the   * email list contents, including adding or deleting recipients which are   * made after this method is called may or may not be included in the Feed   * which is returned.   *   * @return An EmailListRecipientFeed object of the retrieved recipients.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListRecipientFeed retrieveAllRecipients(String emailList)      throws AppsForYourDomainException, ServiceException, IOException {    LOGGER.log(Level.INFO,        "Retrieving all recipients in emailList '" + emailList + "'.");    URL retrieveUrl = new URL(domainUrlBase + "emailList/"        + SERVICE_VERSION + "/" + emailList + "/recipient/");    EmailListRecipientFeed allRecipients = new EmailListRecipientFeed();    EmailListRecipientFeed currentPage;    Link nextLink;    do {      currentPage = emailListRecipientService.getFeed(retrieveUrl,	  EmailListRecipientFeed.class);      allRecipients.getEntries().addAll(currentPage.getEntries());      nextLink = currentPage.getLink(Link.Rel.NEXT, Link.Type.ATOM);      if (nextLink != null) {        retrieveUrl = new URL(nextLink.getHref());      }    } while (nextLink != null);    return allRecipients;  }  /**   * Retrieves one page (100) of recipients in an email list.  Changes to the   * email list recipients including creations and deletions, which are made   * after this method is called may or may not be included in the Feed which is   * returned.  If the optional startRecipient parameter is specified, one   * page of recipients is returned which have email addresses at or after   * startRecipient as per ASCII value ordering with case-insensitivity.   * A value of null or empty string indicates you want results from the   * beginning of the list.   *   * @param emailList The name of the email list for which we are   * retrieving recipients.   * @param startRecipient The starting point of the page (optional).   * @return A EmailListRecipientFeed object of the retrieved recipients.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListRecipientFeed retrievePageOfRecipients(String emailList,      String startRecipient) throws AppsForYourDomainException,      ServiceException, IOException {    LOGGER.log(Level.INFO,        "Retrieving one page of recipients"        + (startRecipient != null          ? " starting at " + startRecipient          : "")        + ".");    URL retrieveUrl = new URL(	domainUrlBase + "emailList/" + SERVICE_VERSION + "/" + emailList	+ "/recipient/");    AppsForYourDomainQuery query = new AppsForYourDomainQuery(retrieveUrl);    query.setStartRecipient(startRecipient);    return emailListRecipientService.query(query, EmailListRecipientFeed.class);  }  /**   * Adds an email address to an email list.   *   * @param recipientAddress The email address you wish to add.   * @param emailList The email list you wish to modify.   * @return The EmailListRecipientEntry of the newly created email list   * recipient.    * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public EmailListRecipientEntry addRecipientToEmailList(      String recipientAddress, String emailList)      throws AppsForYourDomainException, ServiceException, IOException {       LOGGER.log(Level.INFO,        "Adding '" + recipientAddress + "' to emailList '" + emailList + "'.");    EmailListRecipientEntry emailListRecipientEntry	= new EmailListRecipientEntry();    Who who = new Who();    who.setEmail(recipientAddress);    emailListRecipientEntry.addExtension(who);    URL insertUrl = new URL(domainUrlBase + "emailList/"	+ SERVICE_VERSION + "/" + emailList + "/recipient");    return emailListRecipientService.insert(insertUrl, emailListRecipientEntry);  }  /**   * Removes an email address from an email list.   *   * @param recipientAddress The email address you wish to remove.   * @param emailList The email list you wish to modify.   * @throws AppsForYourDomainException If a Provisioning API specific occurs.   * @throws ServiceException If a generic GData framework error occurs.   * @throws IOException If an error occurs communicating with the GData   * service.   */  public void removeRecipientFromEmailList(String recipientAddress,      String emailList) throws AppsForYourDomainException, ServiceException,      IOException {    LOGGER.log(Level.INFO,        "Removing '" + recipientAddress + "' from emailList '" + emailList	    + "'.");    URL deleteUrl = new URL(domainUrlBase + "emailList/"        + SERVICE_VERSION + "/" + emailList + "/recipient/"	+ recipientAddress);    emailListRecipientService.delete(deleteUrl);  }  /*   * Main entry point.  Parses arguments and creates and invokes the   * AppsForYourDomainClient.   *   * Usage: java AppsForYourDomainClient --admin_email [email] --admin_password [pass] --domain [domain]   *    */  public static void main(String[] arg)      throws Exception {    SimpleCommandLineParser parser = new SimpleCommandLineParser(arg);    String adminEmail = parser.getValue("admin_email", "email", "e");    String adminPassword = parser.getValue("admin_password", "pass", "p");    String domain = parser.getValue("domain", "domain", "d");    boolean help = parser.containsKey("help", "h");    if (help || (adminEmail == null) 	|| (adminPassword == null) || (domain == null)) {      usage();      System.exit(1);    }    AppsForYourDomainClient client =        new AppsForYourDomainClient(adminEmail, adminPassword, domain);    client.run();  }  /*   * Prints the command line usage of this sample application.   */  private static void usage() {    System.out.println("Usage: java AppsForYourDomainClient" +        " --admin_email [email] --admin_password [pass] --domain [domain]");    System.out.println(        "\nA simple application that performs user, email list,\n" +        "and nickname related operations on the given domain using.\n" +        "the provided admin username and password.\n");  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -