-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadResource.java
More file actions
70 lines (60 loc) · 2.21 KB
/
ReadResource.java
File metadata and controls
70 lines (60 loc) · 2.21 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
package com.contentstack.utils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class ReadResource {
public JSONObject readJson(String filename) throws IOException {
File file = new File(filename);
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder stringBuilder = new StringBuilder();
char[] buffer = new char[10];
while (reader.read(buffer) != -1) {
stringBuilder.append(new String(buffer));
buffer = new char[10];
}
reader.close();
String response = stringBuilder.toString();
return new JSONObject(response);
}
public Attributes returnEntryAttributes(JSONObject entryObject) {
boolean available = entryObject.has("rich_text_editor");
JSONArray rteArray = null;
if (available) {
Object RTE = entryObject.get("rich_text_editor");
rteArray = ((JSONArray) RTE);
}
Document html = null;
assert rteArray != null;
for (Object RTE : rteArray) {
String stringify = (String) RTE;
html = Jsoup.parse(stringify);
}
assert html != null;
Elements embeddedEntries = html.body().getElementsByClass("embedded-entry");
return embeddedEntries.get(0).attributes();
}
public Attributes returnAssetAttributes(JSONObject entryObject) {
boolean available = entryObject.has("rich_text_editor");
JSONArray rteArray = null;
if (available) {
Object RTE = entryObject.get("rich_text_editor");
rteArray = ((JSONArray) RTE);
}
Document html = null;
assert rteArray != null;
for (Object RTE : rteArray) {
String stringify = (String) RTE;
html = Jsoup.parse(stringify);
}
assert html != null;
Elements embeddedEntries = html.body().getElementsByClass("embedded-asset");
return embeddedEntries.get(0).attributes();
}
}