LetterJSONModelServlet.java 4.63 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.icc.dbforms.obj.Letter
 *  com.adobe.icc.dbforms.obj.LetterRenderOptionsSpec
 *  com.adobe.icc.ddg.api.LetterRenderService
 *  com.adobe.icc.render.obj.PDFResponseType
 *  com.adobe.icc.services.api.LetterService
 *  javax.servlet.ServletException
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.SlingHttpServletResponse
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.api.servlets.SlingAllMethodsServlet
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.fd.adaddon.internal.servlet;

import com.adobe.fd.adaddon.internal.utils.LetterToJsonTransformer;
import com.adobe.icc.dbforms.obj.Letter;
import com.adobe.icc.dbforms.obj.LetterRenderOptionsSpec;
import com.adobe.icc.ddg.api.LetterRenderService;
import com.adobe.icc.render.obj.PDFResponseType;
import com.adobe.icc.services.api.LetterService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(label="Letter Model Servlet", description="Letter Model Servlet")
@Service
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"fd/adaddon/components/guideDocumentContainer"}), @Property(name="sling.servlet.extensions", value={"lettermodeljson"})})
public class LetterJSONModelServlet
extends SlingAllMethodsServlet {
    private static final Logger log = LoggerFactory.getLogger(LetterJSONModelServlet.class);
    @Reference
    LetterService letterService;
    @Reference
    LetterRenderService letterRenderService;

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException {
        ValueMap vm;
        String letterRef = null;
        Resource guideContainer = request.getResource();
        if (guideContainer != null && (vm = (ValueMap)guideContainer.adaptTo(ValueMap.class)) != null) {
            letterRef = (String)vm.get((Object)"letterRef");
        }
        if (StringUtils.isBlank((CharSequence)letterRef)) {
            log.error("letterRef param is blank or is not provided");
            throw new ServletException("letterRef param is blank or is not provided, letterRef : " + letterRef);
        }
        Letter letter = this.letterService.getLetter(letterRef);
        LetterRenderOptionsSpec lros = new LetterRenderOptionsSpec();
        lros.setMergeDataOnServer(false);
        lros.setUseXFABullets(false);
        PDFResponseType pdfResponseType = this.letterRenderService.renderLetter(letter, null, lros);
        HashMap taFieldOrderMap = pdfResponseType.getTaFieldOrderMap();
        if (taFieldOrderMap == null) {
            log.error(" taFieldOrderMap is null " + taFieldOrderMap);
            taFieldOrderMap = new HashMap();
        }
        LetterToJsonTransformer jsonGenerator = new LetterToJsonTransformer(letter, taFieldOrderMap);
        String jsonString = jsonGenerator.getJsonString();
        response.setContentType("application/json");
        response.getWriter().write(jsonString);
    }

    protected void bindLetterService(LetterService letterService) {
        this.letterService = letterService;
    }

    protected void unbindLetterService(LetterService letterService) {
        if (this.letterService == letterService) {
            this.letterService = null;
        }
    }

    protected void bindLetterRenderService(LetterRenderService letterRenderService) {
        this.letterRenderService = letterRenderService;
    }

    protected void unbindLetterRenderService(LetterRenderService letterRenderService) {
        if (this.letterRenderService == letterRenderService) {
            this.letterRenderService = null;
        }
    }
}