AssetVersionImpl.java 3.71 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.asset.api.Asset
 *  com.adobe.granite.asset.api.AssetRelation
 *  com.adobe.granite.asset.api.AssetVersion
 *  com.adobe.granite.asset.api.Rendition
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.jcr.version.Version
 *  javax.jcr.version.VersionHistory
 *  org.apache.sling.api.adapter.Adaptable
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ValueMap
 */
package com.adobe.granite.asset.core.impl;

import com.adobe.granite.asset.api.Asset;
import com.adobe.granite.asset.api.AssetRelation;
import com.adobe.granite.asset.api.AssetVersion;
import com.adobe.granite.asset.api.Rendition;
import com.adobe.granite.asset.core.impl.AssetWrapper;
import java.util.Calendar;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class AssetVersionImpl
implements AssetVersion,
Adaptable {
    private final String id;
    private final String[] labels;
    private final String versionName;
    private String path;
    private final AssetWrapper assetWrapper;
    private ValueMap contentProperties;
    private final String assetPath;
    private Calendar created;

    public AssetVersionImpl(Version version, ResourceResolver resolver) throws RepositoryException {
        Session session = (Session)resolver.adaptTo(Session.class);
        Resource resource = resolver.getResource(version.getNode("jcr:frozenNode").getPath());
        this.assetWrapper = new AssetWrapper(resource);
        Resource contentResource = resolver.getResource(resource, "jcr:content");
        this.contentProperties = ResourceUtil.getValueMap((Resource)contentResource);
        this.id = version.getIdentifier();
        this.versionName = version.getName();
        this.created = version.getCreated();
        VersionHistory versionHistory = version.getContainingHistory();
        this.path = version.getPath();
        this.labels = versionHistory.getVersionLabels(version);
        this.assetPath = session.getNodeByIdentifier(versionHistory.getVersionableIdentifier()).getPath();
    }

    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
        if (ValueMap.class == type) {
            return (AdapterType)this.contentProperties;
        }
        return null;
    }

    public String[] getLabels() {
        return this.labels;
    }

    public String getId() {
        return this.id;
    }

    public String getPath() {
        return this.path;
    }

    public String getAssetPath() {
        return this.assetPath;
    }

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

    public Calendar getCreated() {
        return this.created;
    }

    public Rendition getRendition(String name) {
        return this.assetWrapper.getRendition(name);
    }

    public Iterator<Rendition> listRenditions() {
        return this.assetWrapper.listRenditions();
    }

    public Iterator<Asset> listRelated(String name) {
        return this.assetWrapper.listRelated(name);
    }

    public Iterator<AssetRelation> listRelations(String name) {
        return this.assetWrapper.listRelations(name);
    }
}