com.lonelystorm.air.asset.models.Asset Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of air-asset Show documentation
Show all versions of air-asset Show documentation
The LonelyStorm Air Asset library provides support to be able to compile SASS files at runtime.
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;
}
}