GuideUtils.java 49.6 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.forms.common.service.FileAttachmentWrapper
 *  com.adobe.forms.common.service.StaleAssetIndicatorService
 *  com.adobe.forms.common.submitutils.CustomParameterRequest
 *  com.adobe.forms.common.submitutils.CustomResponse
 *  com.adobe.forms.common.submitutils.ParameterMap
 *  com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
 *  com.day.cq.i18n.I18n
 *  com.day.cq.wcm.api.WCMMode
 *  com.day.cq.wcm.api.components.EditConfig
 *  com.day.cq.wcm.api.components.EditContext
 *  com.day.cq.wcm.api.components.Toolbar
 *  com.day.cq.wcm.api.components.Toolbar$Button
 *  com.day.cq.wcm.api.components.Toolbar$Item
 *  com.day.cq.wcm.api.components.Toolbar$Separator
 *  com.day.cq.widget.ClientLibrary
 *  com.day.cq.widget.HtmlLibrary
 *  com.day.cq.widget.HtmlLibraryManager
 *  com.day.cq.widget.LibraryType
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.servlet.RequestDispatcher
 *  javax.servlet.ServletRequest
 *  javax.servlet.ServletResponse
 *  org.apache.commons.io.IOUtils
 *  org.apache.commons.lang.StringEscapeUtils
 *  org.apache.commons.lang.StringUtils
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.commons.lang3.text.StrLookup
 *  org.apache.commons.lang3.text.StrSubstitutor
 *  org.apache.commons.lang3.text.WordUtils
 *  org.apache.sling.api.SlingException
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.SlingHttpServletResponse
 *  org.apache.sling.api.request.RequestParameter
 *  org.apache.sling.api.request.RequestParameterMap
 *  org.apache.sling.api.request.RequestPathInfo
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.api.scripting.SlingBindings
 *  org.apache.sling.api.scripting.SlingScriptHelper
 *  org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper
 *  org.apache.sling.commons.json.JSONArray
 *  org.apache.sling.commons.json.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.utils;

