All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lonelystorm.air.asset.models.Asset Maven / Gradle / Ivy

Go to download

The LonelyStorm Air Asset library provides support to be able to compile SASS files at runtime.

There is a newer version: 0.1.8
Show newest version
package com.lonelystorm.air.asset.models;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import javax.inject.Inject;

import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Optional;

public abstract class Asset {

    @Inject
    @Optional
    @Default(values = {})
    private String[] loadPaths;

    @Inject
    @Optional
    @Default(values = {})
    private String[] embed;

    private String path;

    private Set sources;

    /**
     * Returns an array containing the load paths for the compiler.
     *
     * @return The load paths
     */
    public String[] getLoadPaths() {
        return loadPaths.clone();
    }

    /**
     * Returns an array containing the categories of assets to embed during compilation.
     *
     * @return The embed dependencies
     */
    public String[] getEmbed() {
        return embed.clone();
    }

    /**
     * Returns the path of the asset.
     *
     * @return The path
     */
    public String getPath() {
        return path;
    }

    /**
     * Sets the path of the asset.
     *
     * @param path The path
     */
    protected void setPath(String path) {
        this.path = path;
    }

    /**
     * Returns the sources of the asset.
     *
     * @return The sources
     */
    public Set getSources() {
        return Collections.unmodifiableSet(sources);
    }

    /**
     * Sets the sources of the asset.
     *
     * @param resource The resource to parse
     */
    protected void setSources(Resource resource) {
        Iterable children = resource.getChildren();

        sources = new HashSet<>();
        for (Resource child : children) {
            if (child.isResourceType(JcrConstants.NT_FILE)) {
                sources.add(child.getPath());
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return Objects.hash(path);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Asset) {
            return path.equals(((Asset) obj).path);
        }

        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy