Class BuilderContext


  • public class BuilderContext
    extends java.lang.Object

    A BuilderContext holds context information when building an RTF document.

    This class was originally developed by Bertrand Delacretaz bdelacretaz@codeconsult.ch for the JFOR project and is now integrated into FOP.

    This work was authored by Bertrand Delacretaz (bdelacretaz@codeconsult.ch), Andreas Putz (a.putz@skynamics.com), and Peter Herweg (pherweg@web.de).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Stack builders
      stack of IBuilders
      private java.util.Stack containers
      stack of RtfContainers
      protected static org.apache.commons.logging.Log LOG
      Static logging instance
      private IRtfOptions options
      Rtf options
      private java.util.Stack tableContexts
      stack of TableContexts
    • Constructor Summary

      Constructors 
      Constructor Description
      BuilderContext​(IRtfOptions rtfOptions)
      Construct a builder context.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      RtfContainer getContainer​(java.lang.Class containerClass, boolean required, java.lang.Object forWhichBuilder)
      Find the "nearest" container that implements the given interface on our stack.
      private java.lang.Object getObjectFromStack​(java.util.Stack s, java.lang.Class desiredClass)
      find first object of given class from top of stack s
      TableContext getTableContext()  
      private void handlePop​(java.lang.Class aClass, RTFHandler handler)
      This method checks for any tag mismatches between what is being closed and what exists on the stack.
      void popContainer​(java.lang.Class containerClass, RTFHandler handler)
      pop the topmost RtfContainer from our stack
      void popPart​(java.lang.Class part, RTFHandler handler)
      pop the topmost part class from our stack
      void popTableContext()
      Pop a TableContext from our stack.
      private void pushAndClose​(java.lang.Class aClass, java.lang.Object object, RTFHandler handler)  
      void pushContainer​(RtfContainer c)
      Push an RtfContainer on our stack.
      void pushPart​(FObj part)
      Push a Class representing a non-writeable section of the FO tree
      void pushTableContext​(TableContext tc)
      Push a TableContext to our stack.
      void replaceContainer​(RtfContainer oldC, RtfContainer newC)
      In some cases an RtfContainer must be replaced by another one on the stack.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        protected static final org.apache.commons.logging.Log LOG
        Static logging instance
      • containers

        private final java.util.Stack containers
        stack of RtfContainers
      • tableContexts

        private final java.util.Stack tableContexts
        stack of TableContexts
      • builders

        private final java.util.Stack builders
        stack of IBuilders
    • Constructor Detail

      • BuilderContext

        public BuilderContext​(IRtfOptions rtfOptions)
        Construct a builder context.
        Parameters:
        rtfOptions - some options
    • Method Detail

      • getObjectFromStack

        private java.lang.Object getObjectFromStack​(java.util.Stack s,
                                                    java.lang.Class desiredClass)
        find first object of given class from top of stack s
        Returns:
        null if not found
      • getContainer

        public RtfContainer getContainer​(java.lang.Class containerClass,
                                         boolean required,
                                         java.lang.Object forWhichBuilder)
                                  throws RtfException
        Find the "nearest" container that implements the given interface on our stack.
        Parameters:
        containerClass - class of container
        required - if true, ConverterException is thrown if no container found
        forWhichBuilder - used in error message if container not found
        Returns:
        the container
        Throws:
        RtfException - if not caught
      • pushContainer

        public void pushContainer​(RtfContainer c)
        Push an RtfContainer on our stack.
        Parameters:
        c - the container
      • pushPart

        public void pushPart​(FObj part)
        Push a Class representing a non-writeable section of the FO tree
        Parameters:
        part - the part
      • replaceContainer

        public void replaceContainer​(RtfContainer oldC,
                                     RtfContainer newC)
                              throws java.lang.Exception
        In some cases an RtfContainer must be replaced by another one on the stack. This happens when handling nested fo:blocks for example: after handling a nested block the enclosing block must switch to a new paragraph container to handle what follows the nested block. TODO: what happens to elements that are "more on top" than oldC on the stack? shouldn't they be closed or something?
        Parameters:
        oldC - old container
        newC - new container
        Throws:
        java.lang.Exception - if not caught
      • popContainer

        public void popContainer​(java.lang.Class containerClass,
                                 RTFHandler handler)
        pop the topmost RtfContainer from our stack
      • popPart

        public void popPart​(java.lang.Class part,
                            RTFHandler handler)
        pop the topmost part class from our stack
      • handlePop

        private void handlePop​(java.lang.Class aClass,
                               RTFHandler handler)
        This method checks for any tag mismatches between what is being closed and what exists on the stack. If a mismatch is found, then it will push the object back onto the stack and attempt to close the given section before retrying with the current pop task.
        Parameters:
        aClass - The class to be popped from the stack
        handler - The RTF handler class to fix any mismatches
      • pushAndClose

        private void pushAndClose​(java.lang.Class aClass,
                                  java.lang.Object object,
                                  RTFHandler handler)
      • getTableContext

        public TableContext getTableContext()
        Returns:
        the current TableContext
      • pushTableContext

        public void pushTableContext​(TableContext tc)
        Push a TableContext to our stack.
        Parameters:
        tc - the table context
      • popTableContext

        public void popTableContext()
        Pop a TableContext from our stack.