/modules/apps/headless/headless-delivery/headless-delivery-client/src/main/java/com/liferay/headless/delivery/client/serdes/v1_0/FragmentViewportStyleSerDes.java

https://github.com/danielreuther/liferay-portal · Java · 946 lines · 724 code · 205 blank · 17 comment · 284 complexity · 4d4700e953e5a13089f6e80d6fec42c4 MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.headless.delivery.client.serdes.v1_0;
  15. import com.liferay.headless.delivery.client.dto.v1_0.FragmentViewportStyle;
  16. import com.liferay.headless.delivery.client.json.BaseJSONParser;
  17. import java.util.Iterator;
  18. import java.util.Map;
  19. import java.util.Objects;
  20. import java.util.Set;
  21. import java.util.TreeMap;
  22. import javax.annotation.Generated;
  23. /**
  24. * @author Javier Gamarra
  25. * @generated
  26. */
  27. @Generated("")
  28. public class FragmentViewportStyleSerDes {
  29. public static FragmentViewportStyle toDTO(String json) {
  30. FragmentViewportStyleJSONParser fragmentViewportStyleJSONParser =
  31. new FragmentViewportStyleJSONParser();
  32. return fragmentViewportStyleJSONParser.parseToDTO(json);
  33. }
  34. public static FragmentViewportStyle[] toDTOs(String json) {
  35. FragmentViewportStyleJSONParser fragmentViewportStyleJSONParser =
  36. new FragmentViewportStyleJSONParser();
  37. return fragmentViewportStyleJSONParser.parseToDTOs(json);
  38. }
  39. public static String toJSON(FragmentViewportStyle fragmentViewportStyle) {
  40. if (fragmentViewportStyle == null) {
  41. return "null";
  42. }
  43. StringBuilder sb = new StringBuilder();
  44. sb.append("{");
  45. if (fragmentViewportStyle.getBackgroundColor() != null) {
  46. if (sb.length() > 1) {
  47. sb.append(", ");
  48. }
  49. sb.append("\"backgroundColor\": ");
  50. sb.append("\"");
  51. sb.append(_escape(fragmentViewportStyle.getBackgroundColor()));
  52. sb.append("\"");
  53. }
  54. if (fragmentViewportStyle.getBorderColor() != null) {
  55. if (sb.length() > 1) {
  56. sb.append(", ");
  57. }
  58. sb.append("\"borderColor\": ");
  59. sb.append("\"");
  60. sb.append(_escape(fragmentViewportStyle.getBorderColor()));
  61. sb.append("\"");
  62. }
  63. if (fragmentViewportStyle.getBorderRadius() != null) {
  64. if (sb.length() > 1) {
  65. sb.append(", ");
  66. }
  67. sb.append("\"borderRadius\": ");
  68. sb.append("\"");
  69. sb.append(_escape(fragmentViewportStyle.getBorderRadius()));
  70. sb.append("\"");
  71. }
  72. if (fragmentViewportStyle.getBorderWidth() != null) {
  73. if (sb.length() > 1) {
  74. sb.append(", ");
  75. }
  76. sb.append("\"borderWidth\": ");
  77. sb.append("\"");
  78. sb.append(_escape(fragmentViewportStyle.getBorderWidth()));
  79. sb.append("\"");
  80. }
  81. if (fragmentViewportStyle.getFontFamily() != null) {
  82. if (sb.length() > 1) {
  83. sb.append(", ");
  84. }
  85. sb.append("\"fontFamily\": ");
  86. sb.append("\"");
  87. sb.append(_escape(fragmentViewportStyle.getFontFamily()));
  88. sb.append("\"");
  89. }
  90. if (fragmentViewportStyle.getFontSize() != null) {
  91. if (sb.length() > 1) {
  92. sb.append(", ");
  93. }
  94. sb.append("\"fontSize\": ");
  95. sb.append("\"");
  96. sb.append(_escape(fragmentViewportStyle.getFontSize()));
  97. sb.append("\"");
  98. }
  99. if (fragmentViewportStyle.getFontWeight() != null) {
  100. if (sb.length() > 1) {
  101. sb.append(", ");
  102. }
  103. sb.append("\"fontWeight\": ");
  104. sb.append("\"");
  105. sb.append(_escape(fragmentViewportStyle.getFontWeight()));
  106. sb.append("\"");
  107. }
  108. if (fragmentViewportStyle.getHeight() != null) {
  109. if (sb.length() > 1) {
  110. sb.append(", ");
  111. }
  112. sb.append("\"height\": ");
  113. sb.append("\"");
  114. sb.append(_escape(fragmentViewportStyle.getHeight()));
  115. sb.append("\"");
  116. }
  117. if (fragmentViewportStyle.getHidden() != null) {
  118. if (sb.length() > 1) {
  119. sb.append(", ");
  120. }
  121. sb.append("\"hidden\": ");
  122. sb.append(fragmentViewportStyle.getHidden());
  123. }
  124. if (fragmentViewportStyle.getMarginBottom() != null) {
  125. if (sb.length() > 1) {
  126. sb.append(", ");
  127. }
  128. sb.append("\"marginBottom\": ");
  129. sb.append("\"");
  130. sb.append(_escape(fragmentViewportStyle.getMarginBottom()));
  131. sb.append("\"");
  132. }
  133. if (fragmentViewportStyle.getMarginLeft() != null) {
  134. if (sb.length() > 1) {
  135. sb.append(", ");
  136. }
  137. sb.append("\"marginLeft\": ");
  138. sb.append("\"");
  139. sb.append(_escape(fragmentViewportStyle.getMarginLeft()));
  140. sb.append("\"");
  141. }
  142. if (fragmentViewportStyle.getMarginRight() != null) {
  143. if (sb.length() > 1) {
  144. sb.append(", ");
  145. }
  146. sb.append("\"marginRight\": ");
  147. sb.append("\"");
  148. sb.append(_escape(fragmentViewportStyle.getMarginRight()));
  149. sb.append("\"");
  150. }
  151. if (fragmentViewportStyle.getMarginTop() != null) {
  152. if (sb.length() > 1) {
  153. sb.append(", ");
  154. }
  155. sb.append("\"marginTop\": ");
  156. sb.append("\"");
  157. sb.append(_escape(fragmentViewportStyle.getMarginTop()));
  158. sb.append("\"");
  159. }
  160. if (fragmentViewportStyle.getMaxHeight() != null) {
  161. if (sb.length() > 1) {
  162. sb.append(", ");
  163. }
  164. sb.append("\"maxHeight\": ");
  165. sb.append("\"");
  166. sb.append(_escape(fragmentViewportStyle.getMaxHeight()));
  167. sb.append("\"");
  168. }
  169. if (fragmentViewportStyle.getMaxWidth() != null) {
  170. if (sb.length() > 1) {
  171. sb.append(", ");
  172. }
  173. sb.append("\"maxWidth\": ");
  174. sb.append("\"");
  175. sb.append(_escape(fragmentViewportStyle.getMaxWidth()));
  176. sb.append("\"");
  177. }
  178. if (fragmentViewportStyle.getMinHeight() != null) {
  179. if (sb.length() > 1) {
  180. sb.append(", ");
  181. }
  182. sb.append("\"minHeight\": ");
  183. sb.append("\"");
  184. sb.append(_escape(fragmentViewportStyle.getMinHeight()));
  185. sb.append("\"");
  186. }
  187. if (fragmentViewportStyle.getMinWidth() != null) {
  188. if (sb.length() > 1) {
  189. sb.append(", ");
  190. }
  191. sb.append("\"minWidth\": ");
  192. sb.append("\"");
  193. sb.append(_escape(fragmentViewportStyle.getMinWidth()));
  194. sb.append("\"");
  195. }
  196. if (fragmentViewportStyle.getOpacity() != null) {
  197. if (sb.length() > 1) {
  198. sb.append(", ");
  199. }
  200. sb.append("\"opacity\": ");
  201. sb.append("\"");
  202. sb.append(_escape(fragmentViewportStyle.getOpacity()));
  203. sb.append("\"");
  204. }
  205. if (fragmentViewportStyle.getOverflow() != null) {
  206. if (sb.length() > 1) {
  207. sb.append(", ");
  208. }
  209. sb.append("\"overflow\": ");
  210. sb.append("\"");
  211. sb.append(_escape(fragmentViewportStyle.getOverflow()));
  212. sb.append("\"");
  213. }
  214. if (fragmentViewportStyle.getPaddingBottom() != null) {
  215. if (sb.length() > 1) {
  216. sb.append(", ");
  217. }
  218. sb.append("\"paddingBottom\": ");
  219. sb.append("\"");
  220. sb.append(_escape(fragmentViewportStyle.getPaddingBottom()));
  221. sb.append("\"");
  222. }
  223. if (fragmentViewportStyle.getPaddingLeft() != null) {
  224. if (sb.length() > 1) {
  225. sb.append(", ");
  226. }
  227. sb.append("\"paddingLeft\": ");
  228. sb.append("\"");
  229. sb.append(_escape(fragmentViewportStyle.getPaddingLeft()));
  230. sb.append("\"");
  231. }
  232. if (fragmentViewportStyle.getPaddingRight() != null) {
  233. if (sb.length() > 1) {
  234. sb.append(", ");
  235. }
  236. sb.append("\"paddingRight\": ");
  237. sb.append("\"");
  238. sb.append(_escape(fragmentViewportStyle.getPaddingRight()));
  239. sb.append("\"");
  240. }
  241. if (fragmentViewportStyle.getPaddingTop() != null) {
  242. if (sb.length() > 1) {
  243. sb.append(", ");
  244. }
  245. sb.append("\"paddingTop\": ");
  246. sb.append("\"");
  247. sb.append(_escape(fragmentViewportStyle.getPaddingTop()));
  248. sb.append("\"");
  249. }
  250. if (fragmentViewportStyle.getShadow() != null) {
  251. if (sb.length() > 1) {
  252. sb.append(", ");
  253. }
  254. sb.append("\"shadow\": ");
  255. sb.append("\"");
  256. sb.append(_escape(fragmentViewportStyle.getShadow()));
  257. sb.append("\"");
  258. }
  259. if (fragmentViewportStyle.getTextAlign() != null) {
  260. if (sb.length() > 1) {
  261. sb.append(", ");
  262. }
  263. sb.append("\"textAlign\": ");
  264. sb.append("\"");
  265. sb.append(_escape(fragmentViewportStyle.getTextAlign()));
  266. sb.append("\"");
  267. }
  268. if (fragmentViewportStyle.getTextColor() != null) {
  269. if (sb.length() > 1) {
  270. sb.append(", ");
  271. }
  272. sb.append("\"textColor\": ");
  273. sb.append("\"");
  274. sb.append(_escape(fragmentViewportStyle.getTextColor()));
  275. sb.append("\"");
  276. }
  277. if (fragmentViewportStyle.getWidth() != null) {
  278. if (sb.length() > 1) {
  279. sb.append(", ");
  280. }
  281. sb.append("\"width\": ");
  282. sb.append("\"");
  283. sb.append(_escape(fragmentViewportStyle.getWidth()));
  284. sb.append("\"");
  285. }
  286. sb.append("}");
  287. return sb.toString();
  288. }
  289. public static Map<String, Object> toMap(String json) {
  290. FragmentViewportStyleJSONParser fragmentViewportStyleJSONParser =
  291. new FragmentViewportStyleJSONParser();
  292. return fragmentViewportStyleJSONParser.parseToMap(json);
  293. }
  294. public static Map<String, String> toMap(
  295. FragmentViewportStyle fragmentViewportStyle) {
  296. if (fragmentViewportStyle == null) {
  297. return null;
  298. }
  299. Map<String, String> map = new TreeMap<>();
  300. if (fragmentViewportStyle.getBackgroundColor() == null) {
  301. map.put("backgroundColor", null);
  302. }
  303. else {
  304. map.put(
  305. "backgroundColor",
  306. String.valueOf(fragmentViewportStyle.getBackgroundColor()));
  307. }
  308. if (fragmentViewportStyle.getBorderColor() == null) {
  309. map.put("borderColor", null);
  310. }
  311. else {
  312. map.put(
  313. "borderColor",
  314. String.valueOf(fragmentViewportStyle.getBorderColor()));
  315. }
  316. if (fragmentViewportStyle.getBorderRadius() == null) {
  317. map.put("borderRadius", null);
  318. }
  319. else {
  320. map.put(
  321. "borderRadius",
  322. String.valueOf(fragmentViewportStyle.getBorderRadius()));
  323. }
  324. if (fragmentViewportStyle.getBorderWidth() == null) {
  325. map.put("borderWidth", null);
  326. }
  327. else {
  328. map.put(
  329. "borderWidth",
  330. String.valueOf(fragmentViewportStyle.getBorderWidth()));
  331. }
  332. if (fragmentViewportStyle.getFontFamily() == null) {
  333. map.put("fontFamily", null);
  334. }
  335. else {
  336. map.put(
  337. "fontFamily",
  338. String.valueOf(fragmentViewportStyle.getFontFamily()));
  339. }
  340. if (fragmentViewportStyle.getFontSize() == null) {
  341. map.put("fontSize", null);
  342. }
  343. else {
  344. map.put(
  345. "fontSize",
  346. String.valueOf(fragmentViewportStyle.getFontSize()));
  347. }
  348. if (fragmentViewportStyle.getFontWeight() == null) {
  349. map.put("fontWeight", null);
  350. }
  351. else {
  352. map.put(
  353. "fontWeight",
  354. String.valueOf(fragmentViewportStyle.getFontWeight()));
  355. }
  356. if (fragmentViewportStyle.getHeight() == null) {
  357. map.put("height", null);
  358. }
  359. else {
  360. map.put(
  361. "height", String.valueOf(fragmentViewportStyle.getHeight()));
  362. }
  363. if (fragmentViewportStyle.getHidden() == null) {
  364. map.put("hidden", null);
  365. }
  366. else {
  367. map.put(
  368. "hidden", String.valueOf(fragmentViewportStyle.getHidden()));
  369. }
  370. if (fragmentViewportStyle.getMarginBottom() == null) {
  371. map.put("marginBottom", null);
  372. }
  373. else {
  374. map.put(
  375. "marginBottom",
  376. String.valueOf(fragmentViewportStyle.getMarginBottom()));
  377. }
  378. if (fragmentViewportStyle.getMarginLeft() == null) {
  379. map.put("marginLeft", null);
  380. }
  381. else {
  382. map.put(
  383. "marginLeft",
  384. String.valueOf(fragmentViewportStyle.getMarginLeft()));
  385. }
  386. if (fragmentViewportStyle.getMarginRight() == null) {
  387. map.put("marginRight", null);
  388. }
  389. else {
  390. map.put(
  391. "marginRight",
  392. String.valueOf(fragmentViewportStyle.getMarginRight()));
  393. }
  394. if (fragmentViewportStyle.getMarginTop() == null) {
  395. map.put("marginTop", null);
  396. }
  397. else {
  398. map.put(
  399. "marginTop",
  400. String.valueOf(fragmentViewportStyle.getMarginTop()));
  401. }
  402. if (fragmentViewportStyle.getMaxHeight() == null) {
  403. map.put("maxHeight", null);
  404. }
  405. else {
  406. map.put(
  407. "maxHeight",
  408. String.valueOf(fragmentViewportStyle.getMaxHeight()));
  409. }
  410. if (fragmentViewportStyle.getMaxWidth() == null) {
  411. map.put("maxWidth", null);
  412. }
  413. else {
  414. map.put(
  415. "maxWidth",
  416. String.valueOf(fragmentViewportStyle.getMaxWidth()));
  417. }
  418. if (fragmentViewportStyle.getMinHeight() == null) {
  419. map.put("minHeight", null);
  420. }
  421. else {
  422. map.put(
  423. "minHeight",
  424. String.valueOf(fragmentViewportStyle.getMinHeight()));
  425. }
  426. if (fragmentViewportStyle.getMinWidth() == null) {
  427. map.put("minWidth", null);
  428. }
  429. else {
  430. map.put(
  431. "minWidth",
  432. String.valueOf(fragmentViewportStyle.getMinWidth()));
  433. }
  434. if (fragmentViewportStyle.getOpacity() == null) {
  435. map.put("opacity", null);
  436. }
  437. else {
  438. map.put(
  439. "opacity", String.valueOf(fragmentViewportStyle.getOpacity()));
  440. }
  441. if (fragmentViewportStyle.getOverflow() == null) {
  442. map.put("overflow", null);
  443. }
  444. else {
  445. map.put(
  446. "overflow",
  447. String.valueOf(fragmentViewportStyle.getOverflow()));
  448. }
  449. if (fragmentViewportStyle.getPaddingBottom() == null) {
  450. map.put("paddingBottom", null);
  451. }
  452. else {
  453. map.put(
  454. "paddingBottom",
  455. String.valueOf(fragmentViewportStyle.getPaddingBottom()));
  456. }
  457. if (fragmentViewportStyle.getPaddingLeft() == null) {
  458. map.put("paddingLeft", null);
  459. }
  460. else {
  461. map.put(
  462. "paddingLeft",
  463. String.valueOf(fragmentViewportStyle.getPaddingLeft()));
  464. }
  465. if (fragmentViewportStyle.getPaddingRight() == null) {
  466. map.put("paddingRight", null);
  467. }
  468. else {
  469. map.put(
  470. "paddingRight",
  471. String.valueOf(fragmentViewportStyle.getPaddingRight()));
  472. }
  473. if (fragmentViewportStyle.getPaddingTop() == null) {
  474. map.put("paddingTop", null);
  475. }
  476. else {
  477. map.put(
  478. "paddingTop",
  479. String.valueOf(fragmentViewportStyle.getPaddingTop()));
  480. }
  481. if (fragmentViewportStyle.getShadow() == null) {
  482. map.put("shadow", null);
  483. }
  484. else {
  485. map.put(
  486. "shadow", String.valueOf(fragmentViewportStyle.getShadow()));
  487. }
  488. if (fragmentViewportStyle.getTextAlign() == null) {
  489. map.put("textAlign", null);
  490. }
  491. else {
  492. map.put(
  493. "textAlign",
  494. String.valueOf(fragmentViewportStyle.getTextAlign()));
  495. }
  496. if (fragmentViewportStyle.getTextColor() == null) {
  497. map.put("textColor", null);
  498. }
  499. else {
  500. map.put(
  501. "textColor",
  502. String.valueOf(fragmentViewportStyle.getTextColor()));
  503. }
  504. if (fragmentViewportStyle.getWidth() == null) {
  505. map.put("width", null);
  506. }
  507. else {
  508. map.put("width", String.valueOf(fragmentViewportStyle.getWidth()));
  509. }
  510. return map;
  511. }
  512. public static class FragmentViewportStyleJSONParser
  513. extends BaseJSONParser<FragmentViewportStyle> {
  514. @Override
  515. protected FragmentViewportStyle createDTO() {
  516. return new FragmentViewportStyle();
  517. }
  518. @Override
  519. protected FragmentViewportStyle[] createDTOArray(int size) {
  520. return new FragmentViewportStyle[size];
  521. }
  522. @Override
  523. protected void setField(
  524. FragmentViewportStyle fragmentViewportStyle,
  525. String jsonParserFieldName, Object jsonParserFieldValue) {
  526. if (Objects.equals(jsonParserFieldName, "backgroundColor")) {
  527. if (jsonParserFieldValue != null) {
  528. fragmentViewportStyle.setBackgroundColor(
  529. (String)jsonParserFieldValue);
  530. }
  531. }
  532. else if (Objects.equals(jsonParserFieldName, "borderColor")) {
  533. if (jsonParserFieldValue != null) {
  534. fragmentViewportStyle.setBorderColor(
  535. (String)jsonParserFieldValue);
  536. }
  537. }
  538. else if (Objects.equals(jsonParserFieldName, "borderRadius")) {
  539. if (jsonParserFieldValue != null) {
  540. fragmentViewportStyle.setBorderRadius(
  541. (String)jsonParserFieldValue);
  542. }
  543. }
  544. else if (Objects.equals(jsonParserFieldName, "borderWidth")) {
  545. if (jsonParserFieldValue != null) {
  546. fragmentViewportStyle.setBorderWidth(
  547. (String)jsonParserFieldValue);
  548. }
  549. }
  550. else if (Objects.equals(jsonParserFieldName, "fontFamily")) {
  551. if (jsonParserFieldValue != null) {
  552. fragmentViewportStyle.setFontFamily(
  553. (String)jsonParserFieldValue);
  554. }
  555. }
  556. else if (Objects.equals(jsonParserFieldName, "fontSize")) {
  557. if (jsonParserFieldValue != null) {
  558. fragmentViewportStyle.setFontSize(
  559. (String)jsonParserFieldValue);
  560. }
  561. }
  562. else if (Objects.equals(jsonParserFieldName, "fontWeight")) {
  563. if (jsonParserFieldValue != null) {
  564. fragmentViewportStyle.setFontWeight(
  565. (String)jsonParserFieldValue);
  566. }
  567. }
  568. else if (Objects.equals(jsonParserFieldName, "height")) {
  569. if (jsonParserFieldValue != null) {
  570. fragmentViewportStyle.setHeight(
  571. (String)jsonParserFieldValue);
  572. }
  573. }
  574. else if (Objects.equals(jsonParserFieldName, "hidden")) {
  575. if (jsonParserFieldValue != null) {
  576. fragmentViewportStyle.setHidden(
  577. (Boolean)jsonParserFieldValue);
  578. }
  579. }
  580. else if (Objects.equals(jsonParserFieldName, "marginBottom")) {
  581. if (jsonParserFieldValue != null) {
  582. fragmentViewportStyle.setMarginBottom(
  583. (String)jsonParserFieldValue);
  584. }
  585. }
  586. else if (Objects.equals(jsonParserFieldName, "marginLeft")) {
  587. if (jsonParserFieldValue != null) {
  588. fragmentViewportStyle.setMarginLeft(
  589. (String)jsonParserFieldValue);
  590. }
  591. }
  592. else if (Objects.equals(jsonParserFieldName, "marginRight")) {
  593. if (jsonParserFieldValue != null) {
  594. fragmentViewportStyle.setMarginRight(
  595. (String)jsonParserFieldValue);
  596. }
  597. }
  598. else if (Objects.equals(jsonParserFieldName, "marginTop")) {
  599. if (jsonParserFieldValue != null) {
  600. fragmentViewportStyle.setMarginTop(
  601. (String)jsonParserFieldValue);
  602. }
  603. }
  604. else if (Objects.equals(jsonParserFieldName, "maxHeight")) {
  605. if (jsonParserFieldValue != null) {
  606. fragmentViewportStyle.setMaxHeight(
  607. (String)jsonParserFieldValue);
  608. }
  609. }
  610. else if (Objects.equals(jsonParserFieldName, "maxWidth")) {
  611. if (jsonParserFieldValue != null) {
  612. fragmentViewportStyle.setMaxWidth(
  613. (String)jsonParserFieldValue);
  614. }
  615. }
  616. else if (Objects.equals(jsonParserFieldName, "minHeight")) {
  617. if (jsonParserFieldValue != null) {
  618. fragmentViewportStyle.setMinHeight(
  619. (String)jsonParserFieldValue);
  620. }
  621. }
  622. else if (Objects.equals(jsonParserFieldName, "minWidth")) {
  623. if (jsonParserFieldValue != null) {
  624. fragmentViewportStyle.setMinWidth(
  625. (String)jsonParserFieldValue);
  626. }
  627. }
  628. else if (Objects.equals(jsonParserFieldName, "opacity")) {
  629. if (jsonParserFieldValue != null) {
  630. fragmentViewportStyle.setOpacity(
  631. (String)jsonParserFieldValue);
  632. }
  633. }
  634. else if (Objects.equals(jsonParserFieldName, "overflow")) {
  635. if (jsonParserFieldValue != null) {
  636. fragmentViewportStyle.setOverflow(
  637. (String)jsonParserFieldValue);
  638. }
  639. }
  640. else if (Objects.equals(jsonParserFieldName, "paddingBottom")) {
  641. if (jsonParserFieldValue != null) {
  642. fragmentViewportStyle.setPaddingBottom(
  643. (String)jsonParserFieldValue);
  644. }
  645. }
  646. else if (Objects.equals(jsonParserFieldName, "paddingLeft")) {
  647. if (jsonParserFieldValue != null) {
  648. fragmentViewportStyle.setPaddingLeft(
  649. (String)jsonParserFieldValue);
  650. }
  651. }
  652. else if (Objects.equals(jsonParserFieldName, "paddingRight")) {
  653. if (jsonParserFieldValue != null) {
  654. fragmentViewportStyle.setPaddingRight(
  655. (String)jsonParserFieldValue);
  656. }
  657. }
  658. else if (Objects.equals(jsonParserFieldName, "paddingTop")) {
  659. if (jsonParserFieldValue != null) {
  660. fragmentViewportStyle.setPaddingTop(
  661. (String)jsonParserFieldValue);
  662. }
  663. }
  664. else if (Objects.equals(jsonParserFieldName, "shadow")) {
  665. if (jsonParserFieldValue != null) {
  666. fragmentViewportStyle.setShadow(
  667. (String)jsonParserFieldValue);
  668. }
  669. }
  670. else if (Objects.equals(jsonParserFieldName, "textAlign")) {
  671. if (jsonParserFieldValue != null) {
  672. fragmentViewportStyle.setTextAlign(
  673. (String)jsonParserFieldValue);
  674. }
  675. }
  676. else if (Objects.equals(jsonParserFieldName, "textColor")) {
  677. if (jsonParserFieldValue != null) {
  678. fragmentViewportStyle.setTextColor(
  679. (String)jsonParserFieldValue);
  680. }
  681. }
  682. else if (Objects.equals(jsonParserFieldName, "width")) {
  683. if (jsonParserFieldValue != null) {
  684. fragmentViewportStyle.setWidth(
  685. (String)jsonParserFieldValue);
  686. }
  687. }
  688. }
  689. }
  690. private static String _escape(Object object) {
  691. String string = String.valueOf(object);
  692. for (String[] strings : BaseJSONParser.JSON_ESCAPE_STRINGS) {
  693. string = string.replace(strings[0], strings[1]);
  694. }
  695. return string;
  696. }
  697. private static String _toJSON(Map<String, ?> map) {
  698. StringBuilder sb = new StringBuilder("{");
  699. @SuppressWarnings("unchecked")
  700. Set set = map.entrySet();
  701. @SuppressWarnings("unchecked")
  702. Iterator<Map.Entry<String, ?>> iterator = set.iterator();
  703. while (iterator.hasNext()) {
  704. Map.Entry<String, ?> entry = iterator.next();
  705. sb.append("\"");
  706. sb.append(entry.getKey());
  707. sb.append("\": ");
  708. Object value = entry.getValue();
  709. Class<?> valueClass = value.getClass();
  710. if (value instanceof Map) {
  711. sb.append(_toJSON((Map)value));
  712. }
  713. else if (valueClass.isArray()) {
  714. Object[] values = (Object[])value;
  715. sb.append("[");
  716. for (int i = 0; i < values.length; i++) {
  717. sb.append("\"");
  718. sb.append(_escape(values[i]));
  719. sb.append("\"");
  720. if ((i + 1) < values.length) {
  721. sb.append(", ");
  722. }
  723. }
  724. sb.append("]");
  725. }
  726. else if (value instanceof String) {
  727. sb.append("\"");
  728. sb.append(_escape(entry.getValue()));
  729. sb.append("\"");
  730. }
  731. else {
  732. sb.append(String.valueOf(entry.getValue()));
  733. }
  734. if (iterator.hasNext()) {
  735. sb.append(", ");
  736. }
  737. }
  738. sb.append("}");
  739. return sb.toString();
  740. }
  741. }