websphinx
Class Concatenator

java.lang.Object
  |
  +--websphinx.HTMLTransformer
        |
        +--websphinx.LinkTransformer
              |
              +--websphinx.RewritableLinkTransformer
                    |
                    +--websphinx.Concatenator

public class Concatenator
extends RewritableLinkTransformer

Transformer that concatenates multiple pages into a single HTML page.

The entire set of pages is preceded by a "prolog" and followed by an "epilog", which are constant strings of HTML. Each page is preceded by a "header" and followed by a "footer". Adjacent pages are separated by a "divider".

Concatenator performs the following transformations on pages before appending them together:


Field Summary
static java.lang.String defaultDivider
           
static java.lang.String defaultEpilog
           
static java.lang.String defaultFooter
           
static java.lang.String defaultHeader
           
static java.lang.String defaultProlog
           
 
Fields inherited from class websphinx.LinkTransformer
base, map
 
Constructor Summary
Concatenator(java.lang.String filename)
          Make a new Concatenator that writes to a file.
 
Method Summary
 void close()
          Close the concatenation.
 java.lang.String getDivider()
          Get the divider.
 java.lang.String getEpilog()
          Get the epilog.
 int getPageCount()
          Get number of pages written to this mirror.
 java.lang.String getPageFooter()
          Get the footer.
 java.lang.String getPageHeader()
          Get the header.
 java.lang.String getProlog()
          Get the prolog.
protected  void handleElement(Element elem)
          Process an HTML element for concatenation.
static void main(java.lang.String[] args)
           
 void rewrite()
          Rewrite the concatenation.
 void setDivider(java.lang.String divider)
          Set the divider.
 void setEpilog(java.lang.String epilog)
          Set the epilog.
 void setPageFooter(java.lang.String footer)
          Set the footer.
 void setPageHeader(java.lang.String header)
          Set the header.
 void setProlog(java.lang.String prolog)
          Set the prolog.
 void writePage(Page page)
          Write a page to the concatenation.
 
Methods inherited from class websphinx.RewritableLinkTransformer
handleLink
 
Methods inherited from class websphinx.LinkTransformer
getBase, getEmitBaseElement, handleBase, isMapped, lookup, map, map, setBase, setEmitBaseElement
 
Methods inherited from class websphinx.HTMLTransformer
emit, emit, finalize, flush, getFilePointer, getOutputStream, getOutputWriter, getRandomAccessFile, seek, setOutput, setRandomAccessFile, transformContents, transformElement, write, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultProlog

public static java.lang.String defaultProlog

defaultHeader

public static java.lang.String defaultHeader

defaultFooter

public static java.lang.String defaultFooter

defaultDivider

public static java.lang.String defaultDivider

defaultEpilog

public static java.lang.String defaultEpilog
Constructor Detail

Concatenator

public Concatenator(java.lang.String filename)
             throws java.io.IOException
Make a new Concatenator that writes to a file.

Parameters:
filename - Filename to write concatenated pages to
Throws:
java.io.IOException - if file cannot be opened
Method Detail

setProlog

public void setProlog(java.lang.String prolog)
Set the prolog.

Parameters:
prolog - string of HTML that is emitted at the beginning of the concatenation. Default value is:
<HTML><HEAD><TITLE>Concatenation</TITLE></HEAD><BODY>\n

getProlog

public java.lang.String getProlog()
Get the prolog.

Returns:
string of HTML that is emitted at the beginning of the concatenation.

setPageHeader

public void setPageHeader(java.lang.String header)
Set the header. The header can contain macro codes which are replaced with attributes of the page about to be written:
%t
title of the page
%u
URL of page
%a
anchor name of the page ("pageN", where N is the page number)
%p
page number (starting from 1)

Parameters:
header - string of HTML that is emitted before each page. The default value is:
<TABLE WIDTH="100%"><TR>\n
<TD ALIGN=left><A NAME="%a">%t [%u]</A>\n
<TD ALIGN=right>Page %p</TABLE>\n

getPageHeader

public java.lang.String getPageHeader()
Get the header.

Returns:
string of HTML that is emitted before each page.

setPageFooter

public void setPageFooter(java.lang.String footer)
Set the footer. The footer can contain the same macros as the header (%t, %u, %a, %p); see setPageHeader for more details.

Parameters:
footer - string of HTML that is emitted after each page.

getPageFooter

public java.lang.String getPageFooter()
Get the footer.

Returns:
string of HTML that is emitted after each page.

setDivider

public void setDivider(java.lang.String divider)
Set the divider.

Parameters:
divider - string of HTML that is emitted between each pair of pages.

getDivider

public java.lang.String getDivider()
Get the divider.

Returns:
string of HTML that is emitted between each pair of pages.

setEpilog

public void setEpilog(java.lang.String epilog)
Set the epilog.

Parameters:
epilog - string of HTML that is emitted after the entire concatenation.

getEpilog

public java.lang.String getEpilog()
Get the epilog.

Returns:
string of HTML that is emitted after the entire concatenation.

getPageCount

public int getPageCount()
Get number of pages written to this mirror.

Returns:
number of calls to writePage() on this mirror

rewrite

public void rewrite()
             throws java.io.IOException
Rewrite the concatenation. Makes sure all the links among concatenated pages have been fixed up.

Overrides:
rewrite in class RewritableLinkTransformer

close

public void close()
           throws java.io.IOException
Close the concatenation. Makes sure all the links among concatenated pages have been fixed up and closes the file.

Overrides:
close in class RewritableLinkTransformer

writePage

public void writePage(Page page)
               throws java.io.IOException
Write a page to the concatenation.

Overrides:
writePage in class LinkTransformer
Parameters:
page - Page to write

handleElement

protected void handleElement(Element elem)
                      throws java.io.IOException
Process an HTML element for concatenation. Deletes tags that would conflict with other pages (such as <HEAD>), changes the URLs in Link elements, and deletes or remaps the BASE element.

Overrides:
handleElement in class LinkTransformer
Parameters:
elem - HTML element to process

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception