diff options
Diffstat (limited to 'src/java/org/apache/fop/area/LinkResolver.java')
-rw-r--r-- | src/java/org/apache/fop/area/LinkResolver.java | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/java/org/apache/fop/area/LinkResolver.java b/src/java/org/apache/fop/area/LinkResolver.java index 1e135701f..b458a1baf 100644 --- a/src/java/org/apache/fop/area/LinkResolver.java +++ b/src/java/org/apache/fop/area/LinkResolver.java @@ -20,6 +20,7 @@ package org.apache.fop.area; // Java +import java.util.ArrayList; import java.util.List; import java.io.Serializable; @@ -33,6 +34,7 @@ public class LinkResolver implements Resolvable, Serializable { private boolean resolved = false; private String idRef; private Area area; + private transient List<Resolvable> dependents = null; /** * Create a new link resolver. @@ -79,8 +81,35 @@ public class LinkResolver implements Resolvable, Serializable { public void resolveIDRef(String id, PageViewport pv) { if (idRef.equals(id) && pv != null) { resolved = true; - Trait.InternalLink iLink = new Trait.InternalLink(pv.getKey(), idRef); - area.addTrait(Trait.INTERNAL_LINK, iLink); + if ( area != null ) { + Trait.InternalLink iLink = new Trait.InternalLink(pv.getKey(), idRef); + area.addTrait(Trait.INTERNAL_LINK, iLink); + area = null; // break circular reference from basic link area to this resolver + } + resolveDependents(id, pv); } } + + /** + * Add dependent resolvable. Used to resolve second-order resolvables that + * depend on resolution of this resolver. + * @param dependent resolvable + */ + public void addDependent(Resolvable dependent) { + if ( dependents == null ) { + dependents = new ArrayList<Resolvable>(); + } + dependents.add(dependent); + } + + private void resolveDependents(String id, PageViewport pv) { + if ( dependents != null ) { + List<PageViewport> pages = new ArrayList<PageViewport>(); + pages.add(pv); + for ( Resolvable r : dependents ) { + r.resolveIDRef(id, pages); + } + } + } + } |