LCFormsServiceImpl.java 7.4 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.ui.clientlibs.HtmlLibraryManager
 *  com.adobe.granite.ui.clientlibs.LibraryType
 *  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
 */
package com.adobe.forms.service.impl;

import com.adobe.forms.external.service.FormsContext;
import com.adobe.forms.option.LCFormsOptions;
import com.adobe.forms.service.LCFormsOptionService;
import com.adobe.forms.service.LCFormsOsgiService;
import com.adobe.forms.service.LCFormsService;
import com.adobe.granite.ui.clientlibs.HtmlLibraryManager;
import com.adobe.granite.ui.clientlibs.LibraryType;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
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;

@Component(label="LC Forms Service", description="LC Forms Service")
@Service(value={LCFormsService.class})
@Properties(value={@Property(name="service.description", value={"LC Forms Service"})})
public class LCFormsServiceImpl
implements LCFormsService {
    @Reference
    private LCFormsOsgiService lcFormsOsgiService;
    @Reference
    private FormsContext formsContext;
    @Reference
    private HtmlLibraryManager htmlLibraryManager;
    @Reference
    LCFormsOptionService lcFormsOptionService;

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public Map<String, Object> render(SlingHttpServletRequest slingRequest) {
        try {
            this.formsContext.begin();
            LCFormsOptions options = this.lcFormsOptionService.createFromRequest(slingRequest);
            Map<String, Object> contentMap = this.lcFormsOsgiService.render(options);
            for (Map.Entry<String, Object> entry : contentMap.entrySet()) {
                slingRequest.setAttribute(entry.getKey(), entry.getValue());
            }
            Map<String, Object> i$ = contentMap;
            return i$;
        }
        finally {
            this.formsContext.end();
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public Map<String, Object> render(LCFormsOptions options) {
        try {
            Map<String, Object> contentMap;
            this.formsContext.begin();
            Map<String, Object> map = contentMap = this.lcFormsOsgiService.render(options);
            return map;
        }
        finally {
            this.formsContext.end();
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public Map<String, Object> exportXFA(SlingHttpServletRequest slingRequest) {
        try {
            this.formsContext.begin();
            LCFormsOptions options = this.lcFormsOptionService.createFromRequest(slingRequest);
            Map<String, Object> contentMap = this.lcFormsOsgiService.exportXFA(options);
            for (Map.Entry<String, Object> entry : contentMap.entrySet()) {
                slingRequest.setAttribute(entry.getKey(), entry.getValue());
            }
            Map<String, Object> i$ = contentMap;
            return i$;
        }
        finally {
            this.formsContext.end();
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public Map<String, Object> exportXFA(LCFormsOptions options) {
        try {
            Map<String, Object> contentMap;
            this.formsContext.begin();
            Map<String, Object> map = contentMap = this.lcFormsOsgiService.exportXFA(options);
            return map;
        }
        finally {
            this.formsContext.end();
        }
    }

    @Override
    public void clearCache() {
        this.lcFormsOsgiService.clearCache();
    }

    @Override
    public String getClientLibNameForCurrentLocale(SlingHttpServletRequest slingRequest) {
        String clientLibPrefix = "xfaforms.I18N";
        String defaultLocale = "en";
        String acceptLang = slingRequest.getHeader("accept-language");
        String localeCode = null;
        if (acceptLang == null || "".equals(acceptLang.trim())) {
            return clientLibPrefix + "." + defaultLocale;
        }
        String[] locales = StringUtils.split((String)acceptLang, (String)",");
        for (int i = 0; i < locales.length; ++i) {
            boolean clientLibForLocaleExists;
            Collection libraries;
            String[] categories;
            localeCode = StringUtils.substringBefore((String)locales[i], (String)";");
            String[] splitLocale = StringUtils.split((String)localeCode, (String)"-");
            localeCode = splitLocale[0].toLowerCase();
            if (splitLocale.length > 1) {
                localeCode = localeCode + splitLocale[1].toUpperCase();
            }
            boolean bl = clientLibForLocaleExists = (libraries = this.htmlLibraryManager.getLibraries(categories = new String[]{clientLibPrefix + "." + localeCode}, null, true, false)).toArray().length > 0;
            if (clientLibForLocaleExists) {
                return clientLibPrefix + "." + localeCode;
            }
            if (splitLocale.length <= 1) continue;
            categories = new String[]{clientLibPrefix + "." + splitLocale[0].toLowerCase()};
            libraries = this.htmlLibraryManager.getLibraries(categories, null, true, false);
            boolean bl2 = clientLibForLocaleExists = libraries.toArray().length > 0;
            if (!clientLibForLocaleExists) continue;
            return clientLibPrefix + "." + splitLocale[0].toLowerCase();
        }
        return clientLibPrefix + "." + defaultLocale;
    }

    protected void bindLcFormsOsgiService(LCFormsOsgiService lCFormsOsgiService) {
        this.lcFormsOsgiService = lCFormsOsgiService;
    }

    protected void unbindLcFormsOsgiService(LCFormsOsgiService lCFormsOsgiService) {
        if (this.lcFormsOsgiService == lCFormsOsgiService) {
            this.lcFormsOsgiService = null;
        }
    }

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

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

    protected void bindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
        this.htmlLibraryManager = htmlLibraryManager;
    }

    protected void unbindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
        if (this.htmlLibraryManager == htmlLibraryManager) {
            this.htmlLibraryManager = null;
        }
    }

    protected void bindLcFormsOptionService(LCFormsOptionService lCFormsOptionService) {
        this.lcFormsOptionService = lCFormsOptionService;
    }

    protected void unbindLcFormsOptionService(LCFormsOptionService lCFormsOptionService) {
        if (this.lcFormsOptionService == lCFormsOptionService) {
            this.lcFormsOptionService = null;
        }
    }
}