mixer
Class Mixer

java.lang.Object
  extended bymixer.Mixer

public class Mixer
extends java.lang.Object

Title: Mixer

Description: Mixer is a simple helper-class (that is easy to use) for Servlet programmers that enable a complete separation of Servlet- and HTML-code.

Copyright: GNU GPL, http://www.gnu.org/licenses/licenses.html#TOCGPL


Constructor Summary
Mixer(java.lang.String html)
          Constructor for the Mixer object.
 
Method Summary
 void add(java.lang.String marker, java.lang.String value)
          Adds a marker that should be substituted by a value.
 void add(java.lang.String context, java.lang.String marker, java.lang.String value)
          Adds a marker that should be substituted by a value.
 void addHTML(java.lang.String htmlPart, java.lang.String context)
          Adds HTML-code to a context.
 void clear()
          Clears all entries associated with no specific context of the HTML-document.
 void clearAll()
          Clears all enries associated with no and all HTML-document contexts Example: mixer.clearAll();
 void clearContext(java.lang.String context)
          Clears all entries associated with a specific context of the HTML-document.
static java.lang.String getContent(java.io.File file)
          Loads a HTML-file and returns the content as a string.
static java.lang.String getContent(java.io.File file, java.lang.String context)
          Loads a HTML-file and returns a specific context of this HTML-file as a string.
 java.lang.String getMix()
          Mixes the template HTML-document with the added marker-value pairs and returns the result.
 void remove(java.lang.String marker, java.lang.String value)
          Removes a marker-value pair associated with no specific context of the HTML-document.
 void remove(java.lang.String context, java.lang.String marker, java.lang.String value)
          Removes a marker-value pair associated with a specific context of the HTML-document.
 void removeContext(java.lang.String context)
          Removes all HTML-code from a context including the context markers.
 void removeHTML(java.lang.String context)
          Removes all HTML-code from a context excluding the context markers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mixer

public Mixer(java.lang.String html)

Constructor for the Mixer object.

Example: Mixer mixer = new Mixer(html);

Parameters:
html - The string containing the template HTML-file.
Method Detail

add

public void add(java.lang.String marker,
                java.lang.String value)

Adds a marker that should be substituted by a value. Context of replacement in the HTML-document: no specific.

Example: mixer.add("---email---", "pierre@dsv.su.se");

Parameters:
marker - The marker string that will be replaced by the value string in the HTML-document.
value - The value string that will replace the marker string in the HTML-document.

add

public void add(java.lang.String context,
                java.lang.String marker,
                java.lang.String value)

Adds a marker that should be substituted by a value. Context of replacement in the HTML-document: specific. This context can be used repeatedly and is marked in the HTML-document by two identical markers.

Example: mixer.add("---context---", "---email---", "pierre@dsv.su.se");

Parameters:
context - The context string that marks a specific area in the HTML-document.
marker - The marker string that will be replaced by the value string in the HTML-document.
value - The value string that will replace the marker string in the HTML-document.

remove

public void remove(java.lang.String marker,
                   java.lang.String value)

Removes a marker-value pair associated with no specific context of the HTML-document.

Example: mixer.remove("---email---", "pierre@dsv.su.se");

Parameters:
marker - The marker string (associated with the value string parameter) that will be removed.
value - The value string (associated with the marker string parameter) that will be removed.

remove

public void remove(java.lang.String context,
                   java.lang.String marker,
                   java.lang.String value)

Removes a marker-value pair associated with a specific context of the HTML-document.

Example: mixer.remove("---context---", "---email---", "pierre@dsv.su.se");

Parameters:
context - The context string that marks a specific area in the HTML-document.
marker - The marker string (accociated with the value string parameter) that will be removed.
value - The value string (accociated with the marker string parameter) that will be removed.

clear

public void clear()

Clears all entries associated with no specific context of the HTML-document.

Example: mixer.clear();


clearContext

public void clearContext(java.lang.String context)

Clears all entries associated with a specific context of the HTML-document.

Example: mixer.clear("---context---");

Parameters:
context - The context that will be cleared.

clearAll

public void clearAll()

Clears all enries associated with no and all HTML-document contexts

Example: mixer.clearAll();


removeContext

public void removeContext(java.lang.String context)

Removes all HTML-code from a context including the context markers.

Example: mixer.removeContext("---context---");

Parameters:
context - The HTML-document context that will be removed.

addHTML

public void addHTML(java.lang.String htmlPart,
                    java.lang.String context)

Adds HTML-code to a context.

Example: mixer.addHTML(htmlPart, "---context---");

Note! Experimental.

Parameters:
htmlPart - The string that contains the subpart HTML-code that will be included.
context - The HTML-document context where the subpart HTML-code will be inserted.

removeHTML

public void removeHTML(java.lang.String context)

Removes all HTML-code from a context excluding the context markers.

Example: mixer.removeHTML("---context---");

Note! Experimental.

Parameters:
context - The HTML-document context where the subpart HTML-code will be removed.

getMix

public java.lang.String getMix()

Mixes the template HTML-document with the added marker-value pairs and returns the result.

Example: String html = mixer.getMix();

Returns:
A string with the result of mixing the values from the Java- and the HTML-code.

getContent

public static java.lang.String getContent(java.io.File file)

Loads a HTML-file and returns the content as a string.

Example: String html = Mixer.getContent(new File("x.html"));

Example: String html = Mixer.getContent(new File(getServletContext().getRealPath("x.html")));

Parameters:
file - The template HTML-file to load.
Returns:
A string containing the loaded HTML-code.

getContent

public static java.lang.String getContent(java.io.File file,
                                          java.lang.String context)

Loads a HTML-file and returns a specific context of this HTML-file as a string.

Example: String html = Mixer.getContent(new File("x.html"), "---context---");

Example: String html = Mixer.getContent(new File(getServletContext().getRealPath("x.html")), "---context---");

Parameters:
file - The template HTML-file to load.
context - The context string that marks a specific area in the HTML-document.
Returns:
A string containing the specific context of the loaded HTML-code.