RenditionsResourceConverter.java 2.74 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.rest.converter.ResourceConverter
 *  com.adobe.granite.rest.converter.ResourceConverterContext
 *  com.adobe.granite.rest.converter.ResourceConverterException
 *  com.adobe.granite.rest.converter.siren.AbstractPageableSirenConverter
 *  com.adobe.reef.siren.Action
 *  com.adobe.reef.siren.Action$Method
 *  com.adobe.reef.siren.Entity
 *  com.adobe.reef.siren.Field
 *  com.adobe.reef.siren.Field$FieldType
 *  com.adobe.reef.siren.builder.ActionBuilder
 *  com.adobe.reef.siren.builder.BuilderException
 *  com.adobe.reef.siren.builder.FieldBuilder
 *  org.apache.sling.api.resource.Resource
 *  org.slf4j.Logger
 */
package com.adobe.granite.rest.assets.impl;

import com.adobe.granite.rest.assets.impl.RenditionResource;
import com.adobe.granite.rest.converter.ResourceConverter;
import com.adobe.granite.rest.converter.ResourceConverterContext;
import com.adobe.granite.rest.converter.ResourceConverterException;
import com.adobe.granite.rest.converter.siren.AbstractPageableSirenConverter;
import com.adobe.reef.siren.Action;
import com.adobe.reef.siren.Entity;
import com.adobe.reef.siren.Field;
import com.adobe.reef.siren.builder.ActionBuilder;
import com.adobe.reef.siren.builder.BuilderException;
import com.adobe.reef.siren.builder.FieldBuilder;
import java.util.List;
import org.apache.sling.api.resource.Resource;
import org.slf4j.Logger;

public class RenditionsResourceConverter
extends AbstractPageableSirenConverter {
    public RenditionsResourceConverter(Resource resource) {
        super(resource);
    }

    protected String[] getClazz() {
        return new String[]{"assets/asset/renditions"};
    }

    protected Entity getEntity(ResourceConverterContext context, Resource child) throws ResourceConverterException {
        if (child instanceof RenditionResource) {
            ResourceConverter converter = (ResourceConverter)child.adaptTo(ResourceConverter.class);
            if (converter != null) {
                return (Entity)converter.toSubEntity(context);
            }
            this.log.error("Could not adapt RenditionResource to ResourceConverter");
        }
        return null;
    }

    protected List<Action> getActions(ResourceConverterContext context) throws BuilderException, ResourceConverterException {
        List actions = super.getActions(context);
        actions.add(new ActionBuilder().setName("add-rendition").setHref(this.buildURL(context, this.resource.getPath() + "/renditions/*", null)).setMethod(Action.Method.POST).setTitle("Add Rendition").addField((Field)new FieldBuilder().setName("name").build()).addField((Field)new FieldBuilder().setName("file").setType(Field.FieldType.FILE).build()).build());
        return actions;
    }
}