public static void parse(
      String token,
      Project project,
      ProjectMetadata metadata,
      final ImportingJob job,
      int limit,
      JSONObject options,
      List<Exception> exceptions) {

    String docType = JSONUtilities.getString(options, "docType", null);
    if ("spreadsheet".equals(docType)) {
      SpreadsheetService service = GDataExtension.getSpreadsheetService(token);
      parse(service, project, metadata, job, limit, options, exceptions);
    } else if ("table".equals(docType)) {
      GoogleService service = GDataExtension.getFusionTablesGoogleService(token);
      parse(service, project, metadata, job, limit, options, exceptions);
    }
  }
    private List<List<Object>> getRowsOfCells(int startRow) throws IOException, ServiceException {
      List<List<Object>> rowsOfCells = new ArrayList<List<Object>>(batchSize);

      String query = baseQuery + " OFFSET " + startRow + " LIMIT " + batchSize;

      List<List<String>> rows = GDataExtension.runFusionTablesSelect(service, query);
      if (rows.size() > 1) {
        for (int i = 1; i < rows.size(); i++) {
          List<String> row = rows.get(i);
          List<Object> rowOfCells = new ArrayList<Object>(row.size());
          for (int j = 0; j < row.size() && j < columns.size(); j++) {
            String text = row.get(j);
            if (text.isEmpty()) {
              rowOfCells.add(null);
            } else {
              FTColumnData cd = columns.get(j);
              if (cd.type == FTColumnType.NUMBER) {
                try {
                  rowOfCells.add(Long.parseLong(text));
                  continue;
                } catch (NumberFormatException e) {
                  // ignore
                }
                try {
                  double d = Double.parseDouble(text);
                  if (!Double.isInfinite(d) && !Double.isNaN(d)) {
                    rowOfCells.add(d);
                    continue;
                  }
                } catch (NumberFormatException e) {
                  // ignore
                }
              }

              rowOfCells.add(text);
            }
          }
          rowsOfCells.add(rowOfCells);
        }
      }
      end = rows.size() < batchSize + 1;
      return rowsOfCells;
    }
  public static void parse(
      GoogleService service,
      Project project,
      ProjectMetadata metadata,
      final ImportingJob job,
      int limit,
      JSONObject options,
      List<Exception> exceptions) {

    String docUrlString = JSONUtilities.getString(options, "docUrl", null);
    String id = getFTid(docUrlString); // Use GDataExtension.getFusionTableKey(url) ?
    // TODO: Allow arbitrary Fusion Tables URL instead of (in addition to?) constructing our own?

    try {
      List<FTColumnData> columns = new ArrayList<GDataImporter.FTColumnData>();
      List<List<String>> rows = GDataExtension.runFusionTablesSelect(service, "DESCRIBE " + id);
      if (rows.size() > 1) {
        for (int i = 1; i < rows.size(); i++) {
          List<String> row = rows.get(i);
          if (row.size() >= 2) {
            FTColumnData cd = new FTColumnData();
            cd.name = row.get(1);
            cd.type = FTColumnType.STRING;

            if (row.size() > 2) {
              String type = row.get(2).toLowerCase();
              if (type.equals("number")) {
                cd.type = FTColumnType.NUMBER;
              } else if (type.equals("datetime")) {
                cd.type = FTColumnType.DATETIME;
              } else if (type.equals("location")) {
                cd.type = FTColumnType.LOCATION;
              }
            }
            columns.add(cd);
          }
        }

        setProgress(job, docUrlString, -1);

        // Force these options for the next call because each fusion table
        // is strictly structured with a single line of headers.
        JSONUtilities.safePut(
            options, "ignoreLines", 0); // number of blank lines at the beginning to ignore
        JSONUtilities.safePut(options, "headerLines", 1); // number of header lines

        TabularImportingParserBase.readTable(
            project,
            metadata,
            job,
            new FusionTableBatchRowReader(job, docUrlString, service, id, columns, 100),
            docUrlString,
            limit,
            options,
            exceptions);
        setProgress(job, docUrlString, 100);
      }
    } catch (IOException e) {
      e.printStackTrace();
      exceptions.add(e);
    } catch (ServiceException e) {
      e.printStackTrace();
      exceptions.add(e);
    }
  }