/** {@inheritDoc} */
public void activateLayout() {
initialize();
FOUserAgent userAgent = pageSeq.getUserAgent();
ImageManager imageManager = userAgent.getFactory().getImageManager();
String uri = URISpecification.getURL(getExternalDocument().getSrc());
Integer firstPageIndex = ImageUtil.getPageIndexFromURI(uri);
boolean hasPageIndex = (firstPageIndex != null);
try {
ImageInfo info = imageManager.getImageInfo(uri, userAgent.getImageSessionContext());
Object moreImages = info.getCustomObjects().get(ImageInfo.HAS_MORE_IMAGES);
boolean hasMoreImages = moreImages != null && !Boolean.FALSE.equals(moreImages);
Dimension intrinsicSize = info.getSize().getDimensionMpt();
ImageLayout layout = new ImageLayout(getExternalDocument(), this, intrinsicSize);
PageSequence pageSequence = new PageSequence(null);
transferExtensions(pageSequence);
areaTreeHandler.getAreaTreeModel().startPageSequence(pageSequence);
if (log.isDebugEnabled()) {
log.debug("Starting layout");
}
makePageForImage(info, layout);
if (!hasPageIndex && hasMoreImages) {
if (log.isTraceEnabled()) {
log.trace("Starting multi-page processing...");
}
URI originalURI;
try {
originalURI = new URI(URISpecification.escapeURI(uri));
int pageIndex = 1;
while (hasMoreImages) {
URI tempURI = new URI(originalURI.getScheme(),
originalURI.getSchemeSpecificPart(),
"page=" + Integer.toString(pageIndex + 1));
if (log.isTraceEnabled()) {
log.trace("Subimage: " + tempURI.toASCIIString());
}
ImageInfo subinfo = imageManager.getImageInfo(
tempURI.toASCIIString(), userAgent.getImageSessionContext());
moreImages = subinfo.getCustomObjects().get(ImageInfo.HAS_MORE_IMAGES);
hasMoreImages = moreImages != null && !Boolean.FALSE.equals(moreImages);