Package nl.siegmann.epublib.viewer
Class HTMLDocumentFactory
- java.lang.Object
-
- nl.siegmann.epublib.viewer.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classHTMLDocumentFactory.DocumentIndexer
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.locks.ReentrantReadWriteLockcacheLockprivate java.util.concurrent.locks.LockcacheReadLockprivate java.util.concurrent.locks.LockcacheWriteLockstatic intDOCUMENT_CACHE_INDEXER_WAIT_TIMEprivate java.util.Map<java.lang.String,javax.swing.text.html.HTMLDocument>documentCacheprivate MyHtmlEditorKiteditorKitprivate ImageLoaderCacheimageLoaderCacheprivate static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description HTMLDocumentFactory(Navigator navigator, javax.swing.text.EditorKit editorKit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private javax.swing.text.html.HTMLDocumentcreateDocument(Resource resource)Creates a swing HTMLDocument from the given resource.javax.swing.text.html.HTMLDocumentgetDocument(Resource resource)Get the HTMLDocument representation of the resource.voidinit(Book book)private voidinitDocumentCache(Book book)voidnavigationPerformed(NavigationEvent navigationEvent)Called whenever the user navigates to another position in the book.private voidputDocument(Resource resource, javax.swing.text.html.HTMLDocument document)private static java.lang.StringremoveControlTags(java.lang.String input)Quick and dirty stripper of all <?...> and <!...> tags as these confuse the html viewer.private java.lang.StringstripHtml(java.lang.String input)
-
-
-
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
-
imageLoaderCache
private ImageLoaderCache imageLoaderCache
-
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
-
editorKit
private MyHtmlEditorKit editorKit
-
-
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)
-
navigationPerformed
public void navigationPerformed(NavigationEvent navigationEvent)
Description copied from interface:NavigationEventListenerCalled whenever the user navigates to another position in the book.- Specified by:
navigationPerformedin interfaceNavigationEventListener
-
-