77import com .contentstack .utils .interfaces .Option ;
88import com .contentstack .utils .node .NodeToHTML ;
99import com .contentstack .utils .render .DefaultOption ;
10- import javax .validation .constraints .NotNull ;
1110import org .json .JSONArray ;
1211import org .json .JSONObject ;
1312import org .jsoup .nodes .Attributes ;
1413import org .jsoup .nodes .Document ;
1514import org .jsoup .select .Elements ;
1615
16+ import javax .validation .constraints .NotNull ;
1717import java .util .ArrayList ;
1818import java .util .Arrays ;
1919import java .util .List ;
2020import java .util .Optional ;
2121
2222public class AutomateCommon {
2323
24+ private static final String ASSET = "asset" ;
25+
26+ private AutomateCommon () {
27+ throw new IllegalStateException ("Not allowed to create instance of AutomateCommon" );
28+ }
2429
2530 /**
2631 * Find dot separated keys
2732 *
28- * @param entryObj Json Object
29- * @param path keyPath
30- * @param contentCallback content callback
33+ * @param entryObj
34+ * Json Object
35+ * @param path
36+ * keyPath
37+ * @param contentCallback
38+ * content callback
3139 */
3240 protected static void findContent (JSONObject entryObj , String path , ContentCallback contentCallback ) {
3341 String [] arrayString = path .split ("\\ ." );
@@ -36,9 +44,12 @@ protected static void findContent(JSONObject entryObj, String path, ContentCallb
3644
3745
3846 /**
39- * @param arrayString list of keys available
40- * @param entryObj entry object
41- * @param contentCallback content callback
47+ * @param arrayString
48+ * list of keys available
49+ * @param entryObj
50+ * entry object
51+ * @param contentCallback
52+ * content callback
4253 */
4354 private static void getContent (String [] arrayString , JSONObject entryObj , ContentCallback contentCallback ) {
4455 if (arrayString != null && arrayString .length != 0 ) {
@@ -78,7 +89,7 @@ protected static String getStringOption(Option option, Metadata metadata, JSONOb
7889 protected static void getEmbeddedObjects (Document html , MetadataCallback metadataCallback ) {
7990 Elements embeddedEntries = html .body ().getElementsByClass ("embedded-entry" );
8091 Elements embeddedAssets = html .body ().getElementsByClass ("embedded-asset" );
81- embeddedEntries .forEach (( entry ) -> {
92+ embeddedEntries .forEach (entry -> {
8293 String text = entry .text ();
8394 String type = entry .attr ("type" );
8495 String uid = entry .attr ("data-sys-entry-uid" );
@@ -89,13 +100,13 @@ protected static void getEmbeddedObjects(Document html, MetadataCallback metadat
89100 metadataCallback .embeddedObject (metadata );
90101 });
91102
92- embeddedAssets .forEach (( asset ) -> {
103+ embeddedAssets .forEach (asset -> {
93104 String text = asset .text ();
94105 String type = asset .attr ("type" );
95106 String uid = asset .attr ("data-sys-asset-uid" );
96107 String style = asset .attr ("sys-style-type" );
97108 String outerHTML = asset .outerHtml ();
98- Metadata metadata = new Metadata (text , type , uid , "asset" , style , outerHTML , asset .attributes ());
109+ Metadata metadata = new Metadata (text , type , uid , ASSET , style , outerHTML , asset .attributes ());
99110 metadataCallback .embeddedObject (metadata );
100111 });
101112 }
@@ -114,27 +125,27 @@ protected static Object enumerateContents(JSONArray contentArray, Option renderO
114125 protected static String enumerateContent (JSONObject jsonObject , Option renderObject , MetaToEmbedCallback item ) {
115126 if (jsonObject .length () > 0 && jsonObject .has ("type" ) && jsonObject .has ("children" )) {
116127 if (jsonObject .opt ("type" ).equals ("doc" )) {
117- return _doRawProcessing (jsonObject .optJSONArray ("children" ), renderObject , item );
128+ return doRawProcessing (jsonObject .optJSONArray ("children" ), renderObject , item );
118129 }
119130 }
120131 return "" ;
121132 }
122133
123134
124- private static String _doRawProcessing (@ NotNull JSONArray children , Option renderObject , MetaToEmbedCallback embedItem ) {
135+ private static String doRawProcessing (@ NotNull JSONArray children , Option renderObject , MetaToEmbedCallback embedItem ) {
125136 StringBuilder stringBuilder = new StringBuilder ();
126137 children .forEach (item -> {
127138 JSONObject child ;
128139 if (item instanceof JSONObject ) {
129140 child = (JSONObject ) item ;
130- stringBuilder .append (_extractKeys (child , renderObject , embedItem ));
141+ stringBuilder .append (extractKeys (child , renderObject , embedItem ));
131142 }
132143 });
133144 return stringBuilder .toString ();
134145 }
135146
136147
137- private static String _extractKeys (@ NotNull JSONObject jsonNode , Option renderObject , MetaToEmbedCallback embedItem ) {
148+ private static String extractKeys (@ NotNull JSONObject jsonNode , Option renderObject , MetaToEmbedCallback embedItem ) {
138149
139150 if (!jsonNode .has ("type" ) && jsonNode .has ("text" )) {
140151 return NodeToHTML .textNodeToHTML (jsonNode , renderObject );
@@ -145,12 +156,12 @@ private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderOb
145156 String attrType = attrObj .optString ("type" );
146157 com .contentstack .utils .helper .Metadata metadata ;
147158
148- if (attrType .equalsIgnoreCase ("asset" )) {
159+ if (attrType .equalsIgnoreCase (ASSET )) {
149160 String text = attrObj .optString ("text" );
150161 String uid = attrObj .optString ("asset-uid" );
151162 String style = attrObj .optString ("display-type" );
152163 metadata = new com .contentstack .utils .helper .Metadata (text , attrType , uid ,
153- "asset" , style , "" , new Attributes ());
164+ ASSET , style , "" , new Attributes ());
154165 } else {
155166 String text = attrObj .optString ("text" );
156167 String uid = attrObj .optString ("entry-uid" );
@@ -167,7 +178,7 @@ private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderOb
167178 }
168179
169180 } else {
170- return renderObject .renderNode (nodeType , jsonNode , nodeJsonArray -> _doRawProcessing (nodeJsonArray , renderObject , embedItem ));
181+ return renderObject .renderNode (nodeType , jsonNode , nodeJsonArray -> doRawProcessing (nodeJsonArray , renderObject , embedItem ));
171182 }
172183 }
173184 return "" ;
0 commit comments