LCFormsAdminServiceImpl.java 9.65 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyOption
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.commons.osgi.OsgiUtil
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  scala.Option
 */
package com.adobe.forms.admin.impl;

import com.adobe.forms.admin.LCFormsAdminService;
import com.adobe.forms.cache.LCFormsCacheConfig;
import com.adobe.forms.cache.impl.CacheConfigParam;
import com.adobe.forms.service.LCFormsOsgiService;
import com.adobe.forms.service.impl.LCFormsOptionServiceImpl;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyOption;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.Option;

@Component(label="Mobile Forms Configurations", description="Mobile Forms Configurations", metatype=1, immediate=1)
@Service(value={LCFormsAdminService.class, LCFormsCacheConfig.class})
public class LCFormsAdminServiceImpl
implements LCFormsAdminService,
LCFormsCacheConfig {
    private static Logger logger = LoggerFactory.getLogger(LCFormsAdminServiceImpl.class);
    private static final String CACHE_STRATEGY_NONE = "none";
    private static final String CACHE_STRATEGY_CONSERVATIVE = "conservative";
    private static final String CACHE_STRATEGY_AGGRESIVE = "aggressive";
    @Property(value={"aggressive"}, label="Caching Strategy", description="Caching Strategy", options={@PropertyOption(name="none", value="None"), @PropertyOption(name="conservative", value="Conservative"), @PropertyOption(name="aggressive", value="Aggressive")})
    private static final String CACHE_STRATEGY = "lcforms.cache.strategy";
    private String cacheStrategy;
    private static final String CACHE_SIZE_DEFAULT = "128";
    @Property(value={"128"}, label="Cache Size in terms of number of forms (128)", description="Number of forms to cache in-memory")
    private static final String MAX_CACHE_SIZE = "lcforms.cache.unit";
    private Long cacheSize;
    private static final String MAX_OBJECT_SIZE_DEFAULT = "8M";
    @Property(value={"8M"}, label="Max Object Size to be cached(8M)", description="Max Object Size limit to be cached")
    private static final String MAX_CACHE_OBJECT_SIZE = "lcforms.cache.maxObjectSize";
    private String maxObjectSize;
    @Property(value={""}, label="Debug Options", description="Options for enabling debugging. e.g.: 1-a5-b5-c5")
    private static final String DEBUG_OPTIONS = "lcforms.debug.debugOptions";
    private String debugOptions = "";
    @Property(boolValue={0}, label="Allow debug parameters in request", description="If enabled, HTML5 Forms would start honoring debugDir & log parameters")
    private static final String ALLOW_DEBUG_PARAMETERS = "lcforms.debug.allowDebugParameters";
    private boolean allowDebugParameters = false;
    private static final String DefaultLevel = "2";
    private static final String[] LoggerType = new String[]{"off", "console", "server", "consoleServer"};
    private static final String[] Category = new String[]{"a", "b", "c"};
    @Property(boolValue={1}, label="Embed Http/Https Images", description="select the option to embed Http/Https images using the data scheme instead of the http/https url in html")
    private static final String EMBED_HTTP_IMAGES = "lcforms.model.embedHttpImages";
    private boolean embedHttpImages = true;
    private LCFormsOsgiService lcFormsOsgiService;
    @Property(boolValue={0}, label="Keep Data Description", description="select the option to keep the dataDescription Tag in dataXML. This will increase the size of dataxml")
    private static final String KEEP_DATA_DESCRIPTION_OPTION = "lcforms.data.keepDataDescription";
    private boolean keepDataDescription = false;
    @Property(boolValue={1}, label="Protected Mode", description="select the option to enable protected mode")
    private static final String PROTECTED_MODE_OPTION = "lcforms.data.protectedMode";
    private boolean protectedMode = true;
    private static final String LOGGING_LEVEL_XFA = "xfaLevel";
    private static final String LOGGING_LEVEL_VIEW = "xfaViewLevel";
    private static final String LOGGING_LEVEL_PERF = "xfaPerfLevel";
    private static final String LOGGING_ENABLED = "loggingEnabled";
    private static final String LOGGER_TYPE = "loggerType";
    private static final String CATEGORY_XFA = "a";
    private static final String CATEGORY_VIEW = "b";
    private static final String CATEGORY_PERF = "c";

    @Override
    public String getCacheStrategy() {
        return this.cacheStrategy;
    }

    private String getOrElse(Option<String> option, String defaultVal) {
        if (option.isDefined()) {
            return (String)option.get();
        }
        return defaultVal;
    }

    @Deprecated
    @Override
    public String getOriginalVersion() {
        return "";
    }

    protected void activate(ComponentContext context) {
        Dictionary props = context.getProperties();
        String newCacheStrategy = OsgiUtil.toString(props.get("lcforms.cache.strategy"), (String)"aggressive");
        String oldCacheStrategy = this.getCacheStrategy();
        if ("none".equalsIgnoreCase(newCacheStrategy) && !newCacheStrategy.equalsIgnoreCase(oldCacheStrategy) && this.lcFormsOsgiService != null) {
            this.lcFormsOsgiService.clearCache();
        }
        this.cacheStrategy = newCacheStrategy;
        this.cacheSize = OsgiUtil.toLong(props.get("lcforms.cache.unit"), (long)Long.parseLong("128"));
        this.maxObjectSize = this.getOrElse(CacheConfigParam.getValidSize(OsgiUtil.toString(props.get("lcforms.cache.maxObjectSize"), (String)"8M")), "8M");
        this.debugOptions = OsgiUtil.toString(props.get("lcforms.debug.debugOptions"), (String)"");
        this.keepDataDescription = OsgiUtil.toBoolean(props.get("lcforms.data.keepDataDescription"), (boolean)false);
        this.embedHttpImages = OsgiUtil.toBoolean(props.get("lcforms.model.embedHttpImages"), (boolean)true);
        this.allowDebugParameters = OsgiUtil.toBoolean(props.get("lcforms.debug.allowDebugParameters"), (boolean)false);
        this.protectedMode = PropertiesUtil.toBoolean(props.get("lcforms.data.protectedMode"), (boolean)true);
    }

    @Override
    public long getCacheSize() {
        return this.cacheSize;
    }

    @Override
    public String getMaxObjectSize() {
        return this.maxObjectSize;
    }

    private String readValue(String splitParam, String category) {
        if (splitParam != null && splitParam.startsWith(category)) {
            return splitParam.substring(category.length());
        }
        return null;
    }

    @Override
    public void setupLogging(SlingHttpServletRequest slingRequest) {
        if (slingRequest == null) {
            throw new IllegalArgumentException();
        }
        String logParam = LCFormsOptionServiceImpl.getAttributeOrRequestParam(slingRequest, "log", this);
        if (logParam == null || "".equals(logParam.trim())) {
            logParam = this.debugOptions;
        }
        slingRequest.setAttribute("xfaLevel", (Object)"2");
        slingRequest.setAttribute("xfaViewLevel", (Object)"2");
        slingRequest.setAttribute("xfaPerfLevel", (Object)"2");
        slingRequest.setAttribute("loggingEnabled", (Object)"false");
        int level = 1;
        String loggerType = LoggerType[level];
        slingRequest.setAttribute("loggerType", (Object)loggerType);
        if (logParam != null && !"".equals(logParam.trim())) {
            slingRequest.setAttribute("loggingEnabled", (Object)"true");
            String[] splitParams = logParam.split("-");
            if (splitParams.length >= 1) {
                try {
                    level = Integer.parseInt(splitParams[0]);
                }
                catch (Exception e) {
                    logger.debug("Error parsing logParam: " + logParam, (Throwable)e);
                }
                loggerType = LoggerType[level];
            }
            slingRequest.setAttribute("loggerType", (Object)loggerType);
            for (int i = 1; i < splitParams.length; ++i) {
                String xfaLevel = this.readValue(splitParams[i], "a");
                if (xfaLevel == null) {
                    String xfaViewLevel = this.readValue(splitParams[i], "b");
                    if (xfaViewLevel == null) {
                        String xfaPerfLevel = this.readValue(splitParams[i], "c");
                        if (xfaPerfLevel == null) continue;
                        slingRequest.setAttribute("xfaPerfLevel", (Object)xfaPerfLevel);
                        continue;
                    }
                    slingRequest.setAttribute("xfaViewLevel", (Object)xfaViewLevel);
                    continue;
                }
                slingRequest.setAttribute("xfaLevel", (Object)xfaLevel);
            }
        }
    }

    @Override
    public boolean isKeepDataDescription() {
        return this.keepDataDescription;
    }

    @Override
    public boolean isEmbedHttpImages() {
        return this.embedHttpImages;
    }

    @Override
    public boolean isAllowDebugParameters() {
        return this.allowDebugParameters;
    }

    @Override
    public boolean isProtectedMode() {
        return this.protectedMode;
    }
}