DamLayout.java 8.67 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.scalautil.javautil.Tuple
 *  com.scene7.is.util.callbacks.Option
 *  scala.Tuple2
 *  scala.Tuple3
 */
package com.adobe.cq.dam.aod.replication;

import com.scene7.is.scalautil.javautil.Tuple;
import com.scene7.is.util.callbacks.Option;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import scala.Tuple2;
import scala.Tuple3;

public class DamLayout {
    public static final String DefaultContentRoot = "/content/dam";
    public static final String DefaultCatalogPath = "/etc/dam/imageserver/configuration/jcr:content/settings";
    public static final String DefaultMacroPath = "/etc/dam/imageserver/macros";
    public static final String DefaultViewerPresetRoot = "/etc/dam/presets/viewer";
    public static final String TenantConfRoot = "/etc/dam/tenants";
    public static final String TenantContentRoot = "/content/dam/mac";
    public static final String CatalogSuffix = "imageserver/configuration/jcr:content/settings";
    public static final String ViewerPresetSuffix = "presets/viewer";
    public static final String ImagePresetSuffix = "presets/image";
    private static final String PathSeg = "[^/]+";

    public static String viewerPresetRoot(String tenantId) {
        if (tenantId.isEmpty()) {
            return "/etc/dam/presets/viewer";
        }
        return "/etc/dam/tenants/" + tenantId;
    }

    public static String contentRoot(String tenantId) {
        if (tenantId.isEmpty()) {
            return "/content/dam";
        }
        return "/content/dam/mac/" + tenantId;
    }

    public static boolean isRenditionPath(String path) {
        return RenditionPath.unapply(path).isDefined();
    }

    public static boolean isRelationPath(String path) {
        return RelationPath.unapply(path).isDefined();
    }

    public static boolean isCatalogPath(String path) {
        return CatalogPath.unapply(path).isDefined();
    }

    public static boolean isMacroPath(String path) {
        return MacroPath.unapply(path).isDefined();
    }

    public static String catalogTenantId(String path) {
        Iterator i$ = CatalogPath.unapply(path).iterator();
        if (i$.hasNext()) {
            String v = (String)i$.next();
            return v;
        }
        throw new IllegalArgumentException("Not a catalog path: '" + path + '\'');
    }

    public static Tuple2<String, String> macroParts(String path) {
        Iterator i$ = MacroPath.unapply(path).iterator();
        if (i$.hasNext()) {
            Tuple2 v = (Tuple2)i$.next();
            return v;
        }
        throw new IllegalArgumentException("Not a macro path: '" + path + '\'');
    }

    public static Tuple2<String, String> assetParts(String path) {
        Iterator i$ = AssetParts.unapply(path).iterator();
        if (i$.hasNext()) {
            Tuple3 v = (Tuple3)i$.next();
            String tenantId = (String)v._1();
            String assetId = (String)v._3();
            return Tuple.tuple((Object)tenantId, (Object)assetId);
        }
        throw new IllegalArgumentException("Not an asset path: '" + path + '\'');
    }

    public static String imagePresetRoot(String tenantId) {
        if (tenantId.isEmpty()) {
            return "/etc/dam/imageserver/macros";
        }
        return "/etc/dam/tenants/" + tenantId + '/' + "presets/image";
    }

    private static Option<Matcher> match(Pattern pattern, String str) {
        Matcher result = pattern.matcher(str);
        if (result.matches()) {
            return Option.some((Object)result);
        }
        return Option.none();
    }

    private DamLayout() {
    }

    private static class RelationPath {
        private static final Pattern regex = Pattern.compile("^(/.+)/jcr:content/related/([^/]+)$");

        private RelationPath() {
        }

        public static Option<Tuple2<String, String>> unapply(String path) {
            Iterator i$ = DamLayout.match(regex, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                return Option.some((Object)Tuple.tuple((Object)v.group(1), (Object)v.group(2)));
            }
            return Option.none();
        }
    }

    private static class AssetParts {
        private static final Pattern regex = Pattern.compile("^((?:/etc/dam/tenants)|(?:/content/dam/mac))/([^/]+)/(.*)?$");

        public static Option<Tuple3<String, String, String>> unapply(String path) {
            Iterator i$ = DamLayout.match(regex, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                String prefix = v.group(1);
                String tenantId = v.group(2);
                String recordId = v.group(3);
                String rootId = (prefix + '/' + tenantId).substring(1);
                return Option.some((Object)Tuple.tuple((Object)tenantId, (Object)rootId, (Object)recordId));
            }
            assert (path.startsWith("/"));
            return Option.some((Object)Tuple.tuple((Object)"", (Object)"", (Object)path.substring(1)));
        }

        private AssetParts() {
        }
    }

    public static class CatalogPath {
        private static final Pattern regex = Pattern.compile("^/etc/dam/tenants/([^/]+)/imageserver/configuration/jcr:content/settings$");

        public static String fromTenantId(String tenantId) {
            if (tenantId.isEmpty()) {
                return "/etc/dam/imageserver/configuration/jcr:content/settings";
            }
            return "/etc/dam/tenants/" + tenantId + '/' + "imageserver/configuration/jcr:content/settings";
        }

        public static Option<String> unapply(String path) {
            if (path.equals("/etc/dam/imageserver/configuration/jcr:content/settings")) {
                return Option.some((Object)"");
            }
            Iterator i$ = DamLayout.match(regex, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                return Option.some((Object)v.group(1));
            }
            return Option.none();
        }
    }

    private static class MacroPath {
        private static final Pattern Default = Pattern.compile("/etc/dam/imageserver/macros/([^/]+)$");
        private static final Pattern Tenant = Pattern.compile("^/etc/dam/tenants/([^/]+)/presets/image/([^/]+)$");

        private MacroPath() {
        }

        public static String fromTenantId(String tenantId, String name) {
            if (tenantId.isEmpty()) {
                return "/etc/dam/imageserver/macros/" + name;
            }
            return DamLayout.imagePresetRoot(tenantId) + '/' + name;
        }

        public static Option<Tuple2<String, String>> unapply(String path) {
            Iterator i$ = DamLayout.match(Default, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                String name = v.group(1);
                return Option.some((Object)Tuple.tuple((Object)"", (Object)name));
            }
            i$ = DamLayout.match(Tenant, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                String tenant = v.group(1);
                String name = v.group(2);
                return Option.some((Object)Tuple.tuple((Object)tenant, (Object)name));
            }
            return Option.none();
        }
    }

    private static class RenditionPath {
        private static final Pattern regex = Pattern.compile("^(/.+)/jcr:content/renditions/([^/]+)$");

        private RenditionPath() {
        }

        public static Option<Tuple2<String, String>> unapply(String path) {
            Iterator i$ = DamLayout.match(regex, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                String asset = v.group(1);
                String name = v.group(2);
                return Option.some((Object)Tuple.tuple((Object)asset, (Object)name));
            }
            return Option.none();
        }
    }

    public static class TenantDomainPath {
        private static final Pattern regex = Pattern.compile("^((?:/etc/dam/tenants)|(?:/content/dam/mac))/([^/]+)(/.*)?$");

        public static Option<Tuple3<String, String, Option<String>>> unapply(String path) {
            Iterator i$ = DamLayout.match(regex, path).iterator();
            if (i$.hasNext()) {
                Matcher v = (Matcher)i$.next();
                String rootPath = v.group(1);
                String tenant = v.group(2);
                Option suffix = Option.some((Object)v.group(3));
                return Option.some((Object)Tuple.tuple((Object)tenant, (Object)rootPath, (Object)suffix));
            }
            return Option.none();
        }
    }

}