AemDsSettingsServiceImpl.java 6.57 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.commons.io.FileUtils
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyOption
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.commons.osgi.OsgiUtil
 *  org.apache.sling.settings.SlingSettingsService
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.settings.internal;

import com.adobe.aemds.settings.AemDsSettingsService;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.felix.scr.annotations.Activate;
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.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.settings.SlingSettingsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Service
@Component(metatype=1, immediate=1, label="%settings.name", description="%settings.description")
public class AemDsSettingsServiceImpl
implements AemDsSettingsService {
    private static final String TEMP_FOLDER_TYPE_SYSTEM = "system";
    private static final String TEMP_FOLDER_TYPE_SLING = "sling";
    private static final String TEMP_FOLDER_TYPE_CUSTOM = "custom";
    @Property(value={"sling"}, options={@PropertyOption(name="system", value="%settings.tempfolder.type.system"), @PropertyOption(name="sling", value="%settings.tempfolder.type.sling"), @PropertyOption(name="custom", value="%settings.tempfolder.type.custom")})
    private static final String PROP_TEMP_FOLDER_TYPE = "settings.tempfolder.type";
    @Property
    private static final String PROP_TEMP_FOLDER_PATH = "settings.tempfolder.path";
    @Property(boolValue={1})
    private static final String PROP_TEMP_FOLDER_CLEAN = "settings.tempfolder.clean";
    private static final boolean PROP_FIPS_MODE_DEFAULT = false;
    @Property(boolValue={0})
    private static final String PROP_FIPS_MODE = "settings.fipsmode.enabled";
    private static final boolean PROPS_A9_COMPAT_MODE_ENABLED_DEFAULT = false;
    @Property(boolValue={0})
    private static final String PROPS_A9_COMPAT_MODE = "settings.a9compatmode.enabled";
    @Property
    private static final String PROPS_PROCESSING_SERVER_URL = "settings.processing.server.url";
    @Property
    private static final String PROPS_PROCESSING_SERVER_USERNAME = "settings.processing.server.username";
    @Property
    private static final String PROPS_PROCESSING_SERVER_PASSWORD = "settings.processing.server.password";
    private static final String TEMP_FOLDER_NAME = "temp";
    private Logger log = LoggerFactory.getLogger(AemDsSettingsServiceImpl.class);
    @Reference
    private SlingSettingsService settingsService;
    private String tempFolderPath;
    private boolean fipsModeEnabled;
    private boolean a9CompatModeEnabled;
    private String processingServerUrl;
    private String processingServerUsername;
    private String processingServerPassword;

    @Activate
    private void activate(Map<String, Object> config) throws IOException {
        String folderType = OsgiUtil.toString((Object)config.get("settings.tempfolder.type"), (String)"sling");
        this.tempFolderPath = "system".equals(folderType) ? System.getProperty("java.io.tmpdir") : ("sling".equals(folderType) ? new File(this.settingsService.getSlingHomePath(), "temp").getCanonicalPath() : OsgiUtil.toString((Object)config.get("settings.tempfolder.path"), (String)null));
        File tempFolder = new File(this.tempFolderPath);
        boolean clean = OsgiUtil.toBoolean((Object)config.get("settings.tempfolder.clean"), (boolean)true);
        if (!"system".equals(folderType)) {
            if (clean && tempFolder.exists()) {
                this.log.info("Clean temporary file folder option enabled. Cleaning the folder {}", (Object)tempFolder);
                try {
                    FileUtils.cleanDirectory((File)tempFolder);
                }
                catch (IOException ioe) {
                    this.log.info("Exception while cleaning temporary file folder", (Throwable)ioe);
                }
                this.log.info("Cleaned the temp folder {}", (Object)tempFolder);
            }
            if (!tempFolder.exists()) {
                FileUtils.forceMkdir((File)tempFolder);
            }
        }
        if (!tempFolder.exists()) {
            throw new IllegalArgumentException("Temporary file folder [" + tempFolder + "] does not exist");
        }
        this.tempFolderPath = tempFolder.getCanonicalPath();
        this.fipsModeEnabled = OsgiUtil.toBoolean((Object)config.get("settings.fipsmode.enabled"), (boolean)false);
        this.a9CompatModeEnabled = OsgiUtil.toBoolean((Object)config.get("settings.a9compatmode.enabled"), (boolean)false);
        this.processingServerUrl = OsgiUtil.toString((Object)config.get("settings.processing.server.url"), (String)null);
        this.processingServerUsername = OsgiUtil.toString((Object)config.get("settings.processing.server.username"), (String)null);
        this.processingServerPassword = OsgiUtil.toString((Object)config.get("settings.processing.server.password"), (String)null);
        this.log.info("Using folder {} as temporary file storage location", (Object)this.tempFolderPath);
    }

    @Override
    public String getTempFolderPath() {
        return this.tempFolderPath;
    }

    @Override
    public boolean isFIPSModeEnabled() {
        return this.fipsModeEnabled;
    }

    @Override
    public boolean isA9CompatModeEnabled() {
        return this.a9CompatModeEnabled;
    }

    @Override
    public String getProcessingServerUrl() {
        return this.processingServerUrl;
    }

    @Override
    public String getProcessingServerUsername() {
        return this.processingServerUsername;
    }

    @Override
    public String getProcessingServerPassword() {
        return this.processingServerPassword;
    }

    protected void bindSettingsService(SlingSettingsService slingSettingsService) {
        this.settingsService = slingSettingsService;
    }

    protected void unbindSettingsService(SlingSettingsService slingSettingsService) {
        if (this.settingsService == slingSettingsService) {
            this.settingsService = null;
        }
    }
}