DamManagerImpl.java 3.98 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.dam.api.Asset
 *  com.day.cq.dam.api.AssetManager
 *  com.day.cq.dam.api.DamManager
 *  com.day.cq.dam.commons.util.DamUtil
 *  javax.jcr.AccessDeniedException
 *  javax.jcr.Node
 *  javax.jcr.PathNotFoundException
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.jcr.lock.LockException
 *  javax.jcr.nodetype.ConstraintViolationException
 *  javax.jcr.version.VersionException
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.jcr.resource.JcrResourceResolverFactory
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.dam.core.impl;

import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.AssetManager;
import com.day.cq.dam.api.DamManager;
import com.day.cq.dam.commons.util.DamUtil;
import java.io.File;
import java.io.IOException;
import javax.jcr.AccessDeniedException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=0, metatype=0, label="DamManager", description="The Dam Manager...")
@Service
public class DamManagerImpl
implements DamManager {
    private static final Logger log = LoggerFactory.getLogger(DamManagerImpl.class);
    @Reference
    private JcrResourceResolverFactory jcrResolverFactory;

    public File createTempFile(String prefix, String suffix) throws IOException {
        throw new RuntimeException("operation no longer supported");
    }

    public Session getSession() throws RepositoryException {
        throw new RuntimeException("operation no longer supported");
    }

    public String createMetadataPath(String binaryNodePath) {
        return DamUtil.binaryToAssetPath((String)binaryNodePath);
    }

    public String createBinaryUploadLocationPath(String metadataNodePath) {
        return DamUtil.assetToBinaryPath((String)metadataNodePath);
    }

    public Node getAssetNode(String assetPath, Session session) {
        try {
            return session.getNode(DamUtil.binaryToAssetPath((String)assetPath));
        }
        catch (PathNotFoundException e) {
        }
        catch (RepositoryException e) {
            // empty catch block
        }
        return null;
    }

    public void removeAssetNode(String assetPath, Session session) {
        try {
            session.removeItem(DamUtil.binaryToAssetPath((String)assetPath));
        }
        catch (AccessDeniedException e) {
            e.printStackTrace();
        }
        catch (VersionException e) {
        }
        catch (LockException e) {
            e.printStackTrace();
        }
        catch (ConstraintViolationException e) {
        }
        catch (RepositoryException e) {
            // empty catch block
        }
    }

    public Asset createAssetStructure(String binaryPath, Session session, boolean doSave) {
        return ((AssetManager)this.jcrResolverFactory.getResourceResolver(session).adaptTo(AssetManager.class)).createAssetForBinary(binaryPath, doSave);
    }

    protected void bindJcrResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
        this.jcrResolverFactory = jcrResourceResolverFactory;
    }

    protected void unbindJcrResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
        if (this.jcrResolverFactory == jcrResourceResolverFactory) {
            this.jcrResolverFactory = null;
        }
    }
}