Skip to content

Commit 95188fa

Browse files
author
Cody Ebberson
committed
Adding support for JDK 1.6
Per customer request, adding backwards support for Java 1.6. There should be zero functional changes. Fixes #62 - correctly parsing user phone field
1 parent 64ff732 commit 95188fa

23 files changed

+393
-467
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'java'
44
apply plugin: 'maven'
55
apply plugin: 'signing'
66

7-
sourceCompatibility = 1.7
7+
sourceCompatibility = 1.6
88

99
group = 'com.box'
1010
archivesBaseName = 'box-java-sdk'

src/main/java/com/box/sdk/BoxAPIRequest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.net.MalformedURLException;
99
import java.net.ProtocolException;
1010
import java.net.URL;
11-
import java.nio.charset.StandardCharsets;
1211
import java.util.ArrayList;
1312
import java.util.List;
1413
import java.util.Map;
@@ -205,13 +204,14 @@ public BoxAPIResponse send(ProgressListener listener) {
205204
*/
206205
@Override
207206
public String toString() {
207+
String lineSeparator = System.getProperty("line.separator");
208208
StringBuilder builder = new StringBuilder();
209209
builder.append("Request");
210-
builder.append(System.lineSeparator());
210+
builder.append(lineSeparator);
211211
builder.append(this.method);
212212
builder.append(' ');
213213
builder.append(this.url.toString());
214-
builder.append(System.lineSeparator());
214+
builder.append(lineSeparator);
215215

216216
for (Map.Entry<String, List<String>> entry : this.requestProperties.entrySet()) {
217217
List<String> nonEmptyValues = new ArrayList<String>();
@@ -233,12 +233,12 @@ public String toString() {
233233
}
234234

235235
builder.delete(builder.length() - 2, builder.length());
236-
builder.append(System.lineSeparator());
236+
builder.append(lineSeparator);
237237
}
238238

239239
String bodyString = this.bodyToString();
240240
if (bodyString != null) {
241-
builder.append(System.lineSeparator());
241+
builder.append(lineSeparator);
242242
builder.append(bodyString);
243243
}
244244

@@ -321,7 +321,7 @@ private BoxAPIResponse trySend(ProgressListener listener) {
321321
HttpURLConnection connection = this.createConnection();
322322

323323
if (this.bodyLength > 0) {
324-
connection.setFixedLengthStreamingMode(this.bodyLength);
324+
connection.setFixedLengthStreamingMode((int) this.bodyLength);
325325
connection.setDoOutput(true);
326326
}
327327

src/main/java/com/box/sdk/BoxAPIResponse.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.io.InputStream;
55
import java.io.InputStreamReader;
66
import java.net.HttpURLConnection;
7-
import java.nio.charset.StandardCharsets;
87
import java.util.ArrayList;
98
import java.util.List;
109
import java.util.Map;
@@ -87,7 +86,7 @@ public int getResponseCode() {
8786
* @return the length of the response's body.
8887
*/
8988
public long getContentLength() {
90-
return this.connection.getContentLengthLong();
89+
return this.connection.getContentLength();
9190
}
9291

9392
/**
@@ -160,16 +159,17 @@ public void disconnect() {
160159

161160
@Override
162161
public String toString() {
162+
String lineSeparator = System.getProperty("line.separator");
163163
Map<String, List<String>> headers = this.connection.getHeaderFields();
164164
StringBuilder builder = new StringBuilder();
165165
builder.append("Response");
166-
builder.append(System.lineSeparator());
166+
builder.append(lineSeparator);
167167
builder.append(this.connection.getRequestMethod());
168168
builder.append(' ');
169169
builder.append(this.connection.getURL().toString());
170-
builder.append(System.lineSeparator());
170+
builder.append(lineSeparator);
171171
builder.append(headers.get(null).get(0));
172-
builder.append(System.lineSeparator());
172+
builder.append(lineSeparator);
173173

174174
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
175175
String key = entry.getKey();
@@ -196,12 +196,12 @@ public String toString() {
196196
}
197197

198198
builder.delete(builder.length() - 2, builder.length());
199-
builder.append(System.lineSeparator());
199+
builder.append(lineSeparator);
200200
}
201201

202202
String bodyString = this.bodyToString();
203203
if (bodyString != null && bodyString != "") {
204-
builder.append(System.lineSeparator());
204+
builder.append(lineSeparator);
205205
builder.append(bodyString);
206206
}
207207

src/main/java/com/box/sdk/BoxCollaboration.java

Lines changed: 67 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -233,59 +233,55 @@ protected void parseJSONMember(JsonObject.Member member) {
233233
String memberName = member.getName();
234234
JsonValue value = member.getValue();
235235
try {
236-
switch (memberName) {
237-
case "created_by":
238-
JsonObject userJSON = value.asObject();
239-
if (this.createdBy == null) {
240-
String userID = userJSON.get("id").asString();
241-
BoxUser user = new BoxUser(getAPI(), userID);
242-
this.createdBy = user.new Info(userJSON);
243-
} else {
244-
this.createdBy.update(userJSON);
245-
}
246-
break;
247-
case "created_at":
248-
this.createdAt = BoxDateFormat.parse(value.asString());
249-
break;
250-
case "modified_at":
251-
this.modifiedAt = BoxDateFormat.parse(value.asString());
252-
break;
253-
case "expires_at":
254-
this.expiresAt = BoxDateFormat.parse(value.asString());
255-
break;
256-
case "status":
257-
String statusString = value.asString().toUpperCase();
258-
this.status = Status.valueOf(statusString);
259-
break;
260-
case "accessible_by":
261-
userJSON = value.asObject();
262-
if (this.accessibleBy == null) {
263-
String userID = userJSON.get("id").asString();
264-
BoxUser user = new BoxUser(getAPI(), userID);
265-
BoxUser.Info userInfo = user.new Info(userJSON);
266-
this.accessibleBy = userInfo;
267-
} else {
268-
this.accessibleBy.update(userJSON);
269-
}
270-
break;
271-
case "role":
272-
this.role = Role.fromJSONString(value.asString());
273-
break;
274-
case "acknowledged_at":
275-
this.acknowledgedAt = BoxDateFormat.parse(value.asString());
276-
break;
277-
case "item":
278-
JsonObject folderJSON = value.asObject();
279-
if (this.item == null) {
280-
String folderID = folderJSON.get("id").asString();
281-
BoxFolder folder = new BoxFolder(getAPI(), folderID);
282-
this.item = folder.new Info(folderJSON);
283-
} else {
284-
this.item.update(folderJSON);
285-
}
286-
break;
287-
default:
288-
break;
236+
if (memberName.equals("created_by")) {
237+
JsonObject userJSON = value.asObject();
238+
if (this.createdBy == null) {
239+
String userID = userJSON.get("id").asString();
240+
BoxUser user = new BoxUser(getAPI(), userID);
241+
this.createdBy = user.new Info(userJSON);
242+
} else {
243+
this.createdBy.update(userJSON);
244+
}
245+
246+
} else if (memberName.equals("created_at")) {
247+
this.createdAt = BoxDateFormat.parse(value.asString());
248+
249+
} else if (memberName.equals("modified_at")) {
250+
this.modifiedAt = BoxDateFormat.parse(value.asString());
251+
252+
} else if (memberName.equals("expires_at")) {
253+
this.expiresAt = BoxDateFormat.parse(value.asString());
254+
255+
} else if (memberName.equals("status")) {
256+
String statusString = value.asString().toUpperCase();
257+
this.status = Status.valueOf(statusString);
258+
259+
} else if (memberName.equals("accessible_by")) {
260+
JsonObject userJSON = value.asObject();
261+
if (this.accessibleBy == null) {
262+
String userID = userJSON.get("id").asString();
263+
BoxUser user = new BoxUser(getAPI(), userID);
264+
BoxUser.Info userInfo = user.new Info(userJSON);
265+
this.accessibleBy = userInfo;
266+
} else {
267+
this.accessibleBy.update(userJSON);
268+
}
269+
270+
} else if (memberName.equals("role")) {
271+
this.role = Role.fromJSONString(value.asString());
272+
273+
} else if (memberName.equals("acknowledged_at")) {
274+
this.acknowledgedAt = BoxDateFormat.parse(value.asString());
275+
276+
} else if (memberName.equals("item")) {
277+
JsonObject folderJSON = value.asObject();
278+
if (this.item == null) {
279+
String folderID = folderJSON.get("id").asString();
280+
BoxFolder folder = new BoxFolder(getAPI(), folderID);
281+
this.item = folder.new Info(folderJSON);
282+
} else {
283+
this.item.update(folderJSON);
284+
}
289285
}
290286
} catch (ParseException e) {
291287
assert false : "A ParseException indicates a bug in the SDK.";
@@ -384,25 +380,24 @@ private Role(String jsonValue) {
384380
}
385381

386382
static Role fromJSONString(String jsonValue) {
387-
switch (jsonValue) {
388-
case "editor":
389-
return EDITOR;
390-
case "viewer":
391-
return VIEWER;
392-
case "previewer":
393-
return PREVIEWER;
394-
case "uploader":
395-
return UPLOADER;
396-
case "previewer uploader":
397-
return PREVIEWER_UPLOADER;
398-
case "viewer uploader":
399-
return VIEWER_UPLOADER;
400-
case "co-owner":
401-
return CO_OWNER;
402-
case "owner":
403-
return OWNER;
404-
default:
405-
throw new IllegalArgumentException("The provided JSON value isn't a valid Role.");
383+
if (jsonValue.equals("editor")) {
384+
return EDITOR;
385+
} else if (jsonValue.equals("viewer")) {
386+
return VIEWER;
387+
} else if (jsonValue.equals("previewer")) {
388+
return PREVIEWER;
389+
} else if (jsonValue.equals("uploader")) {
390+
return UPLOADER;
391+
} else if (jsonValue.equals("previewer uploader")) {
392+
return PREVIEWER_UPLOADER;
393+
} else if (jsonValue.equals("viewer uploader")) {
394+
return VIEWER_UPLOADER;
395+
} else if (jsonValue.equals("co-owner")) {
396+
return CO_OWNER;
397+
} else if (jsonValue.equals("owner")) {
398+
return OWNER;
399+
} else {
400+
throw new IllegalArgumentException("The provided JSON value isn't a valid Role.");
406401
}
407402
}
408403

src/main/java/com/box/sdk/BoxCollaborator.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,13 @@ protected void parseJSONMember(JsonObject.Member member) {
9090

9191
try {
9292
JsonValue value = member.getValue();
93-
switch (member.getName()) {
94-
case "name":
95-
this.name = value.asString();
96-
break;
97-
case "created_at":
98-
this.createdAt = BoxDateFormat.parse(value.asString());
99-
break;
100-
case "modified_at":
101-
this.modifiedAt = BoxDateFormat.parse(value.asString());
102-
break;
103-
default:
104-
break;
93+
String name = member.getName();
94+
if (name.equals("name")) {
95+
this.name = value.asString();
96+
} else if (name.equals("created_at")) {
97+
this.createdAt = BoxDateFormat.parse(value.asString());
98+
} else if (name.equals("modified_at")) {
99+
this.modifiedAt = BoxDateFormat.parse(value.asString());
105100
}
106101
} catch (ParseException e) {
107102
assert false : "A ParseException indicates a bug in the SDK.";

src/main/java/com/box/sdk/BoxComment.java

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -225,44 +225,40 @@ protected void parseJSONMember(JsonObject.Member member) {
225225
try {
226226
String memberName = member.getName();
227227
JsonValue value = member.getValue();
228-
switch (memberName) {
229-
case "is_reply_comment":
230-
this.isReplyComment = value.asBoolean();
231-
break;
232-
case "message":
233-
this.message = value.asString();
234-
break;
235-
case "tagged_message":
236-
this.taggedMessage = value.asString();
237-
break;
238-
case "created_by":
239-
JsonObject userJSON = value.asObject();
240-
if (this.createdBy == null) {
241-
String userID = userJSON.get("id").asString();
242-
BoxUser user = new BoxUser(getAPI(), userID);
243-
this.createdBy = user.new Info(userJSON);
244-
} else {
245-
this.createdBy.update(userJSON);
246-
}
247-
break;
248-
case "created_at":
249-
this.createdAt = BoxDateFormat.parse(value.asString());
250-
break;
251-
case "item":
252-
this.parseItem(value);
253-
break;
254-
case "modified_by":
255-
userJSON = value.asObject();
256-
if (this.modifiedBy == null) {
257-
String userID = userJSON.get("id").asString();
258-
BoxUser user = new BoxUser(getAPI(), userID);
259-
this.modifiedBy = user.new Info(userJSON);
260-
} else {
261-
this.modifiedBy.update(userJSON);
262-
}
263-
break;
264-
default:
265-
break;
228+
if (memberName.equals("is_reply_comment")) {
229+
this.isReplyComment = value.asBoolean();
230+
231+
} else if (memberName.equals("message")) {
232+
this.message = value.asString();
233+
234+
} else if (memberName.equals("tagged_message")) {
235+
this.taggedMessage = value.asString();
236+
237+
} else if (memberName.equals("created_by")) {
238+
JsonObject userJSON = value.asObject();
239+
if (this.createdBy == null) {
240+
String userID = userJSON.get("id").asString();
241+
BoxUser user = new BoxUser(getAPI(), userID);
242+
this.createdBy = user.new Info(userJSON);
243+
} else {
244+
this.createdBy.update(userJSON);
245+
}
246+
247+
} else if (memberName.equals("created_at")) {
248+
this.createdAt = BoxDateFormat.parse(value.asString());
249+
250+
} else if (memberName.equals("item")) {
251+
this.parseItem(value);
252+
253+
} else if (memberName.equals("modified_by")) {
254+
JsonObject userJSON = value.asObject();
255+
if (this.modifiedBy == null) {
256+
String userID = userJSON.get("id").asString();
257+
BoxUser user = new BoxUser(getAPI(), userID);
258+
this.modifiedBy = user.new Info(userJSON);
259+
} else {
260+
this.modifiedBy.update(userJSON);
261+
}
266262
}
267263
} catch (ParseException e) {
268264
assert false : "A ParseException indicates a bug in the SDK.";

0 commit comments

Comments
 (0)