All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.forms.common.utils.XFAUtils Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2017 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.adobe.forms.common.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import com.adobe.forms.common.utils.FormsConstants;
import org.apache.sling.api.resource.ValueMap;

public class XFAUtils {

    /**
     * Checks whethter the provided resource is of forms manager
     *
     * @param resource
     * @return whether provided resource is of forms manager
     * @pad.exclude Exclude from Published API.
     **/
    public static boolean isResourceFormsManager (Resource resource) {
        if (resource != null) {
            String resourceType = resource.getResourceType();
            return  (StringUtils.isNotBlank(resourceType) && resourceType.equals(FormsConstants.FORMS_MANAGER_RESOURCE_TYPE));
        }
        return false;
    }
    /**
     * Retturn the request attribute
     *
     * @param slingRequest, param
     * @return returns the attribute of the provided slingRequest
     * @pad.exclude Exclude from Published API.
     **/
    public static String getRequestAttribute (SlingHttpServletRequest slingRequest, String param) {
        Object valObj = slingRequest.getAttribute("submitUrl");
        String value = "";
        if(valObj != null && valObj instanceof String) {
            value = (String) valObj;
        }
        return value;
    }

    /**
     * Return the forms manager resource
     *
     * @param slingRequest, contentRoot, template
     * @return formsManagerResource
     * @pad.exclude Exclude from Published API.
     **/
    public static Resource getFormsManagerResource (SlingHttpServletRequest slingRequest, String contentRoot, String template) {
        Resource formManagerResource = null;
        if (StringUtils.isNotBlank(contentRoot) && StringUtils.isNotBlank(template)) {
            String resourcePath = contentRoot.replace(FormsConstants.PROTOCOL_CRX, "") + "/" + template;
            Resource resource = slingRequest.getResourceResolver().getResource(resourcePath);
            if (resource != null) {
                formManagerResource = resource.getChild(FormsConstants.JCR_CONTENT);
            }
        }
        return formManagerResource;
    }

    /**
     * returns the submitUrl based on submitUrl present at parameter and attribute
     * @param slingRequest, contentRoot, template
     * @return submitUrl
     * @pad.exclude Exclude from Published API.
     **/
    public static String getSubmitUrl(SlingHttpServletRequest slingRequest, String contentRoot, String template) {
        String formsManagerSubmitUrl = null;
        Resource formManagerResource = getFormsManagerResource(slingRequest, contentRoot, template);
        String submitUrlParameter = slingRequest.getParameter(FormsConstants.SUBMIT_URL);
        String submitUrlAttribute = getRequestAttribute(slingRequest, FormsConstants.SUBMIT_URL);
        String submitUrl = "";
        if (isResourceFormsManager(formManagerResource)) {
            ValueMap managerProperties = formManagerResource.getChild(FormsConstants.METADATA).adaptTo(ValueMap.class);
            formsManagerSubmitUrl = managerProperties.get(FormsConstants.SUBMIT_URL, "");
        }
        // if submitUrl in attribute is same as one present at forms manager then we can pick it from node on submission
        if (StringUtils.isNotBlank(submitUrlAttribute) && !submitUrlAttribute.equals(formsManagerSubmitUrl)) {
            submitUrl = submitUrlAttribute;
        } else if (StringUtils.isNotBlank(submitUrlParameter)) {
            submitUrl = submitUrlParameter;
        }
        return submitUrl;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy