pageContext.getRequestContext();
TestEnvironmentContext envContext =
(TestEnvironmentContext)pageContext.getEnvironmentContext();
// This asset exists
final DeviceImageAsset imageAsset =
new DeviceImageAsset(
"jug", 15, 15, 1,
ImageAsset.MONOCHROME, ImageAsset.JPEG,
"Master", null,
"/com/volantis/mcs/runtime/packagers/mime/jug.jpg");
// This asset does not
final DeviceImageAsset noImageAsset =
new DeviceImageAsset(
"nojug", 15, 15, 1,
ImageAsset.MONOCHROME, ImageAsset.JPEG,
"Master", null,
"/com/volantis/mcs/runtime/packagers/mime/nojug.jpg");
final StringBuffer bodyContent = new StringBuffer();
PackageBodySource bodySource = new PackageBodySource() {
public void write(PackageBodyOutput writer,
MarinerRequestContext context, Object bodyContext)
throws PackagingException {
try {
bodyContent.append("<html><body><div><img src=\"").
append(handler.rewriteAssetURL(
context, imageAsset,
null, new MarinerURL(imageAsset.getValue())).
getExternalForm()).
append("\"/></div><div><img src=\"").
append(handler.rewriteAssetURL(
context, noImageAsset,
null, new MarinerURL(noImageAsset.getValue())).
getExternalForm()).
append("\"/></div></body></html>");
writer.getWriter().write(bodyContent.toString());
} catch (RepositoryException e) {
throw new PackagingException(e);