in Android/app/src/main/java/com/example/samplestickerapp/ContentFileParser.java [66:148]
private static StickerPack readStickerPack(@NonNull JsonReader reader) throws IOException, IllegalStateException {
reader.beginObject();
String identifier = null;
String name = null;
String publisher = null;
String trayImageFile = null;
String publisherEmail = null;
String publisherWebsite = null;
String privacyPolicyWebsite = null;
String licenseAgreementWebsite = null;
String imageDataVersion = "";
boolean avoidCache = false;
boolean animatedStickerPack = false;
List<Sticker> stickerList = null;
while (reader.hasNext()) {
String key = reader.nextName();
switch (key) {
case "identifier":
identifier = reader.nextString();
break;
case "name":
name = reader.nextString();
break;
case "publisher":
publisher = reader.nextString();
break;
case "tray_image_file":
trayImageFile = reader.nextString();
break;
case "publisher_email":
publisherEmail = reader.nextString();
break;
case "publisher_website":
publisherWebsite = reader.nextString();
break;
case "privacy_policy_website":
privacyPolicyWebsite = reader.nextString();
break;
case "license_agreement_website":
licenseAgreementWebsite = reader.nextString();
break;
case "stickers":
stickerList = readStickers(reader);
break;
case "image_data_version":
imageDataVersion = reader.nextString();
break;
case "avoid_cache":
avoidCache = reader.nextBoolean();
break;
case "animated_sticker_pack":
animatedStickerPack = reader.nextBoolean();
break;
default:
reader.skipValue();
}
}
if (TextUtils.isEmpty(identifier)) {
throw new IllegalStateException("identifier cannot be empty");
}
if (TextUtils.isEmpty(name)) {
throw new IllegalStateException("name cannot be empty");
}
if (TextUtils.isEmpty(publisher)) {
throw new IllegalStateException("publisher cannot be empty");
}
if (TextUtils.isEmpty(trayImageFile)) {
throw new IllegalStateException("tray_image_file cannot be empty");
}
if (stickerList == null || stickerList.size() == 0) {
throw new IllegalStateException("sticker list is empty");
}
if (identifier.contains("..") || identifier.contains("/")) {
throw new IllegalStateException("identifier should not contain .. or / to prevent directory traversal");
}
if (TextUtils.isEmpty(imageDataVersion)) {
throw new IllegalStateException("image_data_version should not be empty");
}
reader.endObject();
final StickerPack stickerPack = new StickerPack(identifier, name, publisher, trayImageFile, publisherEmail, publisherWebsite, privacyPolicyWebsite, licenseAgreementWebsite, imageDataVersion, avoidCache, animatedStickerPack);
stickerPack.setStickers(stickerList);
return stickerPack;
}