]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Attempt at providing context information about the element causing an endless loop...
authorJeremias Maerki <jeremias@apache.org>
Thu, 15 Dec 2005 10:57:45 +0000 (10:57 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 15 Dec 2005 10:57:45 +0000 (10:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@357002 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/FONode.java
src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java

index eeab9f4076b02756c47233e4a8bca3348bea70f1..84d04b2c041f65ec400331e9f143bd2c831948c1 100644 (file)
@@ -455,9 +455,13 @@ public abstract class FONode implements Cloneable {
      * @return the decorated text
      */
     public static String decorateWithContextInfo(String text, FONode node) {
-        StringBuffer sb = new StringBuffer(text);
-        sb.append(" (").append(node.getContextInfo()).append(")");
-        return sb.toString();
+        if (node != null) {
+            StringBuffer sb = new StringBuffer(text);
+            sb.append(" (").append(node.getContextInfo()).append(")");
+            return sb.toString();
+        } else {
+            return text;
+        }
     }
     
     /**
index 92d5c08d3d59fed158e6fb86a4ddea02773a4179..c290f5b13fb461bf12cc1bbc57ae3514265581d3 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.fo.FONode;
 import org.apache.fop.traits.MinOptMax;
 
 /**
@@ -427,9 +428,11 @@ public abstract class BreakingAlgorithm {
                         log.debug("first part doesn't fit into line, recovering: " 
                                 + node.fitRecoveryCounter);
                         if (node.fitRecoveryCounter > getMaxRecoveryAttempts()) {
-                            throw new RuntimeException("Some content could not fit "
+                            FONode contextFO = findContextFO(par, node.position + 1);
+                            throw new RuntimeException(FONode.decorateWithContextInfo(
+                                    "Some content could not fit "
                                     + "into a line/page after " + getMaxRecoveryAttempts() 
-                                    + " attempts. Giving up to avoid an endless loop.");
+                                    + " attempts. Giving up to avoid an endless loop.", contextFO));
                         }
                     } else {
                         lastForced = lastTooLong;
@@ -464,6 +467,33 @@ public abstract class BreakingAlgorithm {
         return line;
     }
 
+    /**
+     * This method tries to find the context FO for a position in a KnuthSequence.
+     * @param seq the KnuthSequence to inspect
+     * @param position the index of the position in the KnuthSequence
+     * @return the requested context FO note or null, if no context node could be determined
+     */
+    private FONode findContextFO(KnuthSequence seq, int position) {
+        KnuthElement el = seq.getElement(position);
+        while (el.getLayoutManager() == null && position < seq.size() - 1) {
+            position++;
+            el = seq.getElement(position);
+        }
+        Position pos = (el != null ? el.getPosition() : null);
+        LayoutManager lm = (pos != null ? pos.getLM() : null);
+        while (pos instanceof NonLeafPosition) {
+            pos = ((NonLeafPosition)pos).getPosition();
+            if (pos != null && pos.getLM() != null) {
+                lm = pos.getLM();
+            }
+        }
+        if (lm != null) {
+            return lm.getFObj();
+        } else {
+            return null;
+        }
+    }
+
     protected void initialize() {
         this.totalWidth = 0;
         this.totalStretch = 0;