com.lizardtech.djvu
Class Document

java.lang.Object
  extended by com.lizardtech.djvu.DjVuObject
      extended by com.lizardtech.djvu.Document
All Implemented Interfaces:
DjVuInterface, java.lang.Cloneable, java.lang.Runnable

public class Document
extends DjVuObject
implements java.lang.Cloneable, java.lang.Runnable

This class represents indirect, bundled, and single page DjVu documents.

Version:
$Revision: 1.20 $
Author:
Bill C. Riemers

Field Summary
protected  java.util.Hashtable dataPoolMap
          A map of saved pages for this document.
static byte[] octets
          These are the magic numbers at the start of every DjVu file.
protected  java.util.Hashtable pageMap
          A Vector of soft links to decoded pages.
 
Fields inherited from class com.lizardtech.djvu.DjVuObject
hasReferences
 
Constructor Summary
Document()
          Creates a new Document object.
Document(java.net.URL url)
          Creates a new Document object.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a listener for property change events.
 java.lang.Object clone()
          Create a copy by value.
 DjVuPage createDjVuPage(java.net.URL url)
          Create an overloaded DjVuPage object
static Document createDocument(DjVuInterface ref)
          Creates an instance of Document with the options interherited from the specified reference.
 void delete_file(java.lang.String id)
          Remove the named file from the index
 DataPool get_data(int page_num)
          Query the data for a page.
 DataPool get_data(java.lang.String id)
          Query the data for the specified name.
 Codec getBookmark()
          Query the bookmark codec for this document
 DjVmDir getDjVmDir()
          Query the index for this document.
 DjVuPage getPage(int pageno, int priority, boolean dataWait)
          Get the respective page and start decoding.
 DjVuPage getPage(java.lang.String id, int priority, boolean dataWait)
          Get the respective page and start decoding.
 int getPageno(java.lang.String url)
          Convert a relative url to a page number.
 java.lang.String getStatus()
          Query the status string.
 Document init(java.net.URL url)
          Initialize this document from the specified URL.
 void insert_file(DataPool pool, int file_type, java.lang.String name, java.lang.String id)
          Add a file to the index.
 void insert_file(DataPool pool, int file_type, java.lang.String name, java.lang.String id, java.lang.String title)
          Add a file to the index.
 void insert_file(DataPool pool, int file_type, java.lang.String name, java.lang.String id, java.lang.String title, int pos)
          Add a file to the index.
 void insert_file(DjVmDir.File f, DataPool data_pool)
          Insert a file.
 void insert_file(DjVmDir.File f, DataPool data_pool, int pos)
          Insert a file.
 void insert_file(java.io.InputStream input, int file_type, java.lang.String name, java.lang.String id)
          Add a file to the index.
 void insert_file(java.io.InputStream input, int file_type, java.lang.String name, java.lang.String id, java.lang.String title)
          Add a file to the index.
 void insert_file(java.io.InputStream input, int file_type, java.lang.String name, java.lang.String id, java.lang.String title, int pos)
          Add a file to the index.
 boolean isAsync()
          Query if the asynchronous flag is set.
 void prefetch()
          Call to prefetch all the data for this document.
 void read(DataPool data_pool)
          Called to initialize from the specified stream.
 void read(java.io.InputStream input)
          Called to initialize from the specified stream.
 void read(java.net.URL url)
          Called to initialize from the specified stream.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a listener for PropertyChangeEvent.
 void run()
          This run method is called by the thread created with prefetch()
 void setAsync(boolean value)
          Set the flag to allow or disallow asynchronous operations.
 void setStatus(java.lang.String status)
          Set the status string and fire a property change event "status".
 int size()
          Query the number of pages.
 
Methods inherited from class com.lizardtech.djvu.DjVuObject
checkLockTime, create, create, createSoftReference, createWeakReference, getDjVuOptions, getFromReference, invoke, setDjVuOptions
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

octets

public static final byte[] octets
These are the magic numbers at the start of every DjVu file.


dataPoolMap

protected java.util.Hashtable dataPoolMap
A map of saved pages for this document.


pageMap

protected java.util.Hashtable pageMap
A Vector of soft links to decoded pages.

Constructor Detail

Document

public Document()
Creates a new Document object.


Document

public Document(java.net.URL url)
         throws java.io.IOException
Creates a new Document object.

Parameters:
url - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a listener for property change events.

Parameters:
listener - to add

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a listener for PropertyChangeEvent.

Parameters:
listener - to remove

setStatus

public void setStatus(java.lang.String status)
Set the status string and fire a property change event "status".

Parameters:
status - new status string

getStatus

public java.lang.String getStatus()
Query the status string.

Returns:
the status string

createDocument

public static Document createDocument(DjVuInterface ref)
Creates an instance of Document with the options interherited from the specified reference.

Parameters:
ref - Object to interherit DjVuOptions from.
Returns:
a new instance of Document.

setAsync

public final void setAsync(boolean value)
Set the flag to allow or disallow asynchronous operations.

Parameters:
value - true if asynchronous operations should be used.

isAsync

public final boolean isAsync()
Query if the asynchronous flag is set.

Returns:
true if the asynchronous operations are set.

getBookmark

public Codec getBookmark()
Query the bookmark codec for this document

Returns:
the bookmark codec or null

