GuideContainer.java 20.7 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
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.forms.common.service.FormsCommonConfigurationService
 *  com.adobe.forms.common.utils.TempStorageUtils
 *  com.day.cq.i18n.I18n
 *  javax.jcr.RepositoryException
 *  javax.servlet.http.HttpServletRequest
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.PersistenceException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.api.scripting.SlingBindings
 *  org.apache.sling.api.scripting.SlingScriptHelper
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 *  org.apache.sling.commons.json.io.JSONWriter
 *  org.slf4j.Logger
 */
package com.adobe.aemds.guide.common;

import com.adobe.aemds.guide.common.GuideItemsContainer;
import com.adobe.aemds.guide.common.GuideNode;
import com.adobe.aemds.guide.common.GuidePanel;
import com.adobe.aemds.guide.service.AdaptiveFormConfigurationService;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideIntegrationService;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.utils.GuideContainerThreadLocal;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.JSONCreationOptions;
import com.adobe.aemds.guide.utils.NodeStructureUtils;
import com.adobe.forms.common.service.FormsCommonConfigurationService;
import com.adobe.forms.common.utils.TempStorageUtils;
import com.day.cq.i18n.I18n;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import javax.jcr.RepositoryException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
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.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class GuideContainer
extends GuideNode {
    private GuideModelTransformer guideModelTransformer = null;
    private String defaultDataXml = null;
    private boolean renderCall = false;

    public GuideContainer() {
    }

    public GuideContainer(SlingHttpServletRequest request, Resource resource) {
        this.setResource(resource);
        this.setSlingRequest(request);
    }

    public GuideContainer(Resource resource) {
        this.setResource(resource);
    }

    public String getRedirect() {
        String redirect = (String)this.resourceProps.get("redirect", (Object)"");
        if (redirect.length() > 0) {
            int lastSlash = redirect.lastIndexOf(47);
            if (redirect.indexOf(46, lastSlash) == -1) {
                redirect = redirect + ".html";
            }
        } else {
            redirect = this.getPath() + "." + "guideThankYouPage.html";
        }
        return redirect;
    }

    public void setMaxCallCounter(SlingHttpServletRequest request) {
        AdaptiveFormConfigurationService adaptiveFormConfigurationService;
        boolean setSlingMaxCalls = false;
        SlingBindings slingBindings = GuideUtils.getSlingBinding(request);
        if (slingBindings != null && (adaptiveFormConfigurationService = (AdaptiveFormConfigurationService)slingBindings.getSling().getService(AdaptiveFormConfigurationService.class)) != null) {
            setSlingMaxCalls = adaptiveFormConfigurationService.isSlingMaxCallValueSmall();
        }
        if (setSlingMaxCalls && request.getAttribute("sling.max.calls") == null) {
            try {
                request.setAttribute("sling.max.calls", (Object)20000);
            }
            catch (Exception e) {
                this.logger.error("Cannot increase sling max call value", (Throwable)e);
            }
        }
    }

    @Override
    public Map<String, Object> getAuthoringConfig() {
        Map<String, Object> authoringConfig = super.getAuthoringConfig();
        String referredXsdOrXdp = "";
        try {
            if (!this.getXdpRef().equals("")) {
                referredXsdOrXdp = this.getXdpRef();
                authoringConfig.put("xdpRef", referredXsdOrXdp);
            } else if (!this.getXsdRef().equals("")) {
                referredXsdOrXdp = this.getXsdRef();
                authoringConfig.put("xsdRef", referredXsdOrXdp);
            }
        }
        catch (Exception e) {
            this.logger.error("AF: Unable to fetch xsdRef or xdpRef" + e.getMessage(), (Throwable)e);
        }
        return authoringConfig;
    }

    public String getXdpRef() {
        return (String)this.resourceProps.get("xdpRef", (Object)"");
    }

    public String getLetterRef() {
        return (String)this.resourceProps.get("letterRef", (Object)"");
    }

    public String getAutoSaveStrategyFilePath() {
        String autoSaveStrategyType = (String)this.resourceProps.get("autoSaveStrategyType", (Object)"");
        if (autoSaveStrategyType != null && !autoSaveStrategyType.isEmpty()) {
            return autoSaveStrategyType;
        }
        return null;
    }

    public String getDorTemplateRef() {
        return (String)this.resourceProps.get("dorTemplateRef", (Object)"");
    }

    public Calendar getLastModifiedTime() throws RepositoryException {
        ValueMap properties = (ValueMap)this.resource.getParent().adaptTo(ValueMap.class);
        return (Calendar)properties.get("cq:lastModified", Calendar.class);
    }

    public String getXsdRef() {
        return (String)this.resourceProps.get("xsdRef", (Object)"");
    }

    public String getCssFileRef() {
        return (String)this.resourceProps.get("cssFileRef", null);
    }

    @Override
    public String getClientLibRef() {
        return (String)this.resourceProps.get("clientLibRef", null);
    }

    public boolean isHasToolbar() {
        return this.resource.getChild("toolbar") != null;
    }

    public String getAfPath() {
        return (String)this.resourceProps.get("afPath", null);
    }

    public GuideItemsContainer getToolbar() {
        Resource toolbarResource = this.resource.getChild("toolbar");
        if (toolbarResource != null) {
            GuideItemsContainer guideItemsContainer = new GuideItemsContainer();
            guideItemsContainer.setResource(toolbarResource);
            guideItemsContainer.setSlingRequest(this.slingRequest);
            return guideItemsContainer;
        }
        return null;
    }

    public GuidePanel getRootPanel() {
        return GuideUtils.getRootPanel(this.resource, this.slingRequest);
    }

    public boolean isGuideSyncRequired() {
        boolean hasXDP = !"".equals(this.getXdpRef());
        return hasXDP && this.resourceProps.containsKey((Object)"formModelChanged");
    }

    public boolean isShowAuthoringWarnings() {
        String resourceType = GuideUtils.getNormalizedNodeType(this.getResourceType(), this.getResourceSuperType());
        boolean showWarnings = true;
        if ("fd/adaddon/components/guideDocumentContainer".equals(resourceType)) {
            showWarnings = false;
        }
        return showWarnings;
    }

    public String getStatusBarTitle() {
        I18n i18n = new I18n(this.slingRequest.getResourceBundle(this.slingRequest.getLocale()));
        return i18n.get("Adaptive Form Warnings");
    }

    public String getMobileLayout() {
        String returnLayout = "fd/af/layouts/mobile/simple";
        String mobileLayout = null;
        try {
            mobileLayout = (String)this.getLayoutProperty("mobileLayout");
        }
        catch (PersistenceException e) {
            this.logger.error("Exception while retrieving mobile layout. " + e.getMessage(), (Throwable)e);
        }
        if (mobileLayout != null && !mobileLayout.isEmpty()) {
            returnLayout = mobileLayout;
        }
        return returnLayout;
    }

    public Boolean getParseGridLayoutForMenu() {
        Boolean parseGridLayoutForMenu = null;
        try {
            parseGridLayoutForMenu = Boolean.valueOf(String.valueOf(this.getLayoutProperty("parseGridLayoutForMenu")));
        }
        catch (PersistenceException e) {
            this.logger.error("Exception while retrieving parseGridLayoutForMenu check. " + e.getMessage(), (Throwable)e);
        }
        if (parseGridLayoutForMenu == null) {
            parseGridLayoutForMenu = Boolean.FALSE;
        }
        return parseGridLayoutForMenu;
    }

    public String getXDPName() {
        String xdpRef = this.getXdpRef();
        if (xdpRef != null && xdpRef.length() > 0) {
            return StringUtils.substring((String)xdpRef, (int)(StringUtils.lastIndexOf((CharSequence)xdpRef, (CharSequence)"/") + 1));
        }
        return null;
    }

    public boolean isXDPValid() {
        return GuideUtils.isXDPValid(this.resource);
    }

    public void setGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
        this.guideModelTransformer = guideModelTransformer;
    }

    private GuideModelTransformer getGuideModelTransformer() {
        SlingBindings bindings = GuideUtils.getSlingBinding(this.getSlingRequest());
        if (bindings == null) {
            return this.guideModelTransformer;
        }
        return (GuideModelTransformer)bindings.getSling().getService(GuideModelTransformer.class);
    }

    private Map<String, String> getXfaJsonMap() throws GuideException {
        String xdpRef = this.getXdpRef();
        Map<String, String> xfaJsonMap = null;
        Boolean isValidXdp = xdpRef != null && xdpRef.length() > 0 && this.isXDPValid();
        if (isValidXdp.booleanValue()) {
            GuideModelTransformer guideModelTransformer = this.getGuideModelTransformer();
            xfaJsonMap = guideModelTransformer.exportXfaJson(this.resource);
        }
        return xfaJsonMap;
    }

    public String getXfaRenderContext() throws GuideException {
        Map<String, String> xfaJsonMap;
        String xdpRef = this.getXdpRef();
        String renderContext = "";
        if (xdpRef != null && xdpRef.length() > 0 && (xfaJsonMap = this.getXfaJsonMap()) != null && xfaJsonMap.containsKey("xfaRenderContext")) {
            renderContext = xfaJsonMap.get("xfaRenderContext");
        }
        return renderContext;
    }

    public String getXfaJson() throws GuideException {
        Map<String, String> xfaJsonMap;
        String xdpRef = this.getXdpRef();
        String xfaJson = "";
        if (xdpRef != null && xdpRef.length() > 0 && (xfaJsonMap = this.getXfaJsonMap()) != null && xfaJsonMap.containsKey("formdom")) {
            xfaJson = xfaJsonMap.get("formdom");
        }
        return xfaJson;
    }

    public String getGuideCurrentStateJson() {
        String guideStatePathRef;
        String guideCurrentStateJson = "";
        GuideModelTransformer guideModelTransformer = this.getGuideModelTransformer();
        String guideStatePath = (String)this.slingRequest.getAttribute("guideStatePath");
        if (guideStatePath == null || guideStatePath.isEmpty()) {
            guideStatePath = this.slingRequest.getParameter("guideStatePath");
        }
        if ((guideStatePathRef = (String)this.slingRequest.getAttribute("guideStatePathRef")) == null || guideStatePathRef.isEmpty()) {
            guideStatePathRef = this.slingRequest.getParameter("guideStatePathRef");
        }
        if (guideStatePath != null && !guideStatePath.isEmpty()) {
            guideCurrentStateJson = guideModelTransformer.exportGuideState(guideStatePath);
        } else if (guideStatePathRef != null && !guideStatePathRef.isEmpty()) {
            guideCurrentStateJson = guideModelTransformer.exportGuideStateFromStore(guideStatePathRef);
        }
        if (guideCurrentStateJson.length() == 0) {
            String prefillService;
            String data;
            boolean dataPresent = false;
            JSONCreationOptions options = new JSONCreationOptions();
            options.setI18n(this.i18n).setFormContainerPath(this.getFormContainerPath());
            String dataRef = (String)this.slingRequest.getAttribute("dataRef");
            if (dataRef == null || dataRef.isEmpty()) {
                dataRef = this.slingRequest.getParameter("dataRef");
            }
            if (dataRef != null && !dataRef.isEmpty()) {
                options.setDataRef(dataRef);
                dataPresent = true;
            }
            if ((data = (String)this.slingRequest.getAttribute("data")) == null || data.isEmpty()) {
                data = this.slingRequest.getParameter("data");
            }
            if (data != null && !data.isEmpty()) {
                options.setDataRef(null).setData(data);
                dataPresent = true;
            }
            if ((prefillService = (String)this.resourceProps.get((Object)"prefillService")) != null) {
                dataPresent = true;
            }
            if (dataPresent) {
                guideCurrentStateJson = guideModelTransformer.getDataJson(this.resource, options);
            }
        }
        return guideCurrentStateJson;
    }

    private String getFormContainerPath() {
        if (this.slingRequest == null) {
            return null;
        }
        String formContainerPath = (String)this.slingRequest.getAttribute("formContainerPath");
        if (formContainerPath == null) {
            formContainerPath = this.slingRequest.getParameter("formContainerPath");
        }
        return formContainerPath;
    }

    public String getGuideCurrentStateJson(String dataXml) {
        JSONCreationOptions options = new JSONCreationOptions();
        options.setData(dataXml).setI18n(this.i18n).setFormContainerPath(this.getFormContainerPath());
        return this.guideModelTransformer.getDataJson(this.resource, options);
    }

    public String getGuideContext() {
        return this.exportInitialGuideContext();
    }

    public String getGuideJson() {
        I18n i18ntemp = this.i18n;
        if (this.slingRequest != null && this.getIsEditMode().booleanValue()) {
            i18ntemp = null;
        }
        GuideModelTransformer guideModelTransformer = this.getGuideModelTransformer();
        return guideModelTransformer.exportGuideJson(this.resource, i18ntemp);
    }

    public String getLayout() {
        String layoutpath = "";
        try {
            Map<String, Object> layoutproperties = null;
            String containerName = GuideContainerThreadLocal.getGuideContainerName();
            layoutproperties = containerName != null ? NodeStructureUtils.getLayoutProperties(this.slingRequest, this.resource, containerName) : (GuideUtils.isGuideContainerResource(this.resource) ? NodeStructureUtils.getLayoutProperties(this.slingRequest, this.resource, this.resource.getName()) : NodeStructureUtils.getLayoutProperties(this.slingRequest, this.resource, "guideContainer"));
            layoutpath = (String)layoutproperties.get("sling:resourceType");
            if (layoutpath.startsWith("/libs/") || layoutpath.startsWith("/apps/")) {
                layoutpath = layoutpath.substring(6);
            }
        }
        catch (Exception ex) {
            this.logger.error("Unable to get layout of guide container" + ex.getMessage());
            throw new GuideException(ex.getMessage(), ex);
        }
        return layoutpath;
    }

    public List<String> getGuideIntegrationServiceScriptPaths() {
        SlingBindings bindings = (SlingBindings)this.slingRequest.getAttribute(SlingBindings.class.getName());
        GuideIntegrationService guideIntegrationService = (GuideIntegrationService)bindings.getSling().getService(GuideIntegrationService.class);
        return guideIntegrationService.getScriptPaths();
    }

    private String createGuideInitializationState(String dataXml, String locale) {
        StringWriter jsonStringWriter = new StringWriter();
        JSONWriter jsonWriter = new JSONWriter((Writer)jsonStringWriter);
        GuideModelTransformer guideTransformer = this.getGuideModelTransformer();
        Map<String, Object> jsonMap = guideTransformer.syncXfaProps(this, locale);
        try {
            jsonWriter.object();
            jsonWriter.key("guidejson").value((Object)((String)jsonMap.get("guidejson")));
            jsonWriter.key("guidecontext").value((Object)this.getGuideContext());
            String mergedJson = dataXml != null ? this.getGuideCurrentStateJson(dataXml) : this.getGuideCurrentStateJson();
            jsonWriter.key("guidemergedjson").value((Object)mergedJson);
            jsonWriter.key("xfajson").value((Object)((String)jsonMap.get("xfajson")));
            jsonWriter.key("xfarendercontext").value((Object)this.getXfaRenderContext());
            jsonWriter.endObject();
        }
        catch (JSONException ex) {
            this.logger.error("Error in getting guide initialization state" + ex.getMessage());
            throw new GuideException(ex.getMessage(), (Exception)ex);
        }
        return jsonStringWriter.toString();
    }

    public String getGuideInitializationState() {
        String locale = GuideUtils.getGuideRuntimeLocale(this.slingRequest, this.resource);
        return this.createGuideInitializationState(null, locale);
    }

    public String getGuideInitializationState(String dataXml, String locale) {
        return this.createGuideInitializationState(dataXml, locale);
    }

    public void setRenderCall(boolean isRenderCall) {
        this.renderCall = isRenderCall;
    }

    public boolean isRenderCall() {
        return this.renderCall;
    }

    public JSONObject getCustomContextPropJson(HttpServletRequest request) {
        Object attr = request.getAttribute("customContextProperty");
        JSONObject customContextPropJson = new JSONObject();
        if (attr != null) {
            try {
                customContextPropJson = new JSONObject(attr.toString());
            }
            catch (JSONException e) {
                this.logger.error("Failed to parse JSON for customContextProperty attribute", (Throwable)e);
            }
        }
        return customContextPropJson;
    }

    public String getPagePath() {
        String path = "";
        Resource parent = this.resource;
        while ((parent = parent.getParent()) != null) {
            if (!parent.isResourceType("foundation/components/page") && !parent.isResourceType("wcm/foundation/components/page")) continue;
            path = parent.getPath();
        }
        return path;
    }

    private String exportInitialGuideContext() throws GuideException {
        JSONObject contextObject = new JSONObject();
        try {
            SlingBindings bindings;
            SlingHttpServletRequest slingRequest;
            String guideName = this.getName();
            ValueMap guideProps = (ValueMap)this.getResource().adaptTo(ValueMap.class);
            contextObject.put("guidePath", (Object)this.getPath());
            contextObject.put("guideName", (Object)guideName);
            if (guideProps.containsKey((Object)"xsdRef")) {
                contextObject.put("xsdRef", guideProps.get("xsdRef", (Object)""));
            }
            if (guideProps.containsKey((Object)"xdpRef") && GuideUtils.isXDPValid(this.getResource())) {
                contextObject.put("xdpRef", guideProps.get("xdpRef", (Object)""));
            }
            if ((slingRequest = this.getSlingRequest()) != null && (bindings = GuideUtils.getSlingBinding(this.getSlingRequest())) != null) {
                FormsCommonConfigurationService formsCommonConfigurationService = (FormsCommonConfigurationService)bindings.getSling().getService(FormsCommonConfigurationService.class);
                AdaptiveFormConfigurationService adaptiveFormConfigurationService = (AdaptiveFormConfigurationService)bindings.getSling().getService(AdaptiveFormConfigurationService.class);
                boolean isAnonymous = slingRequest.getAuthType() == null;
                String tempStorageConfig = formsCommonConfigurationService.getTempStorageConfig();
                contextObject.put("disablePreview", TempStorageUtils.isPreviewDisabled((String)tempStorageConfig, (Boolean)isAnonymous));
                contextObject.put("makeFileNameUnique", (Object)adaptiveFormConfigurationService.getMakeFileNamesUnique());
                contextObject.put("scriptingBehaviourVersion", (Object)adaptiveFormConfigurationService.getScriptingCompatibilityMode());
            }
        }
        catch (Exception e) {
            this.logger.error("Error in getting guideContext", (Throwable)e);
            throw new GuideException(e);
        }
        return contextObject.toString();
    }
}