forked from google/gdata-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorksheetEntry.java
More file actions
201 lines (182 loc) · 5.99 KB
/
Copy pathWorksheetEntry.java
File metadata and controls
201 lines (182 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* Copyright (c) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.gdata.data.spreadsheet;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.BaseEntry;
import com.google.gdata.data.Category;
import com.google.gdata.data.ExtensionProfile;
import com.google.gdata.data.Kind;
import com.google.gdata.data.Link;
import com.google.gdata.data.OutOfLineContent;
import com.google.gdata.util.Version;
import java.net.MalformedURLException;
import java.net.URL;
/**
* One worksheet, when listing all worksheets within a spreadsheet.
*
* For instance, this might list Sheet1, Sheet2, Sheet3, etc.
*
*
*/
@Kind.Term(WorksheetEntry.KIND)
public class WorksheetEntry extends BaseEntry<WorksheetEntry> {
/**
* Kind category term used to label the entries that contains worksheet data.
*/
public static final String KIND = Namespaces.gSpreadPrefix + "worksheet";
/**
* Category used to label entries that contain worksheet data.
*/
public static final Category CATEGORY =
new Category(Namespaces.gSpread, KIND);
/**
* Constructs a new uninitialized entry to be populated by the
* GData parsers.
*/
public WorksheetEntry() {
getCategories().add(CATEGORY);
}
/**
* Constructs a new entry with the given row count and column count
* @param rowCount the number of rows in the worksheet
* @param colCount the number of columns in a worksheet
*/
public WorksheetEntry(int rowCount, int colCount) {
getCategories().add(CATEGORY);
addExtension(new RowCount(rowCount));
addExtension(new ColCount(colCount));
}
/**
* Constructs a new entry by doing a shallow copy from another BaseEntry
* instance.
*/
public WorksheetEntry(BaseEntry sourceEntry) {
super(sourceEntry);
getCategories().add(CATEGORY);
}
/**
* Declares any extensions.
*/
public void declareExtensions(ExtensionProfile extProfile) {
extProfile.declare(WorksheetEntry.class, RowCount.getDefaultDescription());
extProfile.declare(WorksheetEntry.class, ColCount.getDefaultDescription());
}
/**
* Gets the URL for this worksheet's list feed.
*
* <p>You can then create a query using this URL to query this worksheet's
* rows, using the very powerful query model.
*
* @return a URL to get a feed of worksheets
*/
public URL getListFeedUrl() {
try {
return new URL(getFeedUrlString(Namespaces.LIST_LINK_REL));
} catch (MalformedURLException e) {
throw new RuntimeException("Error in GData server", e);
}
}
/**
* Gets the URL for this worksheet's cells feed.
*
* <p>With this feed, you can query for arbitrary ranges of cells.
*
* @return a URL to the cells feed
*/
public URL getCellFeedUrl() {
try {
return new URL(getFeedUrlString(Namespaces.CELLS_LINK_REL));
} catch (MalformedURLException e) {
throw new RuntimeException("Error in GData server", e);
}
}
private String getFeedUrlString(String linkRelKind) {
Version spreadsheetVersion = state.service.getProtocolVersion();
if (spreadsheetVersion.isCompatible(SpreadsheetService.Versions.V1)) {
Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM);
return feedLink.getHref();
} else { // must be SpreadsheetService.Versions.V2; only 2 versions for now
// List or Cells feed Url?
if (linkRelKind.equals(Namespaces.LIST_LINK_REL)) {
// the list feed is stored as a <content> tag
return ((OutOfLineContent)(this.getContent())).getUri();
} else { // it must be Namespaces.CELLS_LINK_REL
// the cells feed is stored in the <link> tag
Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM);
return feedLink.getHref();
}
}
}
/**
* Gets the total number of rows.
*
* This refers to the hard bound on rows. It is possible that your
* spreadsheet has many, many empty rows, all of which are counted in
* this count.
*
* Column positions 1 to getRowCount() are valid.
*/
public int getRowCount() {
RowCount count = getExtension(RowCount.class);
if (count != null) {
return count.getCount();
} else {
return 0;
}
}
/**
* Sets the total number of rows.
*
* If the new number of rows is greater than the old, (new-old)
* blank rows will be appended to the end. If the new number of
* rows is less than the old, then (old-new) rows will be removed
* from the end which will DELETE ALL DATE IN DELETED ROWS.
*
* @param count the new row count.
*/
public void setRowCount(int count) {
setExtension(new RowCount(count));
}
/**
* Gets the total number of columns.
*
* This refers to the hard bound on columns. It is possible that your
* spreadsheet has many empty columns, all of which are counted in
* this count.
*
* Column positions 1 to getColCount() are valid.
*/
public int getColCount() {
ColCount count = getExtension(ColCount.class);
if (count != null) {
return count.getCount();
} else {
return 0;
}
}
/**
* Sets the total number of columns.
*
* If the new number of columns is greater than the old, (new-old)
* blank columns will be appended to the end. If the new number of
* columns is less than the old, then (old-new) columns will be removed
* from the end which will DELETE ALL DATE IN DELETED COLUMNS.
*
* @param count the new column count.
*/
public void setColCount(int count) {
setExtension(new ColCount(count));
}
}