Framework Professional Edition Package


com.prosyst.util.template
Class HTMLTemplateFileImpl

java.lang.Object
  extended by com.prosyst.util.template.HTMLTemplateFileImpl
All Implemented Interfaces:
HTMLTemplate

public class HTMLTemplateFileImpl
extends java.lang.Object
implements HTMLTemplate

A class, representing a layer of abstraction for a HTML Template file The HTML template file is a text file containing HTML text with labels in the place(s) where runtime info will be inserted. A label has the following format - $LABEL_NAME$. The LABEL_NAME can be any String. Two labels can have the same name. This class is used in the following way: First, an HTMLTemplate object is created from the template file. This object contains the parsed image of the template. Then every time the page is to be sent to a user, a new TemplateWriter object is got from the HTMLTemplate object with the writer from the current response. The writeToNextLabel() method of this TemplateWriter is called repeatedly to write all the staic HTML content, while between the calls the servlet generates only the corresponding runtime info.

Author:
Sofia Doncheva

Constructor Summary
HTMLTemplateFileImpl(java.net.URL url, java.lang.String[][] initLabels, org.osgi.framework.BundleContext bc)
          This method prepares a template for use.
 
Method Summary
 void close()
          Cleans up any internal data, connections, etc.
 void close(boolean closeFs)
           
 java.lang.String getElementAt(int position)
          Returns the element in the given position in the template.
 int getLength()
          Returns the number of pieces the template was separated into (the number of constant HTML pieces + the number of labels)
 TemplateWriter getTemplateWriter(java.io.PrintWriter writer)
          Creates a new TemplateWriter with initialized writer and internal pointer.
 void templateWriterFinished(TemplateWriter tw)
          Called to notify the template that the work with one of the writers was finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLTemplateFileImpl

public HTMLTemplateFileImpl(java.net.URL url,
                            java.lang.String[][] initLabels,
                            org.osgi.framework.BundleContext bc)
                     throws java.lang.Exception
This method prepares a template for use. It loads the template from the given input stream, replaces the initial labels with their given values and cuts the string to static HTML parts and labels for replacing. If a label is given for initial replacement and this label exists more than once in the template, all its occurrencies will be replaced with the given value.

Parameters:
url - An input stream to read the template from.
initLabels - A String[][] containing the labels to be replaced directly after loading the template. If null no labels will be replaced. The syntax is [[label1, value1], [label2, value2],... [labeln, valuen]]
Throws:
java.lang.Exception
Method Detail

getTemplateWriter

public TemplateWriter getTemplateWriter(java.io.PrintWriter writer)
Creates a new TemplateWriter with initialized writer and internal pointer.

Specified by:
getTemplateWriter in interface HTMLTemplate
Returns:
The created TemplateWriter.

templateWriterFinished

public void templateWriterFinished(TemplateWriter tw)
Description copied from interface: HTMLTemplate
Called to notify the template that the work with one of the writers was finished.

Specified by:
templateWriterFinished in interface HTMLTemplate

close

public void close()
Description copied from interface: HTMLTemplate
Cleans up any internal data, connections, etc.

Specified by:
close in interface HTMLTemplate

close

public void close(boolean closeFs)
           throws java.io.IOException
Throws:
java.io.IOException

getLength

public int getLength()
Returns the number of pieces the template was separated into (the number of constant HTML pieces + the number of labels)

Specified by:
getLength in interface HTMLTemplate
Returns:
the number of elements in the template.

getElementAt

public java.lang.String getElementAt(int position)
Returns the element in the given position in the template. (This can be either a piece of constant HTML code or a label).

Specified by:
getElementAt in interface HTMLTemplate
Parameters:
position - The position of the element.
Returns:
The element at the given position.

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved