ApplicationContextFactory.java 7.71 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.catalog.CatalogLookupAccessor
 *  com.scene7.is.catalog.LookupServiceHandlerFactory
 *  com.scene7.is.catalog.client.CatalogAttributes
 *  com.scene7.is.catalog.client.CatalogRecord
 *  com.scene7.is.catalog.client.CatalogServer
 *  com.scene7.is.catalog.client.CatalogServerBean
 *  com.scene7.is.catalog.client.DomainInfo
 *  com.scene7.is.catalog.client.DomainInfo$DomainInfoConverter
 *  com.scene7.is.catalog.client.ImageDirectory
 *  com.scene7.is.catalog.client.ImageDirectoryImpl
 *  com.scene7.is.mbeans.ps.StaticContentMBean
 *  com.scene7.is.mbeans.ps.StaticContentMBean$class
 *  com.scene7.is.util.FileUtil
 *  com.scene7.is.util.IOUtil
 *  com.scene7.is.util.OneWayConverter
 *  com.scene7.is.util.PSDeploymentConfigSimple
 *  com.scene7.is.util.collections.CollectionUtil
 *  javax.servlet.ServletContext
 *  org.springframework.beans.factory.config.ConfigurableListableBeanFactory
 *  org.springframework.beans.factory.config.Scope
 *  org.springframework.context.ConfigurableApplicationContext
 *  org.springframework.context.support.ClassPathXmlApplicationContext
 *  org.springframework.web.context.request.RequestScope
 */
package com.adobe.cq.dam.s7imaging.impl.ps;

import com.adobe.cq.dam.s7imaging.impl.is.ImageServerComponent;
import com.adobe.cq.dam.s7imaging.impl.ps.JcrResourceAccessor;
import com.adobe.cq.dam.s7imaging.impl.ps.dummies.DummyAgmConfiguration;
import com.adobe.cq.dam.s7imaging.impl.ps.dummies.DummyAgmServer;
import com.adobe.cq.dam.s7imaging.impl.ps.dummies.DummyRunnable;
import com.scene7.is.catalog.CatalogLookupAccessor;
import com.scene7.is.catalog.LookupServiceHandlerFactory;
import com.scene7.is.catalog.client.CatalogAttributes;
import com.scene7.is.catalog.client.CatalogRecord;
import com.scene7.is.catalog.client.CatalogServer;
import com.scene7.is.catalog.client.CatalogServerBean;
import com.scene7.is.catalog.client.DomainInfo;
import com.scene7.is.catalog.client.ImageDirectory;
import com.scene7.is.catalog.client.ImageDirectoryImpl;
import com.scene7.is.mbeans.ps.StaticContentMBean;
import com.scene7.is.util.FileUtil;
import com.scene7.is.util.IOUtil;
import com.scene7.is.util.OneWayConverter;
import com.scene7.is.util.PSDeploymentConfigSimple;
import com.scene7.is.util.collections.CollectionUtil;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationHandler;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.Scope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.request.RequestScope;

public class ApplicationContextFactory {
    private static final StaticContentMBean staticContent = new StaticContentMBean(){

        public String getRootPaths() {
            return StaticContentMBean.class.getRootPaths((StaticContentMBean)this);
        }

        public void setRootPaths(String v) {
            StaticContentMBean.class.setRootPaths((StaticContentMBean)this, (String)v);
        }

        public String rootPaths() {
            return "/";
        }

        public void rootPaths_$eq(String rootPaths) {
            throw new UnsupportedOperationException("Static content root is read only in JCR");
        }
    };
    public static final JcrResourceAccessor resourceAccessor = JcrResourceAccessor.apply("/");

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static ConfigurableApplicationContext apply(File psHome, CatalogLookupAccessor catalogAccessor, ImageServerComponent imageServer, final ServletContext servletContext, Map<String, String> psConfig) throws IOException {
        final CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo> catalogService = ApplicationContextFactory.catalogServerBean(catalogAccessor);
        Properties sysProps = System.getProperties();
        sysProps.setProperty("com.scene7.isHome", psHome.getPath());
        FileUtil.mkdir((File)psHome, (String)"cache");
        File confDir = new File(psHome, "conf");
        FileUtil.mkdir((File)confDir);
        File svgConf = new File(confDir, "svg.conf");
        svgConf.createNewFile();
        final File configFile = new File(confDir, "platform-server.conf");
        Properties props = new Properties();
        props.setProperty("isConnection.host", imageServer.getHost());
        props.setProperty("isConnection.port", CollectionUtil.mkString(Arrays.asList(imageServer.getPort()), (String)";"));
        props.setProperty("fvctx.useCatalogRecordValidation", "true");
        props.setProperty("fvctx.useCache", "false");
        props.putAll(psConfig);
        FileOutputStream out = new FileOutputStream(configFile);
        try {
            props.store(out, "");
        }
        finally {
            IOUtil.closeQuietly((Closeable)out);
        }
        return new ClassPathXmlApplicationContext("/com/scene7/is/ps/j2ee/is-context.xml", ApplicationContextFactory.class){

            public ConfigurableListableBeanFactory obtainFreshBeanFactory() {
                ConfigurableListableBeanFactory f = super.obtainFreshBeanFactory();
                f.registerSingleton("agm", (Object)new DummyAgmConfiguration());
                f.registerSingleton("agmServer", (Object)new DummyAgmServer());
                f.registerSingleton("statLogger", (Object)new DummyRunnable());
                f.registerSingleton("agmRawCleanup", (Object)new DummyRunnable());
                f.registerSingleton("psDeploymentConfig", (Object)new PSDeploymentConfigSimple(8080));
                f.registerSingleton("servletContext", (Object)servletContext);
                f.registerSingleton("defaultConfig", (Object)"classpath:/com/adobe/cq/dam/s7imaging/impl/ps/server.properties");
                f.registerSingleton("customConfig", (Object)configFile.getAbsolutePath());
                f.registerSingleton("catalogService", (Object)catalogService);
                f.registerSingleton("imageDirectory", (Object)ApplicationContextFactory.createImageDirectory((CatalogServer)catalogService));
                f.registerSingleton("staticContent", (Object)staticContent);
                f.registerSingleton("resourceAccessor", (Object)ApplicationContextFactory.resourceAccessor);
                f.registerScope("request", (Scope)new RequestScope());
                return f;
            }
        };
    }

    private static CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo> catalogServerBean(CatalogLookupAccessor catalogAccessor) {
        final InvocationHandler localInvoker = LookupServiceHandlerFactory.lookupServiceInvoker((CatalogLookupAccessor)catalogAccessor);
        CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo> result = new CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo>(CatalogAttributes.catalogAttributesConverter(), CatalogRecord.catalogRecordConverter(), (OneWayConverter)DomainInfo.DomainInfoConverter.apply()){

            public InvocationHandler getLocalInvoker() {
                return localInvoker;
            }
        };
        result.setCacheMaxCount(0);
        return result;
    }

    private static ImageDirectory createImageDirectory(final CatalogServer<CatalogAttributes, CatalogRecord, DomainInfo> catalogService) {
        return new ImageDirectoryImpl(){

            protected CatalogServer<CatalogAttributes, CatalogRecord, DomainInfo> getService() {
                return catalogService;
            }
        };
    }

}