SelectedVariant selectedVariant = selectVariant(src);
if(selectedVariant == null) {
throw new XDIMEException("best selected variant not accessible");
}
AssetResolver assetResolver = pageContext.getAssetResolver();
// The external link rendered for device independent resource will have
// correct URL if used device support encoding from selected variant
// otherwise returned variant will be null because selected variant is
// filtered by PolicyVariantSelector#filter method
Variant variant = selectedVariant.getVariant();
VariantType variantType = null;
if(variant != null) {
variantType = variant.getVariantType();
}
// for MTXT resource
if (variantType == VariantType.TEXT) {
PolicyReferenceResolver resolver = pageContext
.getPolicyReferenceResolver();
TextAssetReference textReference = resolver
.resolveUnquotedTextExpression(src);
final String text = textReference.getText(TextEncoding.PLAIN);
if (text != null) {
// We have found the text, so let's try and write it out to
// attributes
attributes.setTextContainer(text);
} else {
if (logger.isDebugEnabled()) {
logger.debug("No text exists for text asset " + src);
}
}
// remove src pointed at text component
attributes.setSrc(null);
// remove srcType which contains list of device independent mime
// types
attributes.setSrcType(null);
}
// retrieve url only for IMAGE, AUDIO and VIDEO resource so far
String url = assetResolver.retrieveVariantURLAsString(selectedVariant);
// get dimensions for image and video and save it to params into
// attributes
if (variantType == VariantType.IMAGE
|| variantType == VariantType.VIDEO) {
PixelDimensionsMetaData dimMetaData =
(PixelDimensionsMetaData) selectedVariant
.getVariant().getMetaData();
// get the Map of parameters
Map params = attributes.getParamMap();
// save height and width in pixels unit to object's parameter map
if (dimMetaData.getHeight() != 0) {
params.put("height", StringConvertor.valueOf(dimMetaData
.getHeight()));
}
if (dimMetaData.getWidth() != 0) {
params.put("width", StringConvertor.valueOf(dimMetaData
.getWidth()));
}
}
// convert image if needed
if (variantType == VariantType.IMAGE) {
ImageMetaData imageMetaData = (ImageMetaData) selectedVariant
.getVariant().getMetaData();
// image must be convert
if (url != null
&& imageMetaData.getConversionMode() ==
ImageConversionMode.ALWAYS_CONVERT) {
url = assetResolver.rewriteURLWithPageURLRewriter(url,
PageURLType.IMAGE);
attributes.setConvertibleImageAsset(true);
}
}