Class HTMLDocumentFactory

  • All Implemented Interfaces:
    NavigationEventListener

    public class HTMLDocumentFactory
    extends java.lang.Object
    implements NavigationEventListener
    Creates swing HTML documents from resources. Between books the init(Book) function needs to be called in order for images to appear correctly.
    • Field Detail

      • log

        private static final org.slf4j.Logger log
      • DOCUMENT_CACHE_INDEXER_WAIT_TIME

        public static final int DOCUMENT_CACHE_INDEXER_WAIT_TIME
        See Also:
        Constant Field Values
      • cacheLock

        private java.util.concurrent.locks.ReentrantReadWriteLock cacheLock
      • cacheReadLock

        private java.util.concurrent.locks.Lock cacheReadLock
      • cacheWriteLock

        private java.util.concurrent.locks.Lock cacheWriteLock
      • documentCache

        private java.util.Map<java.lang.String,​javax.swing.text.html.HTMLDocument> documentCache
    • Constructor Detail

      • HTMLDocumentFactory

        public HTMLDocumentFactory​(Navigator navigator,
                                   javax.swing.text.EditorKit editorKit)
    • Method Detail

      • init

        public void init​(Book book)
      • putDocument

        private void putDocument​(Resource resource,
                                 javax.swing.text.html.HTMLDocument document)
      • getDocument

        public javax.swing.text.html.HTMLDocument getDocument​(Resource resource)
        Get the HTMLDocument representation of the resource. If the resource is not an XHTML resource then it returns null. It first tries to get the document from the cache. If the document is not in the cache it creates a document from the resource and adds it to the cache.
        Parameters:
        resource -
        Returns:
        the HTMLDocument representation of the resource.
      • stripHtml

        private java.lang.String stripHtml​(java.lang.String input)
      • removeControlTags

        private static java.lang.String removeControlTags​(java.lang.String input)
        Quick and dirty stripper of all <?...> and <!...> tags as these confuse the html viewer.
        Parameters:
        input -
        Returns:
        the input stripped of control characters
      • createDocument

        private javax.swing.text.html.HTMLDocument createDocument​(Resource resource)
        Creates a swing HTMLDocument from the given resource. If the resources is not of type XHTML then null is returned.
        Parameters:
        resource -
        Returns:
        a swing HTMLDocument created from the given resource.
      • initDocumentCache

        private void initDocumentCache​(Book book)