getDjVmDir

public DjVmDir getDjVmDir()
Query the index for this document.

Returns:
the index

getPage

public DjVuPage getPage(int pageno,
                        int priority,
                        boolean dataWait)
                 throws java.io.IOException
Get the respective page and start decoding. If synchronous decoding is used, this call will block until the page is decoded.

Parameters:
pageno - page number to get
priority - decode priority
dataWait - True if bundled pages should be opened even when the data is not ready.
Returns:
the DjVuPage object
Throws:
java.io.IOException - if an error occurs

getPage

public DjVuPage getPage(java.lang.String id,
                        int priority,
                        boolean dataWait)
                 throws java.io.IOException
Get the respective page and start decoding. If synchronous decoding is used, this call will block until the page is decoded.

Parameters:
id - the page name
priority - decode priority
dataWait - True if bundled pages should be opened even when the data is not ready.
Returns:
the DjVuPage object
Throws:
java.io.IOException - if an error occurs

getPageno

public int getPageno(java.lang.String url)
Convert a relative url to a page number. The first page number is page 0.

Parameters:
url - the relative url
Returns:
the page number

clone

public java.lang.Object clone()
Create a copy by value.

Overrides:
clone in class java.lang.Object
Returns:
the newly created copy

createDjVuPage

public DjVuPage createDjVuPage(java.net.URL url)
Create an overloaded DjVuPage object

Returns:
the newly created object

delete_file

public void delete_file(java.lang.String id)
                 throws java.io.IOException
Remove the named file from the index

Parameters:
id - name to remove
Throws:
java.io.IOException - if an error occurs

get_data

public DataPool get_data(java.lang.String id)
                  throws java.io.IOException
Query the data for the specified name.

Parameters:
id - name of the file
Returns:
the requested data
Throws:
java.io.IOException - if an error occurs

get_data

public DataPool get_data(int page_num)
                  throws java.io.IOException
Query the data for a page.

Parameters:
page_num - the page number to request
Returns:
the requested data
Throws:
java.io.IOException - if an error occurs

init

public Document init(java.net.URL url)
              throws java.io.IOException
Initialize this document from the specified URL.

Parameters:
url - the url to initialize from
Returns:
the initialized document
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(java.io.InputStream input,
                        int file_type,
                        java.lang.String name,
                        java.lang.String id)
                 throws java.io.IOException
Add a file to the index.

Parameters:
input - data to add
file_type - type of file to add
name - saved name
id - load name
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(java.io.InputStream input,
                        int file_type,
                        java.lang.String name,
                        java.lang.String id,
                        java.lang.String title)
                 throws java.io.IOException
Add a file to the index.

Parameters:
input - data to add
file_type - type of file to add
name - saved name
id - load name
title - file title
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(java.io.InputStream input,
                        int file_type,
                        java.lang.String name,
                        java.lang.String id,
                        java.lang.String title,
                        int pos)
                 throws java.io.IOException
Add a file to the index.

Parameters:
input - data to add
file_type - type of file to add
name - saved name
id - load name
title - file title
pos - position to insert
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(DataPool pool,
                        int file_type,
                        java.lang.String name,
                        java.lang.String id)
                 throws java.io.IOException
Add a file to the index.

Parameters:
pool - data to add
file_type - type of file to add
name - saved name
id - load name
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(DataPool pool,
                        int file_type,
                        java.lang.String name,
                        java.lang.String id,
                        java.lang.String title)
                 throws java.io.IOException
Add a file to the index.

Parameters:
pool - data to add
file_type - type of file to add
name - saved name
id - load name
title - file title
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(DataPool pool,
                        int file_type,
                        java.lang.String name,
                        java.lang.String id,
                        java.lang.String title,
                        int pos)
                 throws java.io.IOException
Add a file to the index.

Parameters:
pool - data to add
file_type - type of file to add
name - saved name
id - load name
title - file title
pos - position to insert
Throws:
java.io.IOException - if an error occurs

insert_file

public void insert_file(DjVmDir.File f,
                        DataPool data_pool)
                 throws java.io.IOException
Insert a file.

Parameters:
f - File to add
data_pool - data to add
Throws:
java.io.IOException - DOCUMENT ME!

insert_file

public void insert_file(DjVmDir.File f,
                        DataPool data_pool,
                        int pos)
                 throws java.io.IOException
Insert a file.

Parameters:
f - File to add
data_pool - data to add
pos - position to insert
Throws:
java.io.IOException - DOCUMENT ME!

prefetch

public void prefetch()
Call to prefetch all the data for this document.


read

public void read(java.io.InputStream input)
          throws java.io.IOException
Called to initialize from the specified stream.

Parameters:
input - stream to read
Throws:
java.io.IOException - if an error occurs

read

public void read(DataPool data_pool)
          throws java.io.IOException
Called to initialize from the specified stream.

Parameters:
data_pool - data to read
Throws:
java.io.IOException - if an error occurs

read

public void read(java.net.URL url)
          throws java.io.IOException
Called to initialize from the specified stream.

Parameters:
url - URL to read
Throws:
java.io.IOException - if an error occurs

run

public void run()
This run method is called by the thread created with prefetch()

Specified by:
run in interface java.lang.Runnable

size

public int size()
Query the number of pages.

Returns:
the number of pages.