Package com.google.gdata.data.spreadsheet

Examples of com.google.gdata.data.spreadsheet.CellFeed


        List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
        WorksheetEntry worksheet = worksheets.get(0);
        // fetch A1 only
        URL cellFeedUrl = new URI(worksheet.getCellFeedUrl().toString() + "?min-row=1&max-row=1&min-col=1&max-col=1")
            .toURL();
        CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
        // Iterate through each cell, printing its value.
        String onSupport = cellFeed.getEntries().get(0).getCell().getValue();
        return onSupport;
    }
View Full Code Here


 
  public GSpreadResultSet retrieveData() throws Exception {
    URL worksheetUrl = new URL(this.getConfig().generateWorksheetFeedURL());
    WorksheetFeed feedw = this.getConfig().getFeed(worksheetUrl, WorksheetFeed.class);
    WorksheetEntry worksheetEntry = feedw.getEntries().get(this.getWorksheetNumber() - 1);     
    CellFeed feedc = this.getConfig().getFeed(worksheetEntry.getCellFeedUrl(), CellFeed.class);     
    List<CellEntry> entries = feedc.getEntries();     
    GSpreadResultSet grs = new GSpreadResultSet();
   
    /* store the data */
    for (CellEntry entry : entries) {
      grs.addCell(this.getPosStringFromId(entry.getId()),
View Full Code Here

      // this is a workaround for this
      // http://code.google.com/p/gdata-java-client/issues/detail?id=103
      spreadsheetService.setProtocolVersion(SpreadsheetService.Versions.V1);
      URL cellFeedUrl = wsEntry.getCellFeedUrl();
      CellFeed cellFeed = spreadsheetService.getFeed(cellFeedUrl, CellFeed.class);
      // Build list of cell addresses to be filled in
      List<BatchCell> batchCells = new ArrayList<BatchCell>();
      Locale fr = new Locale("fr");
      if (type.equals(ChartTypes.DAY)) {
        Calendar calendar = Calendar.getInstance();
        Calendar nextYear = Calendar.getInstance();
        calendar.set(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_YEAR, 1);
        nextYear.set(Calendar.MONTH, 1);
        nextYear.set(Calendar.DAY_OF_YEAR, 1);
        nextYear.add(Calendar.YEAR, 1);
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM");
        int i = 1;
        while (calendar.before(nextYear)) {
          batchCells.add(new BatchCell(i, 1, dateFormat.format(calendar.getTime())));
          calendar.add(Calendar.DAY_OF_YEAR, 1);
          i++;
        }
      } else if (type.equals(ChartTypes.MONTH)) {
        DateFormatSymbols dfs = new DateFormatSymbols(fr);
        String[] months = dfs.getShortMonths();
        for (int i = 1; i < months.length; i++) {
          batchCells.add(new BatchCell(i, 1, months[i - 1]));
        }
      } else if (type.equals(ChartTypes.YEAR)) {
        for (int i = 1; i < 11; i++) {
          batchCells.add(new BatchCell(i, 1, String.valueOf(i + 2010)));
        }
      }
      // Prepare the update
      // getCellEntryMap is what makes the update fast.
      Map<String, CellEntry> cellEntries = getCellEntryMap(cellFeedUrl, batchCells);

      CellFeed batchRequest = new CellFeed();
      for (BatchCell batchCell : batchCells) {
        CellEntry batchEntry = new CellEntry(cellEntries.get(batchCell.idString));
        batchEntry.changeInputValueLocal(batchCell.value);
        BatchUtils.setBatchId(batchEntry, batchCell.idString);
        BatchUtils.setBatchOperationType(batchEntry, BatchOperationType.UPDATE);
        batchRequest.getEntries().add(batchEntry);
      }

      // Submit the update
      Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
      URL batchURL = new URL(batchLink.getHref());
      CellFeed batchResponse = spreadsheetService.batch(batchURL, batchRequest);

      // Ensure that all the operations were successful.
      boolean isSuccess = true;
      for (CellEntry entry : batchResponse.getEntries()) {
        String batchId = BatchUtils.getBatchId(entry);
        if (!BatchUtils.isSuccess(entry)) {
          isSuccess = false;
          BatchStatus status = BatchUtils.getBatchStatus(entry);
          log.warning("\n" + batchId + " failed (" + status.getReason() + ") " + status.getContent());
View Full Code Here

   * @return a map consisting of one {@link CellEntry} for each address in
   *         {@code cellAddrs}
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public Map getCellEntryMap(URL cellFeedUrl, List<BatchCell> cellAddrs) throws IOException, ServiceException {
    CellFeed batchRequest = new CellFeed();
    for (BatchCell cellId : cellAddrs) {
      CellEntry batchEntry = new CellEntry(cellId.row, cellId.col, cellId.idString);
      batchEntry.setId(String.format("%s/%s", cellFeedUrl.toString(), cellId.idString));
      BatchUtils.setBatchId(batchEntry, cellId.idString);
      BatchUtils.setBatchOperationType(batchEntry, BatchOperationType.QUERY);
      batchRequest.getEntries().add(batchEntry);
    }

    CellFeed cellFeed = spreadsheetService.getFeed(cellFeedUrl, CellFeed.class);
    Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
    URL batchURL = new URL(batchLink.getHref());
    CellFeed queryBatchResponse = spreadsheetService.batch(batchURL, batchRequest);

    Map cellEntryMap = new HashMap(cellAddrs.size());
    for (CellEntry entry : queryBatchResponse.getEntries()) {
      cellEntryMap.put(BatchUtils.getBatchId(entry), entry);
    }

    return cellEntryMap;
  }
View Full Code Here

            cellQuery.setMaximumRow(maxRow);
            cellQuery.setMaximumCol(cols);
            cellQuery.setMaxResults(rows * cols);
            cellQuery.setReturnEmpty(false);
           
            CellFeed cellFeed = service.query(cellQuery, CellFeed.class);
            List<CellEntry> cellEntries = cellFeed.getEntries();
           
            List<List<Object>> rowsOfCells = new ArrayList<List<Object>>(rowCount);
            for (CellEntry cellEntry : cellEntries) {
                Cell cell = cellEntry.getCell();
                if (cell != null) {
View Full Code Here

            new CellEntry[worksheetEntry.getRowCount()][worksheetEntry.getColCount()];
        {
            CellQuery cellQuery = new CellQuery(cellFeedUrl);
            cellQuery.setReturnEmpty(true);
           
            CellFeed fetchingCellFeed = service.getFeed(cellQuery, CellFeed.class);
            for (CellEntry cellEntry : fetchingCellFeed.getEntries()) {
              Cell cell = cellEntry.getCell();
              cellEntries[cell.getRow() - 1][cell.getCol() - 1] = cellEntry;
            }
        }
       
        TabularSerializer serializer = new TabularSerializer() {
            CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
            CellFeed batchRequest = null;
            int row = 0;
           
            @Override
            public void startFile(JSONObject options) {
            }
           
            @Override
            public void endFile() {
                if (batchRequest != null) {
                    sendBatch();
                }
            }
           
            private void sendBatch() {
                try {
                    Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
                    CellFeed batchResponse = service.batch(new URL(batchLink.getHref()), batchRequest);
                   
                    for (CellEntry entry : batchResponse.getEntries()) {
                      String batchId = BatchUtils.getBatchId(entry);
                      if (!BatchUtils.isSuccess(entry)) {
                        BatchStatus status = BatchUtils.getBatchStatus(entry);
                        logger.warn(
                            String.format(
                                "Error: %s failed (%s) %s\n",
                                batchId, status.getReason(), status.getContent()));
                        break;
                      }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                batchRequest = null;
            }
           
            @Override
            public void addRow(List<CellData> cells, boolean isHeader) {
                if (batchRequest == null) {
                    batchRequest = new CellFeed();
                }
                for (int c = 0; c < cells.size(); c++) {
                    CellData cellData = cells.get(c);
                    if (cellData != null && cellData.text != null) {
                        String cellId = String.format("R%sC%s", row + 1, c + 1);
View Full Code Here

    CellQuery query = new CellQuery(cellFeedUrl);

    // Title & Type
    query.setMinimumRow(1);
    query.setMaximumRow(2);
    CellFeed feed = ss.query(query, CellFeed.class);
    for (CellEntry cell : feed.getEntries()) {
      final String shortId = cell.getId().substring(cell.getId().lastIndexOf('/') + 1);
      logger.fine(shortId + ":" + cell.getCell().getValue());
      int row = Integer.parseInt(shortId.substring(1, shortId.lastIndexOf('C')));
      int col = Integer.parseInt(shortId.substring(shortId.lastIndexOf('C') + 1));
      if (row == 1) {
        columnTitle[col - 1] = cell.getCell().getValue();
      } else {
        dataType[col - 1] = cell.getCell().getValue();
      }
    }

    // Data (start from line no.3)
    query.setMinimumRow(startIndex);
    final int nextMax = startIndex + maxRows - 1;
    final int maxRowCount = workSheet.getRowCount();
    final int maxRow = (nextMax > maxRowCount) ? maxRowCount : nextMax;
    logger.fine(startIndex + "〜" + maxRow);
    if (startIndex >= maxRow) {
      return null;
    }
    query.setMaximumRow(maxRow);
    feed = ss.query(query, CellFeed.class);
    GbEntity gbEntity = null;
    List<GbEntity> data = new ArrayList<GbEntity>();
    for (CellEntry cell : feed.getEntries()) {
      final String shortId = cell.getId().substring(cell.getId().lastIndexOf('/') + 1);
      int col = Integer.parseInt(shortId.substring(shortId.lastIndexOf('C') + 1));
      if (col == 1) {
        gbEntity = new GbEntity();
        gbEntity.setKeyString(cell.getCell().getValue());
View Full Code Here

    throws EPAuthenticationException {
    List<CellEntry> returnList = null;

    try {
      SpreadsheetService ssService = getSsService();
      CellFeed cellFeed = ssService.getFeed(
          new URL(cellFeedUrl + "?min-row=1&max-row=1"),
          CellFeed.class);
      returnList = cellFeed.getEntries();
    } catch (com.google.gdata.util.AuthenticationException authEx) {
      throw new
      EPAuthenticationException(
          "SS read access not available");
    } catch (com.google.gdata.util.ServiceException svcex) {
View Full Code Here

     * Load all the cells from Google Spreadsheets.
     */
    public synchronized void refresh() {
      cells.clear();

      CellFeed cellFeed = getCellFeed();

      if (cellFeed != null) {
        for (CellEntry entry : cellFeed.getEntries()) {
          doAddCell(entry);
        }
      }

      int oldMaxRow = maxRow;
      int oldMaxCol = maxCol;

      maxRow = cellFeed.getRowCount();
      maxCol = cellFeed.getColCount();

      fireTableDataChanged();

      if (maxRow != oldMaxRow || maxCol != oldMaxCol) {
        fireTableStructureChanged();
View Full Code Here

    // send the updates in chunks of 1000 to ensure we don't send too much
    // data in one batch
    List<List<CellEntry>> batches = chunkList(updatedCells, 1000);
    for (List<CellEntry> batch : batches) {
      CellFeed batchFeed = new CellFeed();
      for (CellEntry cellEntry : batch) {
        Cell cell = cellEntry.getCell();
        BatchUtils.setBatchId(cellEntry, "R" + cell.getRow() + "C" + cell.getCol());
        BatchUtils.setBatchOperationType(cellEntry, BatchOperationType.UPDATE);
        batchFeed.getEntries().add(cellEntry);
      }

      Link batchLink = worksheet.getBatchUpdateLink();
      CellFeed batchResultFeed = spreadsheetService.batch(new URL(batchLink.getHref()), batchFeed);
      // Make sure all the operations were successful.
      for (CellEntry entry : batchResultFeed.getEntries()) {
        if (!BatchUtils.isSuccess(entry)) {
          String batchId = BatchUtils.getBatchId(entry);
          BatchStatus status = BatchUtils.getBatchStatus(entry);
          System.err.println("Failed entry");
          System.err.println("\t" + batchId + " failed (" + status.getReason() + ") ");
View Full Code Here

TOP

Related Classes of com.google.gdata.data.spreadsheet.CellFeed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.