com.swfit.core.xhtml
Class XHTMLDocument

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--com.swfit.core.xhtml.XHTMLDocument
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.io.Serializable

public class XHTMLDocument
extends java.util.Vector

The XHTMLDocument is a XHTML document dummy that can either be read from disk, from a url, or if the file does not exist, is put together from a XHTML skeleton. Whenever the source file is changed, the source file is re-read - unless data has been added. The purpose of this class is to store an often used XHTML documet in memory. The XHTMLDocument should always consist of at least four byte arrays of text - between which there can be inserted a title and two XHTML body parts as chunks of bytes. The different chunks of bytes are never manipulated directly, and only shallowly copied, so several instances of this class might just be the same chunks of bytes arranged in different sequences. It is the responsibility of the programmer to keep track of how the indexes change - and for that reason it is a good habit to insert the XHTML data backwards (ie first the body parts, and then the title parts).

Note I: To implement cacheing for both files and urls, we need to store some kind of info describing the state of the file. For regular files we store the file.lastModified () date, but for URLs we got a problem, since Apache will not send any Last-Modified header for *.shtml files. As a workaround we store the content length, and hope that will suffice.

Note II: We implement a cacheing mechanism for these text files, to make the rendering of XHTML pages more efficient.

Since:
SWFIT1.0
Version:
$Revision: 1.4 $ $Date: 2003/02/03 04:42:24 $
Author:
Olaf Havnes
See Also:
Serialized Form

Field Summary
static int BUF_SIZE
          How large a file should we read ?
static java.lang.String DELIM
          The String which splits a XHTML dummy file into separate parts.
static int NEEDED_ELEMENTS
          The XHTMLDocument should always consist of at least four byte arrays of text - between which there can be inserted a title and two XHTML body parts as chunks of bytes.
static int NUM_BUF
          How large a file should we read ?
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
XHTMLDocument()
          Creates a new XHTMLDocument instance with no source file.
 
Method Summary
 byte[][] allParts()
          Returns all the data, both read and inserted, from this XHTMLDocument.
 XHTMLDocument copy()
          Duplicates the current XHTMLDocument instance without passing along the source file.
static XHTMLDocument getStyleXHTMLDocument()
          Cache XHTMLDocuments for quick access
static XHTMLDocument getXHTMLDocument(java.io.File file)
           
static XHTMLDocument getXHTMLDocument(java.net.URL url)
           
 void insert(byte[] bytes, int i)
          Inserts an array of bytes into this XHTMLDocument.
 void insert(java.lang.StringBuffer str_b, int i)
          Inserts a StringBuffer as an array of bytes into this XHTMLDocument.
 void insert(java.lang.String str, int i)
          Inserts a String as an array of bytes into this XHTMLDocument.
 void insertPartOne(java.lang.StringBuffer str_b)
           
 void insertPartTwo(java.lang.StringBuffer str_b)
           
 void insertTitle(java.lang.String str)
          Inserts a StringBuffer as an array of bytes into this XHTMLDocument at different places, keeping track of the indexes.
 int size()
          Overrides the superclass method to make sure that the source data has been read from disk when the size is returnd.
protected  byte[][] skeletonBytes()
           
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

BUF_SIZE

public static final int BUF_SIZE
How large a file should we read ?

NUM_BUF

public static final int NUM_BUF
How large a file should we read ?

NEEDED_ELEMENTS

public static final int NEEDED_ELEMENTS
The XHTMLDocument should always consist of at least four byte arrays of text - between which there can be inserted a title and two XHTML body parts as chunks of bytes.

DELIM

public static final java.lang.String DELIM
The String which splits a XHTML dummy file into separate parts.
Constructor Detail

XHTMLDocument

public XHTMLDocument()
Creates a new XHTMLDocument instance with no source file.
Method Detail

getStyleXHTMLDocument

public static final XHTMLDocument getStyleXHTMLDocument()
Cache XHTMLDocuments for quick access

getXHTMLDocument

public static final XHTMLDocument getXHTMLDocument(java.io.File file)

getXHTMLDocument

public static final XHTMLDocument getXHTMLDocument(java.net.URL url)

skeletonBytes

protected byte[][] skeletonBytes()

copy

public final XHTMLDocument copy()
Duplicates the current XHTMLDocument instance without passing along the source file. The chunks of bytes are shallow copies, so several instances of this class might just be the same chunks of bytes.

size

public final int size()
Overrides the superclass method to make sure that the source data has been read from disk when the size is returnd.
Overrides:
size in class java.util.Vector
Returns:
The number of elements the XHTMLDocument consists of.
See Also:
Vector.size()

insertTitle

public final void insertTitle(java.lang.String str)
                       throws java.io.IOException
Inserts a StringBuffer as an array of bytes into this XHTMLDocument at different places, keeping track of the indexes.

insertPartOne

public final void insertPartOne(java.lang.StringBuffer str_b)
                         throws java.io.IOException

insertPartTwo

public final void insertPartTwo(java.lang.StringBuffer str_b)
                         throws java.io.IOException

insert

public final void insert(java.lang.StringBuffer str_b,
                         int i)
                  throws java.io.IOException
Inserts a StringBuffer as an array of bytes into this XHTMLDocument. It is the responsibility of the programmer to keep track of how the indexes change - and for that reason it is a good habit to insert the XHTML data backwards (ie first the body parts, and then the title parts).

insert

public final void insert(java.lang.String str,
                         int i)
                  throws java.io.IOException
Inserts a String as an array of bytes into this XHTMLDocument. It is the responsibility of the programmer to keep track of how the indexes change - and for that reason it is a good habit to insert the XHTML data backwards (ie first the body parts, and then the title parts).

insert

public final void insert(byte[] bytes,
                         int i)
                  throws java.io.IOException
Inserts an array of bytes into this XHTMLDocument. It is the responsibility of the programmer to keep track of how the indexes change - and for that reason it is a good habit to insert the XHTML data backwards (ie first the body parts, and then the title parts).

allParts

public final byte[][] allParts()
                        throws java.io.IOException
Returns all the data, both read and inserted, from this XHTMLDocument.
Returns:
The xhtml data as an array of byte arrays


Swfit developer homepage
Copyright © 2003 Orgdot AS. All Rights Reserved.