/**
   * Select a single page and save the result in the specified directory
   *
   * @param FileName
   * @param format
   * @param pageNumber
   * @param downloadDirectory
   * @return String the first file attachment name
   * @throws RemoteException
   */
  public String selectJavaReportPage(
      String FileName, String format, int pageNumber, String downloadDirectory)
      throws RemoteException {
    // Set file name to view
    com.actuate.schemas.ObjectIdentifier objectIdentifier =
        new com.actuate.schemas.ObjectIdentifier();
    objectIdentifier.setName(FileName);

    // Set the pages to view
    com.actuate.schemas.PageIdentifier pageIdentifier = new com.actuate.schemas.PageIdentifier();
    pageIdentifier.setPageNum(new Long(pageNumber));

    // Set the select page request
    com.actuate.schemas.SelectJavaReportPage selectJavaReportPage =
        new com.actuate.schemas.SelectJavaReportPage();
    selectJavaReportPage.setObject(objectIdentifier);
    // selectJavaReportPage.setViewParameter(viewParameter);
    selectJavaReportPage.setPage(pageIdentifier);
    selectJavaReportPage.setDownloadEmbedded(new Boolean(true));

    // SelectPage
    com.actuate.schemas.SelectJavaReportPageResponse selectJavaReportPageResponse =
        proxy.selectJavaReportPage(selectJavaReportPage);

    // Save the result in download directory
    new File(downloadDirectory).mkdir();

    String firstAttachmentName =
        saveAttachment(selectJavaReportPageResponse.getPageRef(), downloadDirectory);

    return firstAttachmentName;
  }
  /**
   * Select a single page and save the result in the specified directory
   *
   * @param FileName
   * @param format
   * @param pageNumber
   * @param downloadDirectory
   * @return String the first file attachment name
   * @throws RemoteException
   */
  public String selectPage(String FileName, String format, int pageNumber, String downloadDirectory)
      throws RemoteException {
    // Set view parameter
    com.actuate.schemas.ViewParameter viewParameter = new com.actuate.schemas.ViewParameter();
    viewParameter.setFormat(format);
    viewParameter.setUserAgent(
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; .NET CLR 1.0.3705)");

    // Set file name to view
    com.actuate.schemas.ObjectIdentifier objectIdentifier =
        new com.actuate.schemas.ObjectIdentifier();
    objectIdentifier.setName(FileName);

    // Set the pages to view
    com.actuate.schemas.PageIdentifier pageIdentifier = new com.actuate.schemas.PageIdentifier();
    pageIdentifier.setPageNum(new Long(pageNumber));

    // Set the select page request
    com.actuate.schemas.SelectPage selectPage = new com.actuate.schemas.SelectPage();
    selectPage.setObject(objectIdentifier);
    selectPage.setViewParameter(viewParameter);
    selectPage.setPage(pageIdentifier);
    selectPage.setDownloadEmbedded(new Boolean(true));

    // Set FileType
    actuateAPI.setFileType(FileName.split("\\.")[1]);

    // SelectPage
    com.actuate.schemas.SelectPageResponse selectPageResponse = proxy.selectPage(selectPage);

    // Save the result in download directory
    new File(downloadDirectory).mkdir();

    String firstAttachmentName = saveAttachment(selectPageResponse.getPageRef(), downloadDirectory);
    saveAttachment(selectPageResponse.getPostResponseRef(), downloadDirectory);

    return firstAttachmentName;
  }