S7ConfigImpl.java 7.3 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.commons.inherit.InheritanceValueMap
 *  com.day.cq.wcm.webservicesupport.Configuration
 *  javax.jcr.Node
 *  javax.jcr.NodeIterator
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  javax.jcr.Value
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.dam.scene7.impl.model;

import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.dam.scene7.api.S7Config;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.io.InvalidObjectException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class S7ConfigImpl
implements S7Config {
    private Configuration configuration;
    private InheritanceValueMap map;
    private String region;
    private String basePath = "";
    private String email;
    private String password;
    private boolean shared;
    private static final Logger LOG = LoggerFactory.getLogger(S7ConfigImpl.class);

    public S7ConfigImpl(Configuration configuration) throws InvalidObjectException {
        if (configuration == null) {
            throw new InvalidObjectException("The configuration object cannot be null");
        }
        this.configuration = configuration;
        this.map = configuration.getProperties();
        this.region = (String)this.map.get((Object)"region");
    }

    public S7ConfigImpl(Configuration configuration, boolean shared) throws InvalidObjectException {
        this(configuration);
        this.shared = shared;
    }

    public S7ConfigImpl(String email, String password, String region) throws InvalidObjectException {
        this.email = email;
        this.password = password;
        this.region = region;
    }

    @Override
    public String getCloudConfigPath() {
        return this.configuration.getPath();
    }

    @Override
    public String getEmail() {
        return this.email == null ? (String)this.map.get((Object)"email") : this.email;
    }

    @Override
    public String getPassword() {
        return this.password == null ? (String)this.map.get((Object)"password") : this.password;
    }

    @Override
    public String getRegion() {
        return this.region;
    }

    @Override
    public String getUserHandle() {
        return (String)this.map.get("userHandle", String.class);
    }

    @Override
    public String getCompanyHandle() {
        return this.shared ? "Shared" : (String)this.map.get("companyHandle", String.class);
    }

    @Override
    public String getRootPath() {
        return this.shared ? "Scene7SharedAssets/" : (String)this.map.get("rootPath", String.class);
    }

    @Override
    public String isSyncEnabled() {
        return this.shared ? "off" : (String)this.map.get("syncEnabled", String.class);
    }

    @Override
    public String isPublishEnabled() {
        return this.shared ? "off" : (String)this.map.get("publishEnabled", String.class);
    }

    @Override
    public String getBasePath() {
        String cqRootPath;
        int index;
        if (this.basePath.equals("") && (cqRootPath = this.getRootPath()) != null && (index = cqRootPath.indexOf("/")) != -1) {
            this.basePath = cqRootPath.substring(0, index + 1);
        }
        return this.basePath;
    }

    @Override
    public String get(String prop) {
        String value = null;
        value = "email".equals(prop) ? this.getEmail() : ("region".equals(prop) ? this.getRegion() : ("password".equals(prop) ? this.getPassword() : ("companyHandle".equals(prop) ? this.getCompanyHandle() : ("rootPath".equals(prop) ? this.getRootPath() : ("cqRootPath".equals(prop) ? this.getBasePath() : ("userHandle".equals(prop) ? this.getUserHandle() : ("syncEnabled".equals(prop) ? this.isSyncEnabled() : ("publishEnabled".equals(prop) ? this.isPublishEnabled() : (String)this.map.get(prop, String.class)))))))));
        return value;
    }

    @Override
    public InheritanceValueMap getPropertiesMap() {
        return this.map;
    }

    @Override
    public String getPublishServer() {
        return (String)this.map.get("publishServer", String.class);
    }

    @Override
    public String getPreviewServer() {
        return (String)this.map.get("previewServer", String.class);
    }

    @Override
    public String getFlashTemplatesServer() {
        return (String)this.map.get("flashTemplatesServer", String.class);
    }

    @Override
    public String getTargetPath() {
        return (String)this.map.get("targetPath", String.class);
    }

    @Override
    public boolean isDefault() {
        Boolean defaultProperty = (Boolean)this.map.get("defaultConfiguration", (Object)Boolean.FALSE);
        return defaultProperty;
    }

    @Override
    public String getMimeTypeJobParams(String mimeType) {
        if (mimeType == null || mimeType.length() == 0) {
            return "";
        }
        mimeType = mimeType.toLowerCase();
        mimeType = mimeType.replace("/", "_");
        mimeType = mimeType.replace("*", "");
        Resource confResource = this.configuration.getResource();
        ResourceResolver rr = confResource.getResourceResolver();
        String path = confResource.getPath() + "/" + "jcr:content" + "/" + "mimeTypes";
        Resource mimeTypesResource = rr.getResource(path);
        Node mimeTypesNode = (Node)mimeTypesResource.adaptTo(Node.class);
        try {
            if (mimeTypesNode != null && mimeTypesNode.hasNode(mimeType)) {
                Node mimeTypeNode = mimeTypesNode.getNode(mimeType);
                Property jobParam = mimeTypeNode.getProperty("jobParam");
                if (jobParam != null) {
                    return jobParam.getValue().toString();
                }
            } else if (mimeTypesNode != null) {
                NodeIterator iterator = mimeTypesNode.getNodes();
                while (iterator.hasNext()) {
                    Property jobParam;
                    Node childNode = iterator.nextNode();
                    if (!mimeType.startsWith(childNode.getName()) || (jobParam = childNode.getProperty("jobParam")) == null) continue;
                    return jobParam.getValue().toString();
                }
            }
        }
        catch (RepositoryException e) {
            LOG.error(e.getLocalizedMessage());
        }
        return "";
    }

    public boolean equals(Object obj) {
        if (obj != null && obj instanceof S7Config) {
            S7Config anotherS7Config = (S7Config)obj;
            return this.getCloudConfigPath().equals(anotherS7Config.getCloudConfigPath());
        }
        return false;
    }

    @Override
    public String getFXGServer() {
        return (String)this.map.get("fxgServer", String.class);
    }

    @Override
    public String getAdhocFolder() {
        return (String)this.map.get("adhocFolder", String.class);
    }

    @Override
    public String getImportQueueName() {
        return (String)this.map.get("importQueueName", String.class);
    }

    @Override
    public String getImportQueueTopic() {
        return (String)this.map.get("importQueueTopic", String.class);
    }
}