本文整理汇总了Java中com.day.cq.dam.api.Asset类的典型用法代码示例。如果您正苦于以下问题:Java Asset类的具体用法?Java Asset怎么用?Java Asset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Asset类属于com.day.cq.dam.api包,在下文中一共展示了Asset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Override
public IndexEntry create(String path, @Nonnull ResourceResolver resolver) {
String[] indexRules = getIndexRules(PRIMARY_TYPE_VALUE);
if (ArrayUtils.isNotEmpty(indexRules)) {
Resource res = resolver.getResource(path);
if (res != null) {
Asset asset = res.adaptTo(Asset.class);
if (asset != null) {
IndexEntry ret = new IndexEntry("idx", "asset", path);
ret.addContent(getProperties(res, indexRules));
return ret;
}
LOG.error("Could not adapt asset");
}
}
return null;
}
示例2: init
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@PostConstruct public void init() throws SlingModelsException {
Asset asset = resource.adaptTo(Asset.class);
if(null == asset){
return;
}
Rendition rendition = (asset.getRendition("plain") != null) ?
asset.getRendition("plain") :
asset.getOriginal();
StringWriter writer = new StringWriter();
try {
IOUtils.copy(rendition.getStream(), writer, "UTF8");
this.body = writer.toString();
} catch (IOException e) {
LOG.error("Error reading rendition: {}", rendition.getPath(), e);
}
}
示例3: resolveRendition
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
/**
* Returned {@link Rendition} is resolved with the following priority rules:
* <ol>
* <li>Rendition type (eg. web, thumbnail)</li>
* <li>Rendition extension (eg. png, jpeg)</li>
* </ol>
* First match is returned. Requested dimensions are always honored.
* <p>
* {@link RenditionType#ORIGINAL} is a special case which will always result in the "original"
* returned, or null if missing. No extra search rules are used.
*/
@Override
public Rendition resolveRendition(Asset asset, RenditionMeta renditionMeta) {
if (asset == null) return null;
if (renditionMeta == null) return null;
List<String> renditionPriorityList = buildSortedRenditions(renditionMeta);
if (log.isTraceEnabled()) {
log.trace("Searching for {} rendition in order of {}", asset.getPath(), renditionPriorityList);
}
Rendition rendition = null;
for (String name : renditionPriorityList) {
if (log.isTraceEnabled()) log.trace("Searching for {} for {}", name, asset.getPath());
rendition = asset.getRendition(name);
if (rendition != null) break;
}
if (log.isDebugEnabled()) {
log.debug("Resolved rendition {} for {} and {}", (rendition == null) ? "null" : rendition.getName(), asset.getPath(), renditionMeta);
}
return rendition;
}
示例4: getBinary
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Override
public ResourceBinary getBinary(Resource resource) {
Asset asset = resource.adaptTo(Asset.class);
ResourceBinary binary = null;
if (asset != null) {
binary = new ResourceBinary();
binary.setName(asset.getName());
binary.setPath(resource.getPath());
binary.setContentType(asset.getMimeType());
// get original rendition
Rendition original = asset.getOriginal();
if (original != null) {
binary.setSize(original.getSize());
binary.setStream(original.getStream());
return binary;
}
}
return binary;
}
示例5: getRendition
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
/**
* Gets the rendition which matches against the constructor's Regex pattern.
* <p>
* If no matches are made and an Original exists, returns the Original.
* <p>
* If no matches are made and an Original doesn't exist, return the first Rendition.
*
* @param asset Asset whose Renditions will be selected.
* @return The first rendition whose name matches the supplied pattern (via constructor).
*/
@Override
public final Rendition getRendition(final Asset asset) {
final List<Rendition> renditions = asset.getRenditions();
final Pattern p = getPattern();
boolean hasOriginal = asset.getOriginal() != null;
boolean hasRenditions = renditions.size() > 0;
for (final Rendition rendition : renditions) {
final Matcher m = p.matcher(rendition.getName());
if (m.find()) {
return rendition;
}
}
if (hasOriginal) {
return asset.getOriginal();
} else if (hasRenditions) {
return renditions.get(0);
} else {
return null;
}
}
示例6: internalBuild
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Override
protected Asset internalBuild() throws Exception {
ContentBuilder content = client.getContentBuilder();
String path = path();
if (StringUtils.isBlank(path)) {
throw new RuntimeException("Cannot build asset with null path.");
}
if (hasValue("classpathResource") && StringUtils.isNotBlank(classpathResource())) {
this.result = content.asset(path, classpathResource(), mimetype(), metadata());
} else if (hasValue("inputStream")) {
this.result = content.asset(path, inputStream(), mimetype(), metadata());
} else {
this.result = content.asset(path, width(), height(), mimetype(), metadata());
}
if (hasChildren("renditions")) {
for (RenditionBuilder cur : renditions()) {
cur.build();
if (cur.hasInputStream()) {
content.assetRendition(result, cur.name(), cur.inputStream(), cur.mimetype());
} else if (StringUtils.isNotBlank(cur.classpathResource())) {
content.assetRendition(result, cur.name(), cur.classpathResource(), cur.mimetype());
} else {
content.assetRendition(result, cur.name(), cur.width(), cur.height(), cur.mimetype());
}
}
}
return result;
}
示例7: getMetadataValueReturnsMetadataValue
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Test
public void getMetadataValueReturnsMetadataValue() throws Exception {
Asset target = anAsset("/libs/quatico/base/templates/backend/thumbnail.png", "dam:Fileformat", "PNG");
String actual = target.getMetadataValue("dam:Fileformat");
assertEquals("PNG", actual);
}
示例8: getRenditionStringWithExistingNameReturnsRendition
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Test
public void getRenditionStringWithExistingNameReturnsRendition() throws Exception {
Asset target = anAsset("/libs/quatico/base/templates/backend/thumbnail.png");
target.addRendition("cq5dam.thumbnail.48.48.png", ContentBuilder.createDummyImage(1, 1, EMPTY), EMPTY);
Rendition actual = target.getRendition("cq5dam.thumbnail.48.48.png");
assertEquals("cq5dam.thumbnail.48.48.png", actual.getName());
}
示例9: getOriginalWithExistingRenditionReturnsOriginal
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Test
public void getOriginalWithExistingRenditionReturnsOriginal() throws Exception {
Asset target = anAsset("/libs/quatico/base/templates/backend/thumbnail.png");
Rendition actual = target.getOriginal();
assertEquals("original", actual.getName());
}
示例10: listRenditionsWithExistingRendtionsIsNotEmpty
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Test
public void listRenditionsWithExistingRendtionsIsNotEmpty() throws Exception {
Asset target = anAsset("/libs/quatico/base/templates/backend/thumbnail.png");
Iterator<Rendition> actual = target.listRenditions();
assertTrue(actual.hasNext());
}
示例11: apply
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
public Rendition apply(Asset asset) {
InputStream stream = null;
Rendition var3;
try {
stream = RenditionMakerImpl.this.gfx.render(this.plan, ((Resource)asset.adaptTo(Resource.class)).getResourceResolver());
if(stream == null) {
return null;
}
var3 = asset.addRendition(this.renditionName, stream, this.mimeType);
} finally {
IOUtils.closeQuietly(stream);
}
return var3;
}
示例12: findTag
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
public Tag findTag(String tagId, Asset asset, Session session) {
Tag tag = null;
ResourceResolver resourceResolver = null;
try {
resourceResolver = getResourceResolver(session);
TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
tag = tagManager.resolve(tagId);
} finally {
if (null != resourceResolver && resourceResolver.isLive()) {
resourceResolver.close();
}
}
return tag;
}
示例13: indexData
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Override
public void indexData(Map<String, Object> data, Resource resource, String containerPath) {
Asset asset = resource.adaptTo(Asset.class);
if (asset != null) {
data.put(IndexFields.PATH, asset.getPath());
Object tagsArr = asset.getMetadata(NameConstants.PN_TAGS);
if (tagsArr != null && tagsArr instanceof Object[]) {
Object[] tags = (Object[]) tagsArr;
for (Object tag : tags) {
putMultiValue(data, IndexFields.TAGS, tag.toString());
}
}
String title = StringUtils.trimToNull((String) asset.getMetadataValue("dc:title"));
if (title == null || title.trim().length() == 0) {
title = asset.getName();
}
data.put(IndexFields.TITLE, title);
}
}
示例14: getReplicationStatusResource
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Resource getReplicationStatusResource(String path, ResourceResolver resourceResolver) {
final Page page = resourceResolver.adaptTo(PageManager.class).getContainingPage(path);
final Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(path));
Resource resource;
String type;
if (page != null) {
type = "Page";
resource = page.getContentResource();
} else if (asset != null) {
type = "Asset";
Resource assetResource = resourceResolver.getResource(asset.getPath());
resource = assetResource.getChild(JcrConstants.JCR_CONTENT);
} else {
type = "Resource";
resource = resourceResolver.getResource(path);
}
log.trace(type + "'s resource that tracks replication status is " + resource.getPath());
return resource;
}
示例15: invoke
import com.day.cq.dam.api.Asset; //导入依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
Asset asset = (Asset) proxy;
switch (methodName) {
case "adaptTo":
return adaptTo((Class<?>) args[0]);
case "getMetadataValue":
return getMetadataValue((String) args[0]);
case "isSubAsset":
return isSubAsset();
case "getRenditions":
return getRenditions(asset);
case "getSubAssets":
return getSubAssets();
default:
LOG.error("FROZEN ASSET >> NO IMPLEMENTATION FOR "+methodName);
throw new UnsupportedOperationException();
}
}