11package com .contentstack .utils ;
22
3- import com .contentstack .utils .callbacks .ContentCallback ;
4- import com .contentstack .utils .callbacks .MetadataCallback ;
5- import com .contentstack .utils .callbacks .OptionsCallback ;
6- import com .contentstack .utils .helper .Metadata ;
7- import com .contentstack .utils .render .DefaultOptionsCallback ;
3+ import com .contentstack .utils .callbacks .Content ;
4+ import com .contentstack .utils .callbacks .Metadata ;
5+ import com .contentstack .utils .callbacks .Option ;
6+ import com .contentstack .utils .render .DefaultOption ;
87import org .json .JSONArray ;
98import org .json .JSONObject ;
109import org .jsoup .Jsoup ;
@@ -21,8 +20,8 @@ public class Utils {
2120 * @param keyPath keyPath
2221 * @param renderObject renderObject
2322 */
24- public static void render (JSONObject entryObj , String [] keyPath , OptionsCallback renderObject ){
25- ContentCallback callback = content -> {
23+ public static void render (JSONObject entryObj , String [] keyPath , Option renderObject ){
24+ Content callback = content -> {
2625 if (content instanceof JSONArray ) {
2726 JSONArray contentArray = (JSONArray ) content ;
2827 return renderContents (contentArray , entryObj , renderObject );
@@ -54,37 +53,37 @@ public static void render(JSONObject entryObj, String[] keyPath, OptionsCallbac
5453 * Find dot separated keys
5554 * @param entryObj Json Object
5655 * @param path keyPath
57- * @param contentCallback content callback
56+ * @param content content callback
5857 */
59- private static void findContent (JSONObject entryObj , String path , ContentCallback contentCallback ) {
58+ private static void findContent (JSONObject entryObj , String path , Content content ) {
6059 String [] arrayString = path .split ("\\ ." );
61- getContent (arrayString , entryObj , contentCallback );
60+ getContent (arrayString , entryObj , content );
6261 }
6362
6463 /**
6564 *
6665 * @param arrayString list of keys available
6766 * @param entryObj entry object
68- * @param contentCallback content callback
67+ * @param content content callback
6968 */
70- private static void getContent (String [] arrayString , JSONObject entryObj , ContentCallback contentCallback ) {
69+ private static void getContent (String [] arrayString , JSONObject entryObj , Content content ) {
7170 if (arrayString !=null && arrayString .length !=0 ){
7271 String key = arrayString [0 ];
7372 if (arrayString .length == 1 ) {
7473 Object varContent = entryObj .opt (key );
7574 if (varContent instanceof String || varContent instanceof JSONArray ) {
76- entryObj .put (key , contentCallback .contentObject (varContent ));
75+ entryObj .put (key , content .contentObject (varContent ));
7776 }
7877 } else {
7978 List <String > list = new ArrayList <>(Arrays .asList (arrayString ));
8079 list .remove (key );
8180 String [] newArrayString = list .toArray (new String [0 ]);
8281 if (entryObj .opt (key ) instanceof JSONObject ) {
83- getContent (newArrayString , entryObj .optJSONObject (key ), contentCallback );
82+ getContent (newArrayString , entryObj .optJSONObject (key ), content );
8483 } else if (entryObj .opt (key ) instanceof JSONArray ) {
8584 JSONArray jsonArray = entryObj .optJSONArray (key );
8685 for (int idx = 0 ; idx < jsonArray .length (); idx ++) {
87- getContent (newArrayString , jsonArray .optJSONObject (idx ), contentCallback );
86+ getContent (newArrayString , jsonArray .optJSONObject (idx ), content );
8887 }
8988 }
9089 }
@@ -98,18 +97,18 @@ private static void getContent(String[] arrayString, JSONObject entryObj, Conten
9897 * @param keyPath String array keyPath
9998 * @param renderObject renderObjects
10099 */
101- public void render (JSONArray jsonArray , String [] keyPath , OptionsCallback renderObject ){
100+ public void render (JSONArray jsonArray , String [] keyPath , Option renderObject ){
102101 jsonArray .forEach (jsonObj -> render ((JSONObject ) jsonObj , keyPath , renderObject ));
103102 }
104103
105104 /**
106105 * Accepts to render content on the basis of below content
107106 * @param rteStringify String of the rte available for the embedding
108107 * @param embedObject JSONObject to get the _embedded_object (_embedded_entries/_embedded_assets)
109- * @param optionsCallback Options take takes input as (StyleType type, JSONObject embeddedObject)
108+ * @param option Options take takes input as (StyleType type, JSONObject embeddedObject)
110109 * @return String of rte with replaced tag
111110 */
112- public static String renderContent (String rteStringify , JSONObject embedObject , OptionsCallback optionsCallback ) {
111+ public static String renderContent (String rteStringify , JSONObject embedObject , Option option ) {
113112 final String [] sReplaceRTE = {rteStringify };
114113 Document html = Jsoup .parse (rteStringify );
115114 getEmbeddedObjects (html , metadata -> {
@@ -121,7 +120,7 @@ public static String renderContent(String rteStringify, JSONObject embedObject,
121120 }
122121 if (filteredContent .isPresent ()) {
123122 JSONObject contentToPass = filteredContent .get ();
124- String stringOption = getStringOption (optionsCallback , metadata , contentToPass );
123+ String stringOption = getStringOption (option , metadata , contentToPass );
125124 sReplaceRTE [0 ] = html .body ().html ().replace (metadata .getOuterHTML (), stringOption );
126125 }
127126 });
@@ -133,14 +132,14 @@ public static String renderContent(String rteStringify, JSONObject embedObject,
133132 * Take below items to return updated string
134133 * @param rteArray JSONArray of the rte available for the embedding
135134 * @param entryObject JSONObject to get the _embedded_object (_embedded_entries/_embedded_assets)
136- * @param optionsCallback Options take takes input as (StyleType type, JSONObject embeddedObject)
135+ * @param option Options take takes input as (StyleType type, JSONObject embeddedObject)
137136 * @return String of rte with replaced tag
138137 */
139- public static JSONArray renderContents (JSONArray rteArray , JSONObject entryObject , OptionsCallback optionsCallback ) {
138+ public static JSONArray renderContents (JSONArray rteArray , JSONObject entryObject , Option option ) {
140139 JSONArray jsonArrayRTEContent = new JSONArray ();
141140 for (Object RTE : rteArray ) {
142141 String stringify = (String ) RTE ;
143- String renderContent = renderContent (stringify , entryObject , optionsCallback );
142+ String renderContent = renderContent (stringify , entryObject , option );
144143 jsonArrayRTEContent .put (renderContent );
145144 }
146145 return jsonArrayRTEContent ;
@@ -153,7 +152,7 @@ public static JSONArray renderContents(JSONArray rteArray, JSONObject entryObjec
153152 * @param metadata EmbeddedObject: contains the model class information
154153 * @return Optional<JSONObject>
155154 */
156- private static Optional <JSONObject > findEmbeddedItems (JSONObject jsonObject , Metadata metadata ) {
155+ private static Optional <JSONObject > findEmbeddedItems (JSONObject jsonObject , com . contentstack . utils . helper . Metadata metadata ) {
157156 Set <String > allKeys = jsonObject .keySet ();
158157 for (String key : allKeys ) {
159158 JSONArray jsonArray = jsonObject .optJSONArray (key );
@@ -167,17 +166,17 @@ private static Optional<JSONObject> findEmbeddedItems(JSONObject jsonObject, Met
167166 return Optional .empty ();
168167 }
169168
170- private static String getStringOption (OptionsCallback optionsCallback , Metadata metadata , JSONObject contentToPass ) {
171- String stringOption = optionsCallback .renderOptions (contentToPass , metadata );
169+ private static String getStringOption (Option option , com . contentstack . utils . helper . Metadata metadata , JSONObject contentToPass ) {
170+ String stringOption = option .renderOptions (contentToPass , metadata );
172171 if (stringOption == null ) {
173- DefaultOptionsCallback defaultOptions = new DefaultOptionsCallback ();
172+ DefaultOption defaultOptions = new DefaultOption ();
174173 stringOption = defaultOptions .renderOptions (contentToPass , metadata );
175174 }
176175 return stringOption ;
177176 }
178177
179178
180- private static void getEmbeddedObjects (Document html , MetadataCallback metadataCallback ) {
179+ private static void getEmbeddedObjects (Document html , Metadata metadataCallback ) {
181180 Elements embeddedEntries = html .body ().getElementsByClass ("embedded-entry" );
182181 Elements embeddedAssets = html .body ().getElementsByClass ("embedded-asset" );
183182 embeddedEntries .forEach ((entry ) -> {
@@ -187,7 +186,7 @@ private static void getEmbeddedObjects(Document html, MetadataCallback metadataC
187186 String contentType = entry .attr ("data-sys-content-type-uid" );
188187 String style = entry .attr ("sys-style-type" );
189188 String outerHTML = entry .outerHtml ();
190- Metadata metadata = new Metadata (text , type , uid , contentType , style , outerHTML , entry .attributes ());
189+ com . contentstack . utils . helper . Metadata metadata = new com . contentstack . utils . helper . Metadata (text , type , uid , contentType , style , outerHTML , entry .attributes ());
191190 metadataCallback .embeddedObject (metadata );
192191 });
193192
@@ -197,7 +196,7 @@ private static void getEmbeddedObjects(Document html, MetadataCallback metadataC
197196 String uid = asset .attr ("data-sys-asset-uid" );
198197 String style = asset .attr ("sys-style-type" );
199198 String outerHTML = asset .outerHtml ();
200- Metadata metadata = new Metadata (text , type , uid , "asset" , style , outerHTML , asset .attributes ());
199+ com . contentstack . utils . helper . Metadata metadata = new com . contentstack . utils . helper . Metadata (text , type , uid , "asset" , style , outerHTML , asset .attributes ());
201200 metadataCallback .embeddedObject (metadata );
202201 });
203202 }
0 commit comments