@@ -29,11 +29,16 @@ private AutomateCommon() {
29
29
}
30
30
31
31
/**
32
- * Find dot separated keys
32
+ * The function "findContent" splits a given path string into an array of strings, and then calls the
33
+ * "getContent" function with the array, a JSONObject, and a contentCallback as parameters.
33
34
*
34
- * @param entryObj Json Object
35
- * @param path keyPath
36
- * @param contentCallback content callback
35
+ * @param entryObj A JSONObject that contains the data you want to search through.
36
+ * @param path The `path` parameter is a string that represents the path to a specific content in a
37
+ * JSON object. It is used to navigate through the JSON object and find the desired content.
38
+ * @param contentCallback The `contentCallback` parameter is an instance of the `ContentCallback`
39
+ * interface. It is used to provide a callback mechanism for handling the content found during the
40
+ * search process. The `ContentCallback` interface typically defines a method that will be called with
41
+ * the content found at each step of the search.
37
42
*/
38
43
protected static void findContent (JSONObject entryObj , String path , ContentCallback contentCallback ) {
39
44
String [] arrayString = path .split ("\\ ." );
@@ -42,9 +47,15 @@ protected static void findContent(JSONObject entryObj, String path, ContentCallb
42
47
43
48
44
49
/**
45
- * @param arrayString list of keys available
46
- * @param entryObj entry object
47
- * @param contentCallback content callback
50
+ * The function `getContent` recursively traverses a JSON object and modifies its content based on
51
+ * a callback function.
52
+ *
53
+ * @param arrayString An array of strings representing the path to the content in the JSON object.
54
+ * @param entryObj The `entryObj` parameter is a JSONObject that contains the data to be processed.
55
+ * @param contentCallback The `contentCallback` parameter is an instance of the `ContentCallback`
56
+ * interface. This interface defines a method called `contentObject()` which takes an object as
57
+ * input and returns a modified version of that object. The purpose of this callback is to allow
58
+ * the caller of the `getContent()` method to customize
48
59
*/
49
60
private static void getContent (String [] arrayString , JSONObject entryObj , ContentCallback contentCallback ) {
50
61
if (arrayString != null && arrayString .length != 0 ) {
@@ -71,6 +82,20 @@ private static void getContent(String[] arrayString, JSONObject entryObj, Conten
71
82
}
72
83
73
84
85
+ /**
86
+ * The function returns a string representation of an option by rendering it with the provided
87
+ * content and metadata, falling back to default options if necessary.
88
+ *
89
+ * @param option The "option" parameter is an object of type Option, which represents a specific
90
+ * option that can be rendered. It likely has properties and methods that allow it to generate the
91
+ * desired output based on the provided content and metadata.
92
+ * @param metadata Metadata is an object that contains additional information about the option. It
93
+ * may include details such as the option's label, description, and any other relevant information.
94
+ * @param contentToPass The `contentToPass` parameter is a `JSONObject` that contains the data or
95
+ * content that needs to be passed to the `renderOptions` method of the `Option` or `DefaultOption`
96
+ * class. This data or content is used to generate the string representation of the option.
97
+ * @return The method is returning a string value.
98
+ */
74
99
protected static String getStringOption (Option option , Metadata metadata , JSONObject contentToPass ) {
75
100
String stringOption = option .renderOptions (contentToPass , metadata );
76
101
if (stringOption == null ) {
@@ -81,6 +106,17 @@ protected static String getStringOption(Option option, Metadata metadata, JSONOb
81
106
}
82
107
83
108
109
+ /**
110
+ * The function retrieves embedded objects from an HTML document and passes them to a callback
111
+ * function for further processing.
112
+ *
113
+ * @param html The "html" parameter is a Document object that represents an HTML document. It is
114
+ * used to extract embedded objects from the HTML document.
115
+ * @param metadataCallback The `metadataCallback` parameter is an instance of a class that
116
+ * implements the `MetadataCallback` interface. This interface defines a method called
117
+ * `embeddedObject` which is called for each embedded object found in the HTML document. The
118
+ * `embeddedObject` method takes a `Metadata` object as a parameter,
119
+ */
84
120
protected static void getEmbeddedObjects (Document html , MetadataCallback metadataCallback ) {
85
121
Elements embeddedEntries = html .body ().getElementsByClass ("embedded-entry" );
86
122
Elements embeddedAssets = html .body ().getElementsByClass ("embedded-asset" );
@@ -107,6 +143,16 @@ protected static void getEmbeddedObjects(Document html, MetadataCallback metadat
107
143
}
108
144
109
145
146
+ /**
147
+ * The function takes a JSONArray of content, iterates through each element, and calls another
148
+ * function to render and enumerate the content, returning a JSONArray of the rendered content.
149
+ *
150
+ * @param contentArray A JSONArray containing the content to be enumerated.
151
+ * @param renderObject The renderObject parameter is an instance of the Option class.
152
+ * @param item The "item" parameter is a callback function that takes in a "Meta" object and
153
+ * returns a value to be embedded in the rendered content.
154
+ * @return The method is returning a JSONArray object.
155
+ */
110
156
protected static Object enumerateContents (JSONArray contentArray , Option renderObject , MetaToEmbedCallback item ) {
111
157
JSONArray jsonArrayRTEContent = new JSONArray ();
112
158
for (Object RTE : contentArray ) {
@@ -117,8 +163,19 @@ protected static Object enumerateContents(JSONArray contentArray, Option renderO
117
163
return jsonArrayRTEContent ;
118
164
}
119
165
166
+ /**
167
+ * The function checks if a JSON object has a specific type and children, and if so, it performs
168
+ * some processing on the children.
169
+ *
170
+ * @param jsonObject A JSONObject that contains the content to be enumerated.
171
+ * @param renderObject The `renderObject` parameter is of type `Option`. It is used as an argument
172
+ * in the `doRawProcessing` method.
173
+ * @param item The "item" parameter is a callback function that takes in a "Meta" object and returns
174
+ * a string.
175
+ * @return An empty string.
176
+ */
120
177
protected static String enumerateContent (JSONObject jsonObject , Option renderObject , MetaToEmbedCallback item ) {
121
- if (jsonObject .length () > 0 && jsonObject .has ("type" ) && jsonObject .has ("children" )) {
178
+ if (! jsonObject .isEmpty () && jsonObject .has ("type" ) && jsonObject .has ("children" )) {
122
179
if (jsonObject .opt ("type" ).equals ("doc" )) {
123
180
return doRawProcessing (jsonObject .optJSONArray ("children" ), renderObject , item );
124
181
}
@@ -127,6 +184,17 @@ protected static String enumerateContent(JSONObject jsonObject, Option renderObj
127
184
}
128
185
129
186
187
+ /**
188
+ * The function `doRawProcessing` processes a JSONArray of children, extracting keys from each
189
+ * child and appending the results to a StringBuilder, then returns the final string.
190
+ *
191
+ * @param children A JSONArray containing the children items to process.
192
+ * @param renderObject The parameter "renderObject" is of type "Option". It is used as an option to
193
+ * specify how the keys should be rendered during processing.
194
+ * @param embedItem The `embedItem` parameter is a callback function that takes a `Meta` object as
195
+ * input and returns an embedded representation of that object.
196
+ * @return The method is returning a string.
197
+ */
130
198
private static String doRawProcessing (@ NotNull JSONArray children , Option renderObject , MetaToEmbedCallback embedItem ) {
131
199
StringBuilder stringBuilder = new StringBuilder ();
132
200
children .forEach (item -> {
@@ -140,6 +208,20 @@ private static String doRawProcessing(@NotNull JSONArray children, Option render
140
208
}
141
209
142
210
211
+ /**
212
+ * The function extracts keys from a JSON object and returns a string based on the type of the
213
+ * node.
214
+ *
215
+ * @param jsonNode The `jsonNode` parameter is a `JSONObject` that represents a node in a JSON
216
+ * structure. It is used to extract information from the node and perform certain operations based
217
+ * on its properties.
218
+ * @param renderObject The `renderObject` parameter is an object of type `Option`. It is used to
219
+ * specify rendering options for the extracted keys.
220
+ * @param embedItem The `embedItem` parameter is a callback function that takes a `Metadata` object
221
+ * as input and returns an optional `JSONObject`. This callback is used to embed metadata into the
222
+ * rendered content.
223
+ * @return The method is returning a String.
224
+ */
143
225
private static String extractKeys (@ NotNull JSONObject jsonNode , Option renderObject , MetaToEmbedCallback embedItem ) {
144
226
145
227
if (!jsonNode .has ("type" ) && jsonNode .has ("text" )) {
0 commit comments