本文整理汇总了Java中com.day.cq.dam.api.Asset.getOriginal方法的典型用法代码示例。如果您正苦于以下问题:Java Asset.getOriginal方法的具体用法?Java Asset.getOriginal怎么用?Java Asset.getOriginal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.day.cq.dam.api.Asset
的用法示例。
在下文中一共展示了Asset.getOriginal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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;
}
}
示例4: 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());
}
示例5: getSize
import com.day.cq.dam.api.Asset; //导入方法依赖的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();
}
示例6: doGet
import com.day.cq.dam.api.Asset; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws IOException, ServletException {
//TODO: put all of the logic in a context processor (need to fix templating support filter bug first)
String transformName = BLANK;
if (PathInfoUtil.getSuffixSegments(request).length == 2) {
String firstSuffixSegment = PathInfoUtil.getFirstSuffixSegment(request);
if (this.namedImageTransformers.keySet().contains(firstSuffixSegment)) {
transformName = firstSuffixSegment;
}
}
//Adds the asset binary to the inputStream
try {
Resource assetResource = getAssetResource(request);
if (DamUtil.isAsset(assetResource)) {
Binary binary;
String mimeType = BLANK;
Asset asset = DamUtil.resolveToAsset(assetResource);
Resource original = asset.getOriginal();
Node assetNode = original.adaptTo(Node.class);
if (assetNode.hasNode(JCR_CONTENT)) {
Node assetInfo = assetNode.getNode(JCR_CONTENT);
if (assetInfo.hasProperty(JCR_MIMETYPE)) {
mimeType = assetInfo.getProperty(JCR_MIMETYPE).getString();
}
if (StringUtils.isNotBlank(mimeType)) {
response.setContentType(mimeType);
}
binary = assetInfo.getProperty(JCR_DATA).getBinary();
InputStream inputStream = binary.getStream();
OutputStream outputStream = response.getOutputStream();
boolean shouldTransform = StringUtils.isNotBlank(transformName);
if (shouldTransform && ImageUtils.isImage(assetResource)) {
double quality = 1;
double maxGifQuality = 255;
// Transform the image
final Layer layer = new Layer(inputStream, new Dimension(maxWidth, maxHeight));
Layer newLayer = null;
try {
final NamedImageTransformer namedImageTransformer = this.namedImageTransformers.get(transformName);
newLayer = namedImageTransformer.transform(layer);
if (StringUtils.isBlank(mimeType) || !ImageIO.getImageWritersByMIMEType(mimeType).hasNext()) {
mimeType = getImageMimeType(layer, asset.getName());
response.setContentType(mimeType);
}
// For GIF images the colors will be reduced according to the quality argument.
if (StringUtils.equals(mimeType, GIF_MIME_TYPE)) {
quality = quality * maxGifQuality;
}
newLayer.write(mimeType, quality, outputStream);
} finally {
if (layer != null) {
layer.dispose();
}
if (newLayer != null) {
newLayer.dispose();
}
}
} else {
ByteStreams.copy(inputStream, outputStream);
}
response.flushBuffer();
outputStream.close();
}
}
} catch (RepositoryException repoException) {
LOGGER.error("Repository Exception. ", repoException);
}
}