FormsServiceImpl.java 8.34 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.aemfd.docmanager.TempFileManager
 *  com.adobe.forms.external.service.FormsContext
 *  com.day.cq.dam.handler.gibson.fontmanager.FontManagerService
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.ReferenceCardinality
 *  org.apache.felix.scr.annotations.ReferencePolicy
 *  org.apache.felix.scr.annotations.Service
 */
package com.adobe.fd.forms.impl;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.aemfd.docmanager.TempFileManager;
import com.adobe.fd.forms.api.DataFormat;
import com.adobe.fd.forms.api.FormsService;
import com.adobe.fd.forms.api.PDFFormRenderOptions;
import com.adobe.fd.forms.api.ValidationOptions;
import com.adobe.fd.forms.api.ValidationResult;
import com.adobe.fd.forms.internal.ExportDataService;
import com.adobe.fd.forms.internal.FormValidationService;
import com.adobe.fd.forms.internal.ImportDataService;
import com.adobe.fd.forms.internal.RenderPDFFormService;
import com.adobe.fd.forms.internal.exception.FormsServiceException;
import com.adobe.fd.forms.internal.logging.FormsServiceLogger;
import com.adobe.fd.forms.internal.utils.ServiceUtil;
import com.adobe.forms.external.service.FormsContext;
import com.day.cq.dam.handler.gibson.fontmanager.FontManagerService;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;

@Component(label="AEMFD Forms Service", description="AEMFD Forms Service")
@Service(value={FormsService.class})
public class FormsServiceImpl
implements FormsService {
    private static FormsServiceLogger logger = new FormsServiceLogger(FormsServiceImpl.class);
    @Reference
    FormsContext formsContext;
    @Reference
    RenderPDFFormService renderPDFFormService;
    @Reference
    private ExportDataService exportDataService;
    @Reference
    private ImportDataService importDataService;
    @Reference
    private FormValidationService formValidationService;
    @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
    private FontManagerService fontManagerService;
    @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
    private TempFileManager tempFileManager;

    @Activate
    void activate() {
        ServiceUtil.setFontManagerService(this.fontManagerService);
        ServiceUtil.setTempFileManager(this.tempFileManager);
    }

    @Override
    public Document renderPDFForm(String urlOrfilename, Document data, PDFFormRenderOptions pdfFormRenderOptions) throws FormsServiceException {
        if (urlOrfilename == null || urlOrfilename.length() == 0) {
            throw new FormsServiceException("AEM_FRM_001_001", new Object[]{urlOrfilename, "urlOrfilename"});
        }
        if (pdfFormRenderOptions == null) {
            logger.warn("AEM_FRM_001_002", "pdfFormRenderOptions");
            pdfFormRenderOptions = new PDFFormRenderOptions();
        }
        try {
            this.formsContext.begin();
            Document document = this.renderPDFFormService.renderPDFForm(urlOrfilename, data, pdfFormRenderOptions);
            return document;
        }
        catch (Exception ioe) {
            throw new FormsServiceException("AEM_FRM_001_004", new Object[]{ioe.getMessage()}, ioe);
        }
        finally {
            this.formsContext.end();
        }
    }

    @Override
    public Document exportData(Document pdfOrXdp, DataFormat dataFormat) throws FormsServiceException {
        if (pdfOrXdp == null) {
            logger.error("AEM_FRM_001_002", "pdfOrXdp");
            throw new FormsServiceException("AEM_FRM_001_002", new Object[]{"pdfOrXdp"});
        }
        if (dataFormat == null) {
            logger.warn("AEM_FRM_001_002", "dataFormat");
            dataFormat = DataFormat.Auto;
        }
        return this.exportDataService.exportData(pdfOrXdp, dataFormat);
    }

    @Override
    public Document importData(Document doc, Document data) throws FormsServiceException {
        if (doc == null) {
            logger.error("AEM_FRM_001_002", "doc");
            throw new FormsServiceException("AEM_FRM_001_002", new Object[]{"doc"});
        }
        if (data == null) {
            logger.info("AEM_FRM_001_002", "data");
        }
        try {
            return this.importDataService.importData(doc, data);
        }
        catch (Exception e) {
            throw new FormsServiceException("AEM_FRM_001_004", new Object[]{e.getMessage()}, e);
        }
    }

    @Override
    public ValidationResult validate(String template, Document data, ValidationOptions validationOptions) throws FormsServiceException {
        if (data == null) {
            logger.error("AEM_FRM_001_002", "data");
            throw new FormsServiceException("AEM_FRM_001_002", new Object[]{"data"});
        }
        if (validationOptions == null) {
            logger.warn("AEM_FRM_001_002", "validationOptions");
            validationOptions = new ValidationOptions();
        }
        try {
            this.formsContext.begin();
            ValidationResult validationResult = this.formValidationService.validate(template, data, validationOptions);
            return validationResult;
        }
        catch (Exception e) {
            throw new FormsServiceException("AEM_FRM_001_004", new Object[]{e.getMessage()}, e);
        }
        finally {
            this.formsContext.end();
        }
    }

    protected void bindFontManagerService(FontManagerService paramFontManagerService) {
        this.fontManagerService = paramFontManagerService;
        ServiceUtil.setFontManagerService(this.fontManagerService);
    }

    protected void unbindFontManagerService(FontManagerService paramFontManagerService) {
        if (this.fontManagerService == paramFontManagerService) {
            this.fontManagerService = null;
        }
        ServiceUtil.setFontManagerService(this.fontManagerService);
    }

    protected void bindTempFileManager(TempFileManager paramTempFileManager) {
        this.tempFileManager = paramTempFileManager;
        ServiceUtil.setTempFileManager(this.tempFileManager);
    }

    protected void unbindTempFileManager(TempFileManager paramTempFileManager) {
        if (this.tempFileManager == paramTempFileManager) {
            this.tempFileManager = null;
        }
        ServiceUtil.setTempFileManager(this.tempFileManager);
    }

    protected void bindFormsContext(FormsContext formsContext) {
        this.formsContext = formsContext;
    }

    protected void unbindFormsContext(FormsContext formsContext) {
        if (this.formsContext == formsContext) {
            this.formsContext = null;
        }
    }

    protected void bindRenderPDFFormService(RenderPDFFormService renderPDFFormService) {
        this.renderPDFFormService = renderPDFFormService;
    }

    protected void unbindRenderPDFFormService(RenderPDFFormService renderPDFFormService) {
        if (this.renderPDFFormService == renderPDFFormService) {
            this.renderPDFFormService = null;
        }
    }

    protected void bindExportDataService(ExportDataService exportDataService) {
        this.exportDataService = exportDataService;
    }

    protected void unbindExportDataService(ExportDataService exportDataService) {
        if (this.exportDataService == exportDataService) {
            this.exportDataService = null;
        }
    }

    protected void bindImportDataService(ImportDataService importDataService) {
        this.importDataService = importDataService;
    }

    protected void unbindImportDataService(ImportDataService importDataService) {
        if (this.importDataService == importDataService) {
            this.importDataService = null;
        }
    }

    protected void bindFormValidationService(FormValidationService formValidationService) {
        this.formValidationService = formValidationService;
    }

    protected void unbindFormValidationService(FormValidationService formValidationService) {
        if (this.formValidationService == formValidationService) {
            this.formValidationService = null;
        }
    }
}