// 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());