Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.turbine.util.template
Class HtmlPageAttributes  view HtmlPageAttributes download HtmlPageAttributes.java

java.lang.Object
  extended byorg.apache.turbine.util.template.HtmlPageAttributes
All Implemented Interfaces:
org.apache.turbine.services.pull.ApplicationTool

public class HtmlPageAttributes
extends java.lang.Object
implements org.apache.turbine.services.pull.ApplicationTool

Template context tool that can be used to set various attributes of a HTML page. This tool does not automatically make the changes in the HTML page for you. You must use this tool in your layout template to retrieve the attributes.

The set/add methods are can be used from a screen template, action, screen class, layour template, or anywhere else. The get methods should be used in your layout template(s) to construct the appropriate HTML tags.

Example usage of this tool to build the HEAD and BODY tags in your layout templates:

## Set defaults for all pages using this layout. Anything set here can
## be overridden in the screen template.
$page.setTitle("My default page title");
$page.setHttpEquiv("Content-Style-Type","text/css")
$page.addStyleSheet($content.getURI("myStyleSheet.css"))
$page.addScript($content.getURI("globalJavascriptCode.js"))

## build the HTML, HEAD, and BODY tags dynamically
<html>
<head>
#if( $page.Title != "" )
<title>$page.Title</title>
#end
#foreach($metaTag in $page.MetaTags.keySet())
<meta name="$metaTag" content="$page.MetaTags.get($metaTag)">
#end
#foreach($httpEquiv in $page.HttpEquivs.keySet())
<meta http-equiv="$httpEquiv" content="$page.HttpEquivs.get($httpEquiv)">
#end
#foreach( $styleSheet in $page.StyleSheets )
<link rel="stylesheet" href="$styleSheet.Url"
#if($styleSheet.Type != "" ) type="$styleSheet.Type" #end
#if($styleSheet.Media != "") media="$styleSheet.Media" #end
#if($styleSheet.Title != "") title="$styleSheet.Title" #end
>
#end
#foreach( $script in $page.Scripts )
<script type="text/javascript" src="$script" language="JavaScript"></script>
#end
</head>

## Construct the body tag. Iterate through the body attributes to build the opening tag
<body
#foreach( $attributeName in $page.BodyAttributes.keySet() )
$attributeName = "$page.BodyAttributes.get($attributeName)"
#end
>

