ElementTemplateImpl.java 3.03 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.dam.cfm.ElementTemplate
 *  com.day.cq.dam.api.Asset
 *  org.apache.sling.api.resource.ModifiableValueMap
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.dam.cfm.impl;

import com.adobe.cq.dam.cfm.ElementTemplate;
import com.adobe.cq.dam.cfm.impl.FragmentTemplateImpl;
import com.adobe.cq.dam.cfm.impl.FragmentWriteException;
import com.adobe.cq.dam.cfm.impl.InvalidTemplateException;
import com.day.cq.dam.api.Asset;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ElementTemplateImpl
implements ElementTemplate {
    private final Logger log;
    public final FragmentTemplateImpl fragmentTemplate;
    private final String name;
    private final String title;
    private final String initialContentType;
    private final String defaultContent;
    private final Resource resource;
    private String assetName;

    public ElementTemplateImpl(FragmentTemplateImpl fragmentTemplate, Resource resource) throws InvalidTemplateException {
        this.log = LoggerFactory.getLogger(this.getClass());
        this.resource = resource;
        this.fragmentTemplate = fragmentTemplate;
        ValueMap properties = (ValueMap)resource.adaptTo(ValueMap.class);
        String name = (String)properties.get("name", String.class);
        if (name == null) {
            throw new InvalidTemplateException("Missing element name on template.");
        }
        this.name = name;
        String title = (String)properties.get("jcr:title", String.class);
        if (title == null) {
            throw new InvalidTemplateException("Missing element title on template.");
        }
        this.title = title;
        this.assetName = (String)properties.get("assetName", String.class);
        this.initialContentType = (String)properties.get("initialContentType", (Object)"text/html");
        this.defaultContent = (String)properties.get("defaultContent", (Object)"");
    }

    public String getName() {
        return this.name;
    }

    public String getTitle() {
        return this.title;
    }

    public String getInitialContentType() {
        return this.initialContentType;
    }

    public String getDefaultContent() {
        return this.defaultContent;
    }

    public FragmentTemplateImpl getFragmentTemplate() {
        return this.fragmentTemplate;
    }

    public void linkToAsset(Asset asset, boolean isMainAsset) throws FragmentWriteException {
        if (isMainAsset) {
            return;
        }
        ModifiableValueMap values = (ModifiableValueMap)this.resource.adaptTo(ModifiableValueMap.class);
        String assetName = asset.getName();
        values.put((Object)"assetName", (Object)assetName);
    }

    public String getAssetName() {
        return this.assetName;
    }
}