本文整理汇总了Java中com.day.cq.dam.api.Rendition类的典型用法代码示例。如果您正苦于以下问题:Java Rendition类的具体用法?Java Rendition怎么用?Java Rendition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rendition类属于com.day.cq.dam.api包,在下文中一共展示了Rendition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.day.cq.dam.api.Rendition; //导入依赖的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);
}
}
示例2: resolveRendition
import com.day.cq.dam.api.Rendition; //导入依赖的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;
}
示例3: getBinary
import com.day.cq.dam.api.Rendition; //导入依赖的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;
}
示例4: getRendition
import com.day.cq.dam.api.Rendition; //导入依赖的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;
}
}
示例5: getRenditionStringWithExistingNameReturnsRendition
import com.day.cq.dam.api.Rendition; //导入依赖的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());
}
示例6: getOriginalWithExistingRenditionReturnsOriginal
import com.day.cq.dam.api.Rendition; //导入依赖的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());
}
示例7: listRenditionsWithExistingRendtionsIsNotEmpty
import com.day.cq.dam.api.Rendition; //导入依赖的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());
}
示例8: apply
import com.day.cq.dam.api.Rendition; //导入依赖的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;
}
示例9: writeResponse
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
private static void writeResponse(SlingHttpServletResponse response, Rendition rendition) throws IOException {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = rendition.getStream();
outputStream = response.getOutputStream();
// NOTE: This does not matter if dispatcher serves image
// Dispatcher will use extension of file, it does not save HTTP Content-Type header
response.setContentType(rendition.getMimeType());
IOUtils.copy(inputStream, outputStream);
} finally {
if (inputStream != null) inputStream.close();
if (outputStream != null) outputStream.close();
}
}
示例10: getSize
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
/**
* Get the size of the Asset (the original rendition).
*
* @param asset
* @return
*/
private static long getSize(final Asset asset) {
final Rendition original = asset.getOriginal();
if (original == null) {
return 0;
}
return original.getSize();
}
示例11: processLayer
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
@Override
protected Layer processLayer(Layer layer, Rendition rendition, WorkflowSession workflowSession, String[] args) {
final String watermarkPath = workflowHelper.getValuesFromArgs(ARG_WATERMARK, args).size() > 0 ? workflowHelper.getValuesFromArgs(
ARG_WATERMARK, args).get(0) : null;
if (watermarkPath != null) {
Layer watermark = null;
try {
watermark = getLayer(watermarkPath, workflowSession);
if (watermark != null) {
addWatermark(layer, watermark);
}
} catch (LoginException e) {
log.error("Unable to log into repository.", e);
} finally {
if (watermark != null) {
watermark.dispose();
watermark = null;
}
}
} else {
log.info("No watermark specified. Skipping.");
}
return layer;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:27,代码来源:AddWatermarkToRenditionProcess.java
示例12: getRenditionsWithExistingRenditionsIsNotEmpty
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
@Test
public void getRenditionsWithExistingRenditionsIsNotEmpty() throws Exception {
Asset target = anAsset("/libs/quatico/base/templates/backend/thumbnail.png");
List<Rendition> actual = target.getRenditions();
assertFalse(actual.isEmpty());
}
示例13: assetWithRenditionAndExistingNameYieldsRendition
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
@Test
public void assetWithRenditionAndExistingNameYieldsRendition() throws Exception {
Asset target = testObj.anAsset().path("/libs/quatico/base/templates/backend/thumbnail.png").rendition(
testObj.anAssetRendition().name("cq5dam.thumbnail.48.48.png").inputStream(ContentBuilder.createDummyImage(1, 1, EMPTY))
).build();
Rendition actual = target.getRendition("cq5dam.thumbnail.48.48.png");
assertEquals("cq5dam.thumbnail.48.48.png", actual.getName());
}
示例14: getAWebRendition
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
/**
* Given an {@link Asset}, this method will return the first web {@link Rendition} it finds in the asset's renditions list.
*
* @param asset the asset for which to retrieve the web rendition
* @return the rendition, if found, {@code null} otherwise
*/
private Rendition getAWebRendition(Asset asset) {
List<Rendition> renditions = asset.getRenditions();
for (Rendition rendition : renditions) {
if (rendition.getName().startsWith(DamConstants.PREFIX_ASSET_WEB)) {
return rendition;
}
}
return null;
}
示例15: init
import com.day.cq.dam.api.Rendition; //导入依赖的package包/类
@Before
public void init() throws IOException {
resourceResolver = CONTEXT.resourceResolver();
servlet = new AdaptiveImageServlet();
Whitebox.setInternalState(servlet, "mimeTypeService", mockedMimeTypeService);
AssetHandler assetHandler = mock(AssetHandler.class);
AssetStore assetStore = mock(AssetStore.class);
when(assetStore.getAssetHandler(anyString())).thenReturn(assetHandler);
when(assetHandler.getImage(any(Rendition.class))).thenAnswer(invocation -> {
Rendition rendition = invocation.getArgumentAt(0, Rendition.class);
return ImageIO.read(rendition.getStream());
});
Whitebox.setInternalState(servlet, "assetStore", assetStore);
activateServlet(servlet);
}