import com.adobe.aemds.guide.common.GuideContainer;
import com.adobe.aemds.guide.common.GuideNode;
import com.adobe.aemds.guide.common.GuidePanel;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideLocalizationService;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.service.GuideModuleImporter;
import com.adobe.aemds.guide.submitutils.FileRequestParameter;
import com.adobe.aemds.guide.taglibs.GuideELUtils;
import com.adobe.aemds.guide.utils.CustomJSONWriter;
import com.adobe.aemds.guide.utils.DataLookUp;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideHTMLParser;
import com.adobe.aemds.guide.utils.GuideStringWriterResponse;
import com.adobe.forms.common.service.FileAttachmentWrapper;
import com.adobe.forms.common.service.StaleAssetIndicatorService;
import com.adobe.forms.common.submitutils.CustomParameterRequest;
import com.adobe.forms.common.submitutils.CustomResponse;
import com.adobe.forms.common.submitutils.ParameterMap;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.WCMMode;
import com.day.cq.wcm.api.components.EditConfig;
import com.day.cq.wcm.api.components.EditContext;
import com.day.cq.wcm.api.components.Toolbar;
import com.day.cq.widget.ClientLibrary;
import com.day.cq.widget.HtmlLibrary;
import com.day.cq.widget.HtmlLibraryManager;
import com.day.cq.widget.LibraryType;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.text.StrLookup;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.sling.api.SlingException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class GuideUtils {
    private static Logger logger = LoggerFactory.getLogger(GuideUtils.class);

    public static String humanize(String name) {
        if (name == null) {
            return null;
        }
        String humanizedName = name.replaceAll("_", " ");
        humanizedName = humanizedName.replaceAll("([A-Z][a-z]+)", " $1").replaceAll("([A-Z][A-Z]+)", " $1").replaceAll("([^A-Za-z ]+)", " $1").trim();
        humanizedName = WordUtils.capitalize((String)humanizedName);
        return humanizedName;
    }

    public static Map<String, String> convertStringToMap(String params) {
        HashMap<String, String> paramMap = new HashMap<String, String>();
        if (params != null) {
            String[] strategyParams;
            for (String param : strategyParams = params.split(",")) {
                String[] keyValue = param.split("=");
                if (keyValue.length == 2) {
                    paramMap.put(keyValue[0], keyValue[1]);
                    continue;
                }
                paramMap.put(param, param);
            }
        }
        return paramMap;
    }

    public static String paramToString(RequestParameter param) {
        if (param != null) {
            return param.toString();
        }
        return null;
    }

    public static String guideRefToGuidePath(String guideRefPath) {
        if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)guideRefPath, (CharSequence)"/content/dam/formsanddocuments/")) {
            return "/content/forms/af/" + org.apache.commons.lang3.StringUtils.substringAfter((String)guideRefPath, (String)"/content/dam/formsanddocuments/") + "/jcr:content/guideContainer";
        }
        return guideRefPath;
    }

    public static String manipulateBindRefForFragments(String bindRefPrefixForFragment, String bindRef, String fragmentRoot) {
        String manipulatedBindRef = bindRef;
        if (org.apache.commons.lang3.StringUtils.isNotBlank((CharSequence)bindRefPrefixForFragment) && org.apache.commons.lang3.StringUtils.isNotBlank((CharSequence)fragmentRoot)) {
            if (fragmentRoot.equals(bindRef)) {
                return null;
            }
            if (fragmentRoot.equals("/") || fragmentRoot.equals("xfa[0].form[0]")) {
                return bindRef;
            }
            if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)bindRef, (CharSequence)"xfa[0].form[0]") && !org.apache.commons.lang3.StringUtils.startsWith((CharSequence)bindRef, (CharSequence)(fragmentRoot + '.'))) {
                return bindRef;
            }
            if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)bindRef, (CharSequence)"/") && !org.apache.commons.lang3.StringUtils.startsWith((CharSequence)bindRef, (CharSequence)(fragmentRoot + '/'))) {
                return bindRef;
            }
            if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)bindRef, (CharSequence)"xfa[0].form[0]")) {
                manipulatedBindRef = bindRefPrefixForFragment + org.apache.commons.lang3.StringUtils.substringAfter((String)bindRef, (String)fragmentRoot);
            } else if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)bindRef, (CharSequence)"/")) {
                manipulatedBindRef = bindRefPrefixForFragment + org.apache.commons.lang3.StringUtils.substringAfter((String)bindRef, (String)fragmentRoot);
            }
        }
        return manipulatedBindRef;
    }

    public static String getNamespacedKeys(String key) {
        return "fd_" + key;
    }

    public static String translateOrReturnOriginal(String original, I18n i18n) {
        String nameSpacedkey;
        String localizedkey;
        if (i18n != null && !(nameSpacedkey = GuideUtils.getNamespacedKeys(original)).equals(localizedkey = i18n.getVar(nameSpacedkey))) {
            return localizedkey;
        }
        return original;
    }

    public static String escapeXml(String unescaped) {
        return StringEscapeUtils.escapeXml((String)unescaped);
    }

    public static boolean isGuideFileUploadModel(String guideNodeClass) {
        return "guideFileUpload".equals(guideNodeClass);
    }

    public static boolean isGuideButtonModel(String guideNodeClass) {
        return "guideButton".equals(guideNodeClass);
    }

    public static boolean isGuideFieldModel(String guideNodeClass) {
        return GuideConstants.GUIDE_FIELDS_CLASS_NAMES.indexOf(guideNodeClass) >= 0;
    }

    public static JSONObject getGuideContainer(JSONObject guideJson) throws GuideException {
        try {
            return guideJson.has("rootPanel") ? guideJson : guideJson.getJSONObject("jcr:content").getJSONObject("guideContainer");
        }
        catch (Exception e) {
            logger.error("Could not get guideContainer within GuideJson : " + guideJson.toString(), (Throwable)e);
            throw new GuideException(e);
        }
    }

    public static ValueMap getGuideContainer(SlingHttpServletRequest request, Resource elementResource) throws RepositoryException {
        if (elementResource == null) {
            return null;
        }
        Iterator iter = elementResource.listChildren();
        Resource guideContainer = null;
        while (iter.hasNext() && guideContainer == null) {
            Resource current = (Resource)iter.next();
            if (!GuideConstants.CONTAINER_RESOURCES.contains(current.getResourceType())) continue;
            guideContainer = current;
        }
        if (guideContainer != null) {
            return ResourceUtil.getValueMap((Resource)guideContainer);
        }
        logger.error("No guideContainer found");
        throw new GuideException("No guideContainer found");
    }

    public static Boolean isValidGuide(SlingHttpServletRequest request, Resource resource) throws RepositoryException {
        ValueMap properties = null;
        properties = GuideConstants.CONTAINER_RESOURCES.contains(resource.getResourceType()) ? ResourceUtil.getValueMap((Resource)resource) : GuideUtils.getGuideContainer(request, resource);
        String guideRef = (String)properties.get("guideRef", null);
        if (guideRef != null && guideRef.length() != 0) {
            String guideContainerPath = GuideUtils.guideRefToGuidePath(guideRef);
            Resource guideContainer = request.getResourceResolver().getResource(guideContainerPath);
            if (guideContainer == null) {
                logger.error("No guide found in guide reference present in guide container");
                return false;
            }
        }
        return true;
    }

    public static String getNormalizedNodeType(String resourceType, String resourceSuperType) {
        String normalizedType = null;
        if (resourceType == null && resourceSuperType == null) {
            return null;
        }
        if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)resourceType, (CharSequence)"fd/")) {
            normalizedType = resourceType;
        } else if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)resourceType, (CharSequence)"/libs/fd/") || org.apache.commons.lang3.StringUtils.startsWith((CharSequence)resourceType, (CharSequence)"/apps/fd/")) {
            normalizedType = resourceType.substring(6);
        } else if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)resourceSuperType, (CharSequence)"fd/")) {
            normalizedType = resourceSuperType;
        } else if (org.apache.commons.lang3.StringUtils.startsWith((CharSequence)resourceSuperType, (CharSequence)"/libs/fd/") || org.apache.commons.lang3.StringUtils.startsWith((CharSequence)resourceSuperType, (CharSequence)"/apps/fd/")) {
            normalizedType = resourceSuperType.substring(6);
        }
        return normalizedType;
    }

    public static void walkThroughContent(List<String> list, Resource elementResource, String resourceToBeFound) {
        if (elementResource == null) {
            return;
        }
        Iterator iter = elementResource.listChildren();
        while (iter.hasNext()) {
            Resource current = (Resource)iter.next();
            String normalizedNodeType = GuideUtils.getNormalizedNodeType(current.getResourceType(), current.getResourceSuperType());
            if (resourceToBeFound.equals(normalizedNodeType)) {
                list.add(current.getPath());
            }
            GuideUtils.walkThroughContent(list, current, resourceToBeFound);
        }
    }

    public static boolean isLayoutablePanel(GuideNode node) {
        String nodeType = GuideUtils.getNormalizedNodeType(node.getResourceType(), node.getResourceSuperType());
        return "fd/af/components/rootPanel".equals(nodeType) || "fd/af/components/panel".equals(nodeType);
    }

    public static String convertFMAssetPathToContainerPath(String fragRef) {
        fragRef = StringUtils.replace((String)fragRef, (String)"/content/dam/formsanddocuments/", (String)"/content/forms/af/", (int)1);
        fragRef = fragRef + "/jcr:content" + "/" + "guideContainer";
        return fragRef;
    }

    public static ResourceResolver getResolverFromResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
        if (resourceResolverHelper != null) {
            return resourceResolverHelper.getResourceResolver();
        }
        return null;
    }

    public static ResourceResolver getResolverFromResource(GuideContainer guideContainer) {
        Resource resource = null;
        if (guideContainer != null && (resource = guideContainer.getResource()) != null) {
            return resource.getResourceResolver();
        }
        return null;
    }

    public static StrSubstitutor getStringSubstitutor(JSONObject valueMap) {
        return new StrSubstitutor((StrLookup)new DataLookUp(valueMap));
    }

    public static GuidePanel getRootPanel(Resource resource, SlingHttpServletRequest slingRequest) {
        Iterator iter = resource.listChildren();
        GuidePanel rootPanel = null;
        ResourceResolver resourceResolver = resource.getResourceResolver();
        while (iter.hasNext() && rootPanel == null) {
            Resource current = (Resource)iter.next();
            String name = current.getName();
            if (!"rootPanel".equals(name)) continue;
            rootPanel = new GuidePanel();
            rootPanel.setResource(current);
            rootPanel.setSlingRequest(slingRequest);
        }
        return rootPanel;
    }

    public static GuideModuleImporter getGuideModuleImporter(SlingHttpServletRequest slingRequest) {
        SlingBindings bindings = null;
        GuideModuleImporter guideModuleImporter = null;
        if (slingRequest != null && (bindings = (SlingBindings)slingRequest.getAttribute(SlingBindings.class.getName())) != null) {
            guideModuleImporter = (GuideModuleImporter)bindings.getSling().getService(GuideModuleImporter.class);
        }
        return guideModuleImporter;
    }

    public static Resource getRootPanel(Resource resource) {
        try {
            if (resource != null) {
                for (Resource item : resource.getChildren()) {
                    String valueOfResourceType;
                    ValueMap valueMap = (ValueMap)item.adaptTo(ValueMap.class);
                    if (valueMap.get((Object)"sling:resourceType") == null || !"fd/af/components/rootPanel".equals(valueOfResourceType = (String)valueMap.get((Object)"sling:resourceType"))) continue;
                    return item;
                }
            }
        }
        catch (Exception e) {
            logger.error("error in getting root panel via guide json", (Throwable)e);
        }
        return null;
    }

    protected static String removePrefix(String str, String prefix) {
        if (str == null || prefix == null) {
            return str;
        }
        if (str.startsWith(prefix)) {
            return str.substring(prefix.length());
        }
        return str;
    }

    public static Calendar getLastModifiedTimeFromStaleAssetIndicatorService(GuideContainer guideContainer, StaleAssetIndicatorService staleAssetIndicatorService) {
        Resource assetNode = null;
        Calendar lastModifiedTime = null;
        try {
            ResourceResolver guideResourceResolver = guideContainer.getResource().getResourceResolver();
            if (guideResourceResolver != null) {
                String assetJcrContentPath = org.apache.commons.lang3.StringUtils.replace((String)guideContainer.getPath(), (String)"/content/forms/af/", (String)"/content/dam/formsanddocuments/", (int)1);
                String assetPath = org.apache.commons.lang3.StringUtils.substringBefore((String)(assetJcrContentPath = assetJcrContentPath.substring(0, assetJcrContentPath.lastIndexOf("/"))), (String)"/jcr:content");
                assetNode = guideResourceResolver.getResource(assetPath);
                lastModifiedTime = assetNode != null && org.apache.commons.lang3.StringUtils.startsWith((CharSequence)assetPath, (CharSequence)"/content/dam/formsanddocuments/") ? GuideUtils.getCurrentLMT(assetNode, staleAssetIndicatorService) : guideContainer.getLastModifiedTime();
            }
        }
        catch (Exception e) {
            logger.error("Error while calling getLastModifiedTimeFromStaleAssetIndicatorService", (Throwable)e);
        }
        return lastModifiedTime;
    }

    public static boolean isXDPValid(Resource guideContainer) {
        if (guideContainer == null) {
            return false;
        }
        ResourceResolver resolver = guideContainer.getResourceResolver();
        ValueMap guideContainerProps = (ValueMap)guideContainer.adaptTo(ValueMap.class);
        String xdpRef = (String)guideContainerProps.get("xdpRef", null);
        if (xdpRef == null || xdpRef.length() == 0) {
            return false;
        }
        return resolver.getResource(xdpRef) != null;
    }

    public static boolean isGuideContainerResource(Resource resource) {
        return GuideConstants.CONTAINER_RESOURCES.contains(resource.getResourceType());
    }

    public static boolean isCacheableContainerResource(Resource resource) {
        return GuideConstants.CACHEABLE_CONTAINER_RESOURCES.contains(resource.getResourceType());
    }

    public static boolean isTargetEnabled(Resource guideContainerResource) {
        ValueMap props = (ValueMap)guideContainerResource.getParent().adaptTo(ValueMap.class);
        return (Boolean)props.get("targetEnabled", (Object)false);
    }

    public static String getAlternateContainerPathFromCurrentContainer(RequestPathInfo requestPathInfo) {
        String currentContainerPath = requestPathInfo.getResourcePath();
        String extension = null;
        if (currentContainerPath == null) {
            return null;
        }
        extension = requestPathInfo.getExtension();
        if (extension == null) {
            return currentContainerPath.substring(0, currentContainerPath.lastIndexOf("/")) + "/" + "guideContainer2";
        }
        return currentContainerPath.substring(0, currentContainerPath.lastIndexOf("/")) + "/" + "guideContainer2" + "." + extension;
    }

    public static boolean isDorTemplateRefValid(Resource guideContainer) {
        if (guideContainer == null) {
            return false;
        }
        ResourceResolver resolver = guideContainer.getResourceResolver();
        ValueMap guideContainerProps = (ValueMap)guideContainer.adaptTo(ValueMap.class);
        String xsdRef = (String)guideContainerProps.get("xsdRef", null);
        String dorTemplateRef = null;
        if (xsdRef == null || xsdRef.length() == 0) {
            return false;
        }
        dorTemplateRef = (String)guideContainerProps.get("dorTemplateRef", null);
        if (dorTemplateRef != null) {
            boolean isValid = true;
            try {
                isValid = resolver.getResource(dorTemplateRef) != null;
            }
            catch (SlingException ex) {
                isValid = false;
                logger.error("DOR Template present in XDP is either set to null or is relative" + ex.getMessage(), (Throwable)ex);
            }
            return isValid;
        }
        return false;
    }

    public static String getGuideRuntimeLocale(SlingHttpServletRequest slingRequest, Resource resource) {
        int index = 0;
        String[] GUIDES_SUPPORTED_CLIENTLIBS = GuideConstants.GUIDES_SUPPORTED_CLIENTLIBS;
        String[] supportedLocales = GuideConstants.AEM_SUPPORTED_LOCALES;
        if (resource != null && slingRequest != null) {
            Locale authoringLocale;
            SlingBindings bindings = (SlingBindings)slingRequest.getAttribute(SlingBindings.class.getName());
            if (bindings != null) {
                GuideLocalizationService guideLocalizationService = (GuideLocalizationService)bindings.getSling().getService(GuideLocalizationService.class);
                supportedLocales = guideLocalizationService.getSupportedLocales();
                GUIDES_SUPPORTED_CLIENTLIBS = GuideUtils.sanitizeLocaleList(supportedLocales);
            }
            String locale = GuideELUtils.getLocale(slingRequest, resource);
            index = Arrays.asList(GUIDES_SUPPORTED_CLIENTLIBS).indexOf(locale);
            if (index == -1 && (authoringLocale = slingRequest.getLocale()) != null) {
                index = Arrays.asList(GUIDES_SUPPORTED_CLIENTLIBS).indexOf(authoringLocale.toString());
            }
            if (index == -1) {
                index = 0;
            }
        }
        return supportedLocales[index];
    }

    public static Calendar getCurrentLMT(Resource containerResource, StaleAssetIndicatorService staleAssetIndicatorService) {
        Calendar calendar = Calendar.getInstance();
        if (staleAssetIndicatorService != null) {
            long currentLMT = staleAssetIndicatorService.getAssetTreeLMT(containerResource);
            calendar.setTimeInMillis(currentLMT);
        } else {
            logger.info("staleAssetIndicatorService not available : Guide Json cache miss");
            calendar.setTimeInMillis(Long.MAX_VALUE);
        }
        return calendar;
    }

    public static String getAcceptLang(SlingHttpServletRequest request) {
        String acceptLang;
        if (request == null) {
            return "en";
        }
        String language = null;
        SlingBindings bindings = (SlingBindings)request.getAttribute(SlingBindings.class.getName());
        String afLang = request.getParameter("afAcceptLang");
        if (afLang != null && !afLang.trim().equals("")) {
            language = GuideUtils.getAcceptLang(afLang, bindings);
        }
        if (language == null && (acceptLang = request.getHeader("Accept-Language")) != null && !acceptLang.isEmpty()) {
            language = GuideUtils.getAcceptLang(acceptLang, bindings);
        }
        if (language != null) {
            return language;
        }
        return GuideUtils.getDefaultLocale(request);
    }

    private static String getDefaultLocale(SlingHttpServletRequest request) {
        try {
            Resource guideContainerResource;
            String path;
            ResourceResolver guideResourceResolver;
            Resource resource = request.getResource();
            if (resource != null && (path = GuideELUtils.getGuideContainerPath(request, resource)) != null && !path.isEmpty() && (guideResourceResolver = request.getResourceResolver()) != null && (guideContainerResource = guideResourceResolver.getResource(path)) != null) {
                return GuideELUtils.getDefaultLocale(guideContainerResource);
            }
        }
        catch (Exception e) {
            logger.error("Guide Resource not found", (Throwable)e);
        }
        return "en";
    }

    private static String getAcceptLang(String locale, SlingBindings bindings) {
        String acceptLang = locale;
        if (bindings != null) {
            GuideLocalizationService guideLocalizationService = (GuideLocalizationService)bindings.getSling().getService(GuideLocalizationService.class);
            String[] supportedLocales = guideLocalizationService.getSupportedLocales();
            String[] supportedLocalesSanitized = GuideUtils.sanitizeLocaleList(supportedLocales);
            String[] locales = org.apache.commons.lang3.StringUtils.split((String)acceptLang, (String)",");
            for (int i = 0; i < locales.length; ++i) {
                int index;
                String localeCode = org.apache.commons.lang3.StringUtils.substringBefore((String)locales[i], (String)";");
                String[] splitLocale = org.apache.commons.lang3.StringUtils.split((String)localeCode, (String)"-");
                localeCode = splitLocale[0].toLowerCase();
                if (splitLocale.length > 1) {
                    localeCode = localeCode + splitLocale[1].toUpperCase();
                }
                if ((index = Arrays.asList(supportedLocalesSanitized).indexOf(localeCode)) != -1) {
                    acceptLang = supportedLocales[index];
                    return acceptLang;
                }
                if (splitLocale.length <= 1 || (index = Arrays.asList(supportedLocalesSanitized).indexOf(splitLocale[0].toLowerCase())) == -1) continue;
                acceptLang = supportedLocales[index];
                return acceptLang;
            }
            return null;
        }
        return locale;
    }

    public static void visitToCollectProperties(JSONObject guideTypeJsonObject, String toCheck, String keyToPut, String valueToPut, JSONArray collection) {
        try {
            if (guideTypeJsonObject.has(toCheck)) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put((String)guideTypeJsonObject.get(keyToPut), (Object)((String)guideTypeJsonObject.get(valueToPut)));
                collection.put((Object)jsonObject);
            }
            if (guideTypeJsonObject.has("items")) {
                JSONObject items = (JSONObject)guideTypeJsonObject.get("items");
                Iterator childKeys = items.keys();
                while (childKeys.hasNext()) {
                    GuideUtils.visitToCollectProperties((JSONObject)items.get((String)childKeys.next()), toCheck, keyToPut, valueToPut, collection);
                }
            }
        }
        catch (Exception e) {
            logger.error("Error in visting XML Schema", (Throwable)e);
        }
    }

    public static I18n getI18nForDesiredLocale(SlingHttpServletRequest request, Resource guideContainerResource, Locale desiredLocale) {
        ResourceBundle resourceBundle;
        String baseName = null;
        if (desiredLocale == null) {
            desiredLocale = request.getLocale();
        }
        if (guideContainerResource != null && request != null && (baseName = GuideELUtils.getGuideContainerPath(request, guideContainerResource) + "/assets/dictionary") != null && (resourceBundle = request.getResourceBundle(baseName, desiredLocale)) != null) {
            return new I18n(resourceBundle);
        }
        return null;
    }

    public static int getLocaleIndexFromLocale(String locale, String[] AEM_SUPPORTED_LOCALES) {
        String[] GUIDES_SUPPORTED_CLIENTLIBS = GuideUtils.sanitizeLocaleList(AEM_SUPPORTED_LOCALES);
        int index = Arrays.asList(GUIDES_SUPPORTED_CLIENTLIBS).indexOf(locale);
        if (index == -1) {
            index = 0;
        }
        return index;
    }

    public static String[] sanitizeLocaleList(String[] locales) {
        String[] sanitizedLocales = new String[locales.length];
        for (int i = 0; i < locales.length; ++i) {
            String localeCode = locales[i];
            String[] splitLocale = org.apache.commons.lang3.StringUtils.split((String)localeCode, (String)"-");
            localeCode = splitLocale[0].toLowerCase();
            if (splitLocale.length > 1) {
                localeCode = localeCode + splitLocale[1].toUpperCase();
            }
            sanitizedLocales[i] = localeCode;
        }
        return sanitizedLocales;
    }

    public static Session getUserSessionFromRequest(SlingHttpServletRequest slingHttpServletRequest) {
        return (Session)slingHttpServletRequest.getResourceResolver().adaptTo(Session.class);
    }

    public static SlingHttpServletResponse processInternalPostOnRestEndPoint(SlingHttpServletRequest request, SlingHttpServletResponse response, String postUrl) {
        CustomParameterRequest wrappedRequest = null;
        CustomResponse wrappedResponse = null;
        try {
            ParameterMap wrappedParameterMap = GuideUtils.prepareWrappedRequestWithDataXMLAndAttachments(request);
            wrappedRequest = new CustomParameterRequest(request, wrappedParameterMap, "POST");
            wrappedResponse = new CustomResponse(response);
            request.getRequestDispatcher(postUrl).forward((ServletRequest)wrappedRequest, (ServletResponse)wrappedResponse);
        }
        catch (Exception e) {
            logger.error("Some Problem While Posting to rest End Point", (Throwable)e);
        }
        return wrappedResponse;
    }

    public static void addToRequestMap(ParameterMap requestParameterMap, String key, RequestParameter[] requestParameter) {
        requestParameterMap.put((Object)key, (Object)requestParameter);
    }

    public static ParameterMap prepareWrappedRequestWithDataXMLAndAttachments(SlingHttpServletRequest request) {
        ParameterMap wrappedParameterMap = new ParameterMap();
        RequestParameterMap originalParams = request.getRequestParameterMap();
        ArrayList<FileAttachmentWrapper> fileAttachments = new ArrayList<FileAttachmentWrapper>();
        try {
            for (Map.Entry param : originalParams.entrySet()) {
                RequestParameter[] rpm = (RequestParameter[])param.getValue();
                if (rpm == null || rpm.length <= 0 || rpm[0].isFormField()) continue;
                FileAttachmentWrapper fileAttachment = new FileAttachmentWrapper(rpm[0].getFileName(), rpm[0].getContentType(), rpm[0].get());
                fileAttachments.add(fileAttachment);
            }
            if (fileAttachments.size() > 0) {
                RequestParameter[] attachments = new RequestParameter[fileAttachments.size()];
                int index = 0;
                for (FileAttachmentWrapper fileAttachment : fileAttachments) {
                    attachments[index] = new FileRequestParameter(fileAttachment.getFileName(), IOUtils.toByteArray((InputStream)fileAttachment.getInputStream()), fileAttachment.getContentType());
                }
                GuideUtils.addToRequestMap(wrappedParameterMap, "attachments", attachments);
            }
            GuideUtils.addToRequestMap(wrappedParameterMap, "dataXml", originalParams.getValues("jcr:data"));
        }
        catch (Exception e) {
            logger.error("Not Able to make internal post req parameter", (Throwable)e);
        }
        return wrappedParameterMap;
    }

    public static String getFieldLayout(Resource guideContainerResource, String propertyName, String defaultValue) {
        ValueMap properties = (ValueMap)guideContainerResource.adaptTo(ValueMap.class);
        return (String)properties.get(propertyName, (Object)defaultValue);
    }

    public static boolean setEmbedFragButton(String title, EditContext editContext, SlingHttpServletRequest request, String fragRef, String currentPanelPath, String bindRef) {
        EditConfig editConfig;
        Toolbar tb;
        if (editContext != null && (editConfig = editContext.getEditConfig()) != null && (tb = editConfig.getToolbar()) != null) {
            if (title != null) {
                tb.add((Toolbar.Item)new Toolbar.Separator());
                fragRef = org.apache.commons.lang3.StringUtils.replace((String)fragRef, (String)"/content/dam/formsanddocuments/", (String)"/content/forms/af/", (int)1);
                tb.add((Toolbar.Item)new Toolbar.Button(title, "function(){guidelib.author.editConfigListeners.embedFragment(\"" + fragRef + "\", \"" + currentPanelPath + "\" ,\"" + bindRef + "\");}"));
            }
            return true;
        }
        return false;
    }

    public static boolean setButtonForPanel(String title, EditContext editContext, SlingHttpServletRequest request, String currentPanelPath, String bindRef, String handler, Integer index) {
        Toolbar tb;
        EditConfig editConfig;
        if (editContext != null && (editConfig = editContext.getEditConfig()) != null && (tb = editConfig.getToolbar()) != null) {
            if (index == null) {
                index = tb.size();
            }
            if (title != null) {
                tb.add(index.intValue(), (Toolbar.Item)new Toolbar.Separator());
                tb.add(index + 1, (Toolbar.Item)new Toolbar.Button(title, handler));
            }
            return true;
        }
        return false;
    }

    public static void putQueryParamsToRedirectRequest(String responseString, Map<String, String> redirectParameters) {
        try {
            String[] pairs = responseString.split("&");
            for (int i = 0; i < pairs.length; ++i) {
                String[] fields = pairs[i].split("=");
                if (fields.length != 2) continue;
                String name = URLDecoder.decode(fields[0].trim(), "UTF-8");
                String value = URLDecoder.decode(fields[1].trim(), "UTF-8");
                redirectParameters.put(name, value);
            }
        }
        catch (Exception e) {
            logger.error("Error while putting params to redirect Request", (Throwable)e);
        }
    }

    public static double parseSize(String size) {
        if (size.indexOf("in") >= 0 || size.indexOf("mm") >= 0 || size.indexOf("cm") >= 0 || size.indexOf("pt") >= 0 || size.indexOf("px") >= 0) {
            return Double.parseDouble(size.substring(0, size.length() - 2));
        }
        return 1.0;
    }

    public static double convertToPx(String size) {
        Double pxSize = Double.parseDouble(size.substring(0, size.length() - 2));
        if (size.indexOf("in") >= 0) {
            pxSize = GuideUtils.mm2px(pxSize * 25.4);
        } else if (size.indexOf("mm") >= 0) {
            pxSize = GuideUtils.mm2px(pxSize);
        } else if (size.indexOf("cm") >= 0) {
            pxSize = GuideUtils.mm2px(pxSize * 10.0);
        } else if (size.indexOf("pt") >= 0) {
            pxSize = pxSize * 2.0;
        }
        return pxSize;
    }

    public static double mm2px(double mmSize) {
        double mm2in = 0.03937007874015748;
        double pxSize = mmSize * mm2in * 144.0;
        return pxSize;
    }

    public static String getOrGenerateUniqueName(String localName, HashMap<String, Integer> nameCountMap) {
        String normalizedName = localName.replace('.', '_');
        if (nameCountMap.containsKey(normalizedName)) {
            int countName = nameCountMap.get(normalizedName) + 1;
            nameCountMap.put(normalizedName, countName);
            normalizedName = normalizedName + "_" + countName;
        } else {
            nameCountMap.put(normalizedName, 0);
        }
        return normalizedName;
    }

    public static JSONObject trimLazyChildren(String guideJsonString) {
        JSONObject trimmedGuideJson = null;
        try {
            trimmedGuideJson = new JSONObject(guideJsonString);
            GuideUtils.trimJsonOfLazyInstances(trimmedGuideJson);
        }
        catch (Exception e) {
            logger.error("Could not trim children", (Throwable)e);
        }
        return trimmedGuideJson;
    }

    private static void trimJsonOfLazyInstances(JSONObject jsonObject) {
        try {
            if (jsonObject.has("optimizeRenderPerformance")) {
                if (jsonObject.has("items")) {
                    jsonObject.remove("items");
                }
            } else if (jsonObject.has("rootPanel")) {
                GuideUtils.trimJsonOfLazyInstances(jsonObject.getJSONObject("rootPanel"));
            } else if (jsonObject.has("items")) {
                JSONObject itemsNode = jsonObject.getJSONObject("items");
                Iterator keys = itemsNode.keys();
                while (keys.hasNext()) {
                    String key = (String)keys.next();
                    JSONObject childItem = itemsNode.getJSONObject(key);
                    GuideUtils.trimJsonOfLazyInstances(childItem);
                }
            }
        }
        catch (Exception e) {
            logger.error("Some exception while removing on demand children", (Throwable)e);
        }
    }

    private static String findJsonObjectWithProperty(JSONObject jsonObject, String propertyName, String propertyValue, String path, boolean ignorePath) {
        String stringifiedResult;
        block7 : {
            stringifiedResult = "";
            try {
                if (jsonObject.has(propertyName) && propertyValue.equals(jsonObject.getString(propertyName)) && (ignorePath || path.equals(jsonObject.get("jcr:path")))) {
                    JSONObject itemsNode = jsonObject.getJSONObject("items");
                    Iterator keys = itemsNode.keys();
                    while (keys.hasNext()) {
                        String key = (String)keys.next();
                        JSONObject childItem = itemsNode.getJSONObject(key);
                        GuideUtils.trimJsonOfLazyInstances(childItem);
                    }
                    return jsonObject.toString();
                }
                if (jsonObject.has("rootPanel")) {
                    return GuideUtils.findJsonObjectWithProperty(jsonObject.getJSONObject("rootPanel"), propertyName, propertyValue, path, ignorePath);
                }
                if (jsonObject.has("items")) {
                    JSONObject itemsNode = jsonObject.getJSONObject("items");
                    Iterator keys = itemsNode.keys();
                    while (keys.hasNext()) {
                        String key = (String)keys.next();
                        JSONObject childItem = itemsNode.getJSONObject(key);
                        stringifiedResult = stringifiedResult + GuideUtils.findJsonObjectWithProperty(childItem, propertyName, propertyValue, path, ignorePath);
                    }
                    break block7;
                }
                return "";
            }
            catch (Exception e) {
                logger.error("Error while fetching json for " + propertyValue, (Throwable)e);
            }
        }
        return stringifiedResult;
    }

    public static String findJsonObjectWithProperty(JSONObject jsonObject, String propertyName, String propertyValue, String path) {
        return GuideUtils.findJsonObjectWithProperty(jsonObject, propertyName, propertyValue, path, Boolean.FALSE);
    }

    public static String getAssetHTMLFromFullHTML(String templateId, String html) {
        return GuideHTMLParser.getAssetHTMLFromFullHTML(html, templateId);
    }

    public static String formJsonHtmlString(String json, String html) {
        StringWriter stringWriter = new StringWriter();
        CustomJSONWriter jsonWriter = new CustomJSONWriter(stringWriter);
        jsonWriter.object();
        jsonWriter.key("json").value(json);
        jsonWriter.key("html").value(html);
        jsonWriter.endObject();
        return stringWriter.toString();
    }

    public static String getLayoutScriptFromContainer(GuideContainer guideContainer) {
        String script = guideContainer.getLayout();
        Resource scriptResource = GuideUtils.getResolverFromResource(guideContainer).getResource(script);
        String scriptPath = scriptResource != null ? scriptResource.getPath() : "/libs/" + script;
        script = scriptPath + "/" + org.apache.commons.lang3.StringUtils.substringAfterLast((String)script, (String)"/") + ".jsp";
        return script;
    }

    public static String produceHTML(GuideContainer guideContainer, SlingHttpServletResponse slingHttpServletResponse) {
        String script = GuideUtils.getLayoutScriptFromContainer(guideContainer);
        SlingHttpServletRequest slingRequest = guideContainer.getSlingRequest();
        try {
            String guideContainerPath = guideContainer.getPath();
            String urlToRootPanel = guideContainerPath + "/" + "rootPanel" + "." + "html";
            RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(urlToRootPanel);
            WCMMode.DISABLED.toRequest((ServletRequest)slingRequest);
            GuideStringWriterResponse responseWrapper = new GuideStringWriterResponse(slingHttpServletResponse);
            dispatcher.include((ServletRequest)new SlingHttpServletRequestWrapper(slingRequest), (ServletResponse)responseWrapper);
            return responseWrapper.getString();
        }
        catch (Exception e) {
            logger.error("Error while executing script " + script, (Throwable)e);
            return null;
        }
    }

    public static String getJsonObjectWithGivenTemplateIds(JSONObject guideJsonObject, JSONArray jsonArray) {
        try {
            JSONObject jsonObject = new JSONObject();
            for (int index = 0; index < jsonArray.length(); ++index) {
                JSONObject newGuideJsonObject = new JSONObject(guideJsonObject.toString());
                String templateId = jsonArray.getString(index);
                jsonObject.put(templateId, (Object)GuideUtils.findJsonObjectWithProperty(newGuideJsonObject, "templateId", templateId, "", Boolean.TRUE));
            }
            return jsonObject.toString();
        }
        catch (Exception e) {
            logger.error("Could not for json object with the given template ids", (Throwable)e);
            return null;
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static String getScriptAsStringFromClientLib(HtmlLibraryManager htmlLibraryManager, String clientLibPath) {
        StringWriter writer = new StringWriter();
        InputStream inputStream = null;
        try {
            inputStream = htmlLibraryManager.getLibrary(LibraryType.JS, clientLibPath).getInputStream();
            IOUtils.copy((InputStream)inputStream, (Writer)writer);
        }
        catch (IOException ex) {
            logger.error(ex.getMessage(), (Throwable)ex);
        }
        finally {
            IOUtils.closeQuietly((InputStream)inputStream);
        }
        return writer.toString();
    }

    public static ArrayList<String> getScriptFromClientLibList(HtmlLibraryManager htmlLibraryManager, String[] clientLibCategories) {
        Collection clientLibrary = htmlLibraryManager.getLibraries(clientLibCategories, null, true, false);
        ArrayList<String> script = new ArrayList<String>();
        Iterator iter = clientLibrary.iterator();
        while (iter.hasNext()) {
            String path = ((ClientLibrary)iter.next()).getPath();
            script.add(GuideUtils.getScriptAsStringFromClientLib(htmlLibraryManager, path));
        }
        return script;
    }

    public static JSONObject getDictionaryInfoFromAssetPaths(JSONArray assetList, List<String> locales) {
        JSONObject dictionaryInfo = new JSONObject();
        JSONArray dictInfoArray = new JSONArray();
        try {
            for (String locale : locales) {
                JSONObject localeObject = new JSONObject();
                localeObject.put("lang", (Object)locale);
                JSONArray pathArray = new JSONArray();
                for (int index = 0; index < assetList.length(); ++index) {
                    String path = assetList.getString(index);
                    String convertedPath = GuideUtils.convertContainerPathToDictionaryPath(path, locale);
                    if (!org.apache.commons.lang3.StringUtils.isNotEmpty((CharSequence)convertedPath)) continue;
                    pathArray.put((Object)convertedPath);
                }
                localeObject.put("dicts", (Object)pathArray);
                dictInfoArray.put((Object)localeObject);
            }
            dictionaryInfo.put("languages", (Object)dictInfoArray);
        }
        catch (Exception e) {
            logger.error("Could not create dictionary paths", (Throwable)e);
        }
        return dictionaryInfo;
    }

    private static String convertContainerPathToDictionaryPath(String containerPath, String locale) {
        if (org.apache.commons.lang3.StringUtils.isNotEmpty((CharSequence)containerPath) && org.apache.commons.lang3.StringUtils.isNotEmpty((CharSequence)locale)) {
            return containerPath + "/" + "assets" + "/" + "dictionary" + "/" + locale;
        }
        return null;
    }

    public static Boolean listContains(List<String> list, String searchString, Boolean ignoreCase) {
        if (searchString != null && list != null) {
            if (!ignoreCase.booleanValue()) {
                return list.contains(searchString);
            }
            for (String str : list) {
                if (!searchString.equalsIgnoreCase(str)) continue;
                return Boolean.TRUE;
            }
        }
        return Boolean.FALSE;
    }

    public static SlingBindings getSlingBinding(SlingHttpServletRequest slingRequest) {
        SlingBindings bindings = null;
        if (slingRequest != null) {
            bindings = (SlingBindings)slingRequest.getAttribute(SlingBindings.class.getName());
        }
        return bindings;
    }

    public static boolean checkIfForms(Resource resource) {
        Resource guideContainer;
        Resource pageContent = resource.getChild("jcr:content");
        if (pageContent != null && (guideContainer = pageContent.getChild("guideContainer")) != null) {
            return GuideConstants.CONTAINER_RESOURCES.contains(guideContainer.getResourceType());
        }
        return false;
    }

    public static boolean checkIfFormsTemplate(Resource resource) {
        String guideComponentType;
        ValueMap templateContentValueMap;
        Resource templateContent = resource.getChild("jcr:content");
        if (templateContent != null && (guideComponentType = (String)(templateContentValueMap = templateContent.getValueMap()).get("guideComponentType", (Object)"")) != null && guideComponentType.length() > 0) {
            return true;
        }
        return false;
    }

    public static boolean isRepeatablePanel(JSONObject obj) {
        if ("guidePanel".equals(obj.optString("guideNodeClass"))) {
            Integer maxOccur = obj.optInt("maxOccur", 1);
            Integer minOccur = obj.optInt("minOccur", 1);
            return minOccur != 1 || maxOccur != 1;
        }
        return false;
    }

    public static boolean isCompositeField(JSONObject obj) {
        String objType = obj.optString("guideNodeClass", "");
        return GuideConstants.GUIDE_COMPOSITE_FIELD_TYPES.contains(objType);
    }

    public static FileAttachmentWrapper findFileAttachment(List<FileAttachmentWrapper> attachmentWrappers, String fileName) {
        if (attachmentWrappers != null) {
            for (FileAttachmentWrapper fileAttachmentWrapper : attachmentWrappers) {
                if (!org.apache.commons.lang3.StringUtils.equals((CharSequence)fileAttachmentWrapper.getFileName(), (CharSequence)fileName)) continue;
                return fileAttachmentWrapper;
            }
        }
        return null;
    }

    public static Resource getFormResource(Resource otherResource, String fragRef) {
        if (org.apache.commons.lang3.StringUtils.isNotBlank((CharSequence)fragRef) && otherResource != null) {
            String path = GuideUtils.convertFMAssetPathToContainerPath(fragRef);
            ResourceResolver resolver = otherResource.getResourceResolver();
            return resolver.getResource(path);
        }
        return null;
    }

    public static JSONObject getFormJson(Resource formRes, GuideModelTransformer guideModelTransformer) {
        JSONObject guideJson = null;
        try {
            guideJson = guideModelTransformer.exportGuideJsonObject(formRes);
        }
        catch (GuideException e) {
            logger.error("Failed to Fetch Form Json", (Throwable)e);
        }
        return guideJson;
    }

    private static Resource findGuideContainerFromPage(Resource resource) {
        if (resource == null) {
            return null;
        }
        if (GuideUtils.isGuideContainerResource(resource)) {
            return resource;
        }
        Resource r = null;
        Iterator t = resource.listChildren();
        while (t.hasNext() && r == null) {
            Resource child = (Resource)t.next();
            if (child != null && GuideUtils.isGuideContainerResource(resource)) {
                return child;
            }
            r = GuideUtils.findGuideContainerFromPage(child);
        }
        return r;
    }

    public static String getGuideContainerPathFromResource(SlingHttpServletRequest request, Resource resource) {
        Resource parent;
        for (parent = resource.getParent(); parent != null && !parent.getResourceType().equals("cq:Page"); parent = parent.getParent()) {
        }
        Resource currentResource = parent;
        Resource GuideContainer2 = GuideUtils.findGuideContainerFromPage(currentResource);
        return GuideContainer2.getPath();
    }
}