Example usages of this tool in your screen templates:
$page.addScript($content.getURI("myJavascript.js")
$page.setTitle("My page title")
$page.setHttpEquiv("refresh","5; URL=http://localhost/nextpage.html")

Version:
$Id: HtmlPageAttributes.java 264148 2005-08-29 14:21:04Z henning $

Nested Class Summary
 class HtmlPageAttributes.StyleSheet
          Helper class to hold data about a stylesheet
 
Field Summary
private  java.util.Map bodyAttributes
          Body Attributes
private  java.lang.String doctype
          Doctype
private  java.util.Map httpEquivs
          http-equiv tags
private static org.apache.commons.logging.Log log
          Logging
private  java.util.Map metaTags
          Meta tags for the HEAD
private  java.util.List scripts
          Script references
private  java.util.List styles
          Inline styles
private  java.util.List styleSheets
          Stylesheet references
private  java.lang.String title
          The title
 
Constructor Summary
HtmlPageAttributes()
          Default constructor.
HtmlPageAttributes(org.apache.turbine.util.RunData data)
          Construct a new instance with the given RunData object.
 
Method Summary
 HtmlPageAttributes addAttribute(java.lang.String name, java.lang.String value)
          Deprecated. Use addBodyAttribute instead.
 HtmlPageAttributes addBodyAttribute(java.lang.String name, java.lang.String value)
          Adds an attribute to the BODY tag.
 HtmlPageAttributes addScript(java.lang.String scriptURL)
          Adds a script reference
 HtmlPageAttributes addStyle(java.lang.String styleText)
          Adds a STYLE element to the HEAD of the page with the provided content.
 HtmlPageAttributes addStyleSheet(java.lang.String styleSheetURL)
          Adds a style sheet reference
 HtmlPageAttributes addStyleSheet(java.lang.String styleSheetURL, java.lang.String media, java.lang.String title, java.lang.String type)
          Adds a style sheet reference
private  java.lang.String buildDoctype(java.lang.String tag, java.lang.String identifier, java.lang.String uri)
          Build the doctype element.
 java.util.Map getBodyAttributes()
          Returns the map of body attributes
 java.lang.String getDefaultDoctype()
          Retrieve the default Doctype as configured by the TurbineResources.peoperties default.doctype.root.element, default.doctype.identifier and default.doctype.url properties (defaults are "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN" and "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd" respectively).
 java.util.Map getHttpEquivs()
          Gets the map of http equiv tags
 java.util.Map getMetaTags()
          Gets the map of meta tags
 java.util.List getScripts()
          Returns a collection of script URLs
 java.util.List getStyles()
          Returns a collection of styles
 java.util.List getStyleSheets()
          Returns a collection of script URLs
 java.lang.String getTitle()
          Get the title in the page.
 void init(java.lang.Object data)
          Initialise this instance with the given RunData object.
 void refresh()
          Refresh method - does nothing
 HtmlPageAttributes setAlinkColor(java.lang.String color)
          Set the active link color for the BODY tag.
 HtmlPageAttributes setBackground(java.lang.String url)
          Set the background image for the BODY tag.
 HtmlPageAttributes setBgColor(java.lang.String color)
          Set the background color for the BODY tag.
 HtmlPageAttributes setDescription(java.lang.String description)
          Add a description META tag to the HEAD of the page.
 HtmlPageAttributes setHttpEquiv(java.lang.String httpEquiv, java.lang.String content)
          Sets a HttpEquiv META tag in the HEAD of the page, usage:
setHttpEquiv("refresh", "5; URL=http://localhost/nextpage.html")
setHttpEquiv("Expires", "Tue, 20 Aug 1996 14:25:27 GMT")
 HtmlPageAttributes setKeywords(java.lang.String keywords)
          Set a keywords META tag in the HEAD of the page.
 HtmlPageAttributes setLinkColor(java.lang.String color)
          Set the link color for the BODY tag.
 HtmlPageAttributes setScript(java.lang.String scriptURL)
          Deprecated. Use addScript instead
 HtmlPageAttributes setStyle(java.lang.String styleText)
          Deprecated. use addStyle instead
 HtmlPageAttributes setStyleSheet(java.lang.String styleSheetURL)
          Deprecated. use addStyleSheet instead
 HtmlPageAttributes setStyleSheet(java.lang.String styleSheetURL, java.lang.String media)
          Deprecated. use addStyleSheet instead
 HtmlPageAttributes setTextColor(java.lang.String color)
          Set the text color for the BODY tag.
 HtmlPageAttributes setTitle(java.lang.String title)
          Set the title in the page.
 HtmlPageAttributes setVlinkColor(java.lang.String color)
          Set the visited link color for the BODY tag.
 java.lang.String toString()
          A dummy toString method that returns an empty string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Logging


title

private java.lang.String title
The title


bodyAttributes

private java.util.Map bodyAttributes
Body Attributes


scripts

private java.util.List scripts
Script references


styleSheets

private java.util.List styleSheets
Stylesheet references


styles

private java.util.List styles
Inline styles


metaTags

private java.util.Map metaTags
Meta tags for the HEAD


httpEquivs

private java.util.Map httpEquivs
http-equiv tags


doctype

private java.lang.String doctype
Doctype

Constructor Detail

HtmlPageAttributes

public HtmlPageAttributes()
Default constructor. The init method must be called before use


HtmlPageAttributes

public HtmlPageAttributes(org.apache.turbine.util.RunData data)
Construct a new instance with the given RunData object.

Method Detail

init

public void init(java.lang.Object data)
Initialise this instance with the given RunData object. (ApplicationTool method)

Specified by:
init in interface org.apache.turbine.services.pull.ApplicationTool

refresh

public void refresh()
Refresh method - does nothing

Specified by:
refresh in interface org.apache.turbine.services.pull.ApplicationTool

setTitle

public HtmlPageAttributes setTitle(java.lang.String title)
Set the title in the page. This returns an empty String so that the template doesn't complain about getting a null return value. Subsequent calls to this method will replace the current title.


getTitle

public java.lang.String getTitle()
Get the title in the page. This returns an empty String if empty so that the template doesn't complain about getting a null return value.


addAttribute

public HtmlPageAttributes addAttribute(java.lang.String name,
                                       java.lang.String value)
Deprecated. Use addBodyAttribute instead.

Adds an attribute to the BODY tag.


addBodyAttribute

public HtmlPageAttributes addBodyAttribute(java.lang.String name,
                                           java.lang.String value)
Adds an attribute to the BODY tag.


getBodyAttributes

public java.util.Map getBodyAttributes()
Returns the map of body attributes


addScript

public HtmlPageAttributes addScript(java.lang.String scriptURL)
Adds a script reference


setScript

public HtmlPageAttributes setScript(java.lang.String scriptURL)
Deprecated. Use addScript instead

Adds a script reference


getScripts

public java.util.List getScripts()
Returns a collection of script URLs


addStyleSheet

public HtmlPageAttributes addStyleSheet(java.lang.String styleSheetURL)
Adds a style sheet reference


addStyleSheet

public HtmlPageAttributes addStyleSheet(java.lang.String styleSheetURL,
                                        java.lang.String media,
                                        java.lang.String title,
                                        java.lang.String type)
Adds a style sheet reference


setStyleSheet

public HtmlPageAttributes setStyleSheet(java.lang.String styleSheetURL)
Deprecated. use addStyleSheet instead

Adds a style sheet reference


setStyleSheet

public HtmlPageAttributes setStyleSheet(java.lang.String styleSheetURL,
                                        java.lang.String media)
Deprecated. use addStyleSheet instead

Adds a style sheet reference


getStyleSheets

public java.util.List getStyleSheets()
Returns a collection of script URLs


setStyle

public HtmlPageAttributes setStyle(java.lang.String styleText)
Deprecated. use addStyle instead

Adds a STYLE element to the HEAD of the page with the provided content.


addStyle

public HtmlPageAttributes addStyle(java.lang.String styleText)
Adds a STYLE element to the HEAD of the page with the provided content.


getStyles

public java.util.List getStyles()
Returns a collection of styles


setKeywords

public HtmlPageAttributes setKeywords(java.lang.String keywords)
Set a keywords META tag in the HEAD of the page.


setHttpEquiv

public HtmlPageAttributes setHttpEquiv(java.lang.String httpEquiv,
                                       java.lang.String content)
Sets a HttpEquiv META tag in the HEAD of the page, usage:
setHttpEquiv("refresh", "5; URL=http://localhost/nextpage.html")
setHttpEquiv("Expires", "Tue, 20 Aug 1996 14:25:27 GMT")


setDescription

public HtmlPageAttributes setDescription(java.lang.String description)
Add a description META tag to the HEAD of the page.


setBackground

public HtmlPageAttributes setBackground(java.lang.String url)
Set the background image for the BODY tag.


setBgColor

public HtmlPageAttributes setBgColor(java.lang.String color)
Set the background color for the BODY tag. You can use either color names or color values (e.g. "white" or "#ffffff" or "ffffff").


setTextColor

public HtmlPageAttributes setTextColor(java.lang.String color)
Set the text color for the BODY tag. You can use either color names or color values (e.g. "white" or "#ffffff" or "ffffff").


setLinkColor

public HtmlPageAttributes setLinkColor(java.lang.String color)
Set the link color for the BODY tag. You can use either color names or color values (e.g. "white" or "#ffffff" or "ffffff").


setVlinkColor

public HtmlPageAttributes setVlinkColor(java.lang.String color)
Set the visited link color for the BODY tag.


setAlinkColor

public HtmlPageAttributes setAlinkColor(java.lang.String color)
Set the active link color for the BODY tag.


getHttpEquivs

public java.util.Map getHttpEquivs()
Gets the map of http equiv tags


getMetaTags

public java.util.Map getMetaTags()
Gets the map of meta tags


toString

public java.lang.String toString()
A dummy toString method that returns an empty string.


getDefaultDoctype

public java.lang.String getDefaultDoctype()
Retrieve the default Doctype as configured by the TurbineResources.peoperties default.doctype.root.element, default.doctype.identifier and default.doctype.url properties (defaults are "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN" and "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd" respectively).


buildDoctype

private java.lang.String buildDoctype(java.lang.String tag,
                                      java.lang.String identifier,
                                      java.lang.String uri)
Build the doctype element.