Class HtmlPageAttributes
- java.lang.Object
-
- org.apache.turbine.util.template.HtmlPageAttributes
-
- All Implemented Interfaces:
ApplicationTool
public class HtmlPageAttributes extends Object implements 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$
- Author:
- Quinton McCombs, Scott Eade
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HtmlPageAttributes.LinkTag
Helper class to hold data about a <link
-
Constructor Summary
Constructors Constructor Description HtmlPageAttributes()
Construct a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlPageAttributes
addBodyAttribute(String name, String value)
Adds an attribute to the BODY tag.HtmlPageAttributes
addLink(String relation, String linkURL)
Adds a generic external referenceHtmlPageAttributes
addLink(String relation, String linkURL, String title)
Adds a generic external referenceHtmlPageAttributes
addLink(String relation, String linkURL, String title, String type)
Adds a generic external referenceHtmlPageAttributes
addScript(String scriptURL)
Adds a script referenceHtmlPageAttributes
addStyle(String styleText)
Adds a STYLE element to the HEAD of the page with the provided content.HtmlPageAttributes
addStyleSheet(String styleSheetURL)
Adds a style sheet referenceHtmlPageAttributes
addStyleSheet(String styleSheetURL, String media, String title, String type)
Adds a style sheet referenceMap<String,String>
getBodyAttributes()
Returns the map of body attributesString
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).String
getDoctype(String tag, String identifier, String uri)
Build the doctype element.Map<String,String>
getHttpEquivs()
Gets the map of http equiv tagsList<HtmlPageAttributes.LinkTag>
getLinks()
Returns a collection of link URLsMap<String,String>
getMetaTags()
Gets the map of meta tagsList<String>
getScripts()
Returns a collection of script URLsList<String>
getStyles()
Returns a collection of stylesString
getTitle()
Get the title in the page.void
init(Object data)
Initialize this instance.void
refresh()
Refresh method - does nothingHtmlPageAttributes
setAlinkColor(String color)
Set the active link color for the BODY tag.HtmlPageAttributes
setBackground(String url)
Set the background image for the BODY tag.HtmlPageAttributes
setBgColor(String color)
Set the background color for the BODY tag.HtmlPageAttributes
setDescription(String description)
Add a description META tag to the HEAD of the page.HtmlPageAttributes
setHttpEquiv(String httpEquiv, 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(String keywords)
Set a keywords META tag in the HEAD of the page.HtmlPageAttributes
setLinkColor(String color)
Set the link color for the BODY tag.HtmlPageAttributes
setTextColor(String color)
Set the text color for the BODY tag.HtmlPageAttributes
setTitle(String title)
Set the title in the page.HtmlPageAttributes
setVlinkColor(String color)
Set the visited link color for the BODY tag.String
toString()
A dummy toString method that returns an empty string.
-
-
-
Constructor Detail
-
HtmlPageAttributes
public HtmlPageAttributes()
Construct a new instance
-
-
Method Detail
-
init
public void init(Object data)
Initialize this instance. (ApplicationTool method)- Specified by:
init
in interfaceApplicationTool
- Parameters:
data
- not used
-
refresh
public void refresh()
Refresh method - does nothing- Specified by:
refresh
in interfaceApplicationTool
-
setTitle
public HtmlPageAttributes setTitle(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.- Parameters:
title
- A String with the title.- Returns:
- a
HtmlPageAttributes
(self).
-
getTitle
public 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.- Returns:
- A String with the title.
-
addBodyAttribute
public HtmlPageAttributes addBodyAttribute(String name, String value)
Adds an attribute to the BODY tag.- Parameters:
name
- A String.value
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
getBodyAttributes
public Map<String,String> getBodyAttributes()
Returns the map of body attributes- Returns:
- the map
-
addScript
public HtmlPageAttributes addScript(String scriptURL)
Adds a script reference- Parameters:
scriptURL
- the url- Returns:
- a
HtmlPageAttributes
(self).
-
getScripts
public List<String> getScripts()
Returns a collection of script URLs- Returns:
- list of String objects containing URLs of javascript files to include
-
addStyleSheet
public HtmlPageAttributes addStyleSheet(String styleSheetURL)
Adds a style sheet reference- Parameters:
styleSheetURL
- URL of the style sheet- Returns:
- a
HtmlPageAttributes
(self).
-
addStyleSheet
public HtmlPageAttributes addStyleSheet(String styleSheetURL, String media, String title, String type)
Adds a style sheet reference- Parameters:
styleSheetURL
- URL of the style sheetmedia
- name of the mediatitle
- title of the stylesheettype
- content type- Returns:
- a
HtmlPageAttributes
(self).
-
addLink
public HtmlPageAttributes addLink(String relation, String linkURL)
Adds a generic external reference- Parameters:
relation
- type of the reference (prev, next, first, last, top, etc.)linkURL
- URL of the reference- Returns:
- a
HtmlPageAttributes
(self).
-
addLink
public HtmlPageAttributes addLink(String relation, String linkURL, String title)
Adds a generic external reference- Parameters:
relation
- type of the reference (prev, next, first, last, top, etc.)linkURL
- URL of the referencetitle
- title of the reference- Returns:
- a
HtmlPageAttributes
(self).
-
addLink
public HtmlPageAttributes addLink(String relation, String linkURL, String title, String type)
Adds a generic external reference- Parameters:
relation
- type of the reference (prev, next, first, last, top, etc.)linkURL
- URL of the referencetitle
- title of the referencetype
- content type- Returns:
- a
HtmlPageAttributes
(self).
-
getLinks
public List<HtmlPageAttributes.LinkTag> getLinks()
Returns a collection of link URLs- Returns:
- list LinkTag objects (inner class)
-
addStyle
public HtmlPageAttributes addStyle(String styleText)
Adds a STYLE element to the HEAD of the page with the provided content.- Parameters:
styleText
- The contents of thestyle
tag.- Returns:
- a
HtmlPageAttributes
(self).
-
getStyles
public List<String> getStyles()
Returns a collection of styles- Returns:
- list of String objects containing the contents of style tags
-
setKeywords
public HtmlPageAttributes setKeywords(String keywords)
Set a keywords META tag in the HEAD of the page.- Parameters:
keywords
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setHttpEquiv
public HtmlPageAttributes setHttpEquiv(String httpEquiv, 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")
- Parameters:
httpEquiv
- The value to use for the http-equiv attribute.content
- The text for the content attribute of the meta tag.- Returns:
- a
HtmlPageAttributes
(self).
-
setDescription
public HtmlPageAttributes setDescription(String description)
Add a description META tag to the HEAD of the page.- Parameters:
description
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setBackground
public HtmlPageAttributes setBackground(String url)
Set the background image for the BODY tag.- Parameters:
url
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setBgColor
public HtmlPageAttributes setBgColor(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").- Parameters:
color
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setTextColor
public HtmlPageAttributes setTextColor(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").- Parameters:
color
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setLinkColor
public HtmlPageAttributes setLinkColor(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").- Parameters:
color
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setVlinkColor
public HtmlPageAttributes setVlinkColor(String color)
Set the visited link color for the BODY tag.- Parameters:
color
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
setAlinkColor
public HtmlPageAttributes setAlinkColor(String color)
Set the active link color for the BODY tag.- Parameters:
color
- A String.- Returns:
- a
HtmlPageAttributes
(self).
-
getHttpEquivs
public Map<String,String> getHttpEquivs()
Gets the map of http equiv tags- Returns:
- Map of http equiv names to the contents
-
getMetaTags
public Map<String,String> getMetaTags()
Gets the map of meta tags- Returns:
- Map of http equiv names to the contents
-
getDefaultDoctype
public 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).- Returns:
- the DOCTYPE tag constructed from the properties in TurbineResources.properties.
-
getDoctype
public String getDoctype(String tag, String identifier, String uri)
Build the doctype element.- Parameters:
tag
- the tag whose DTD is being declared.identifier
- the identifier for the doctype declaration.uri
- the uri for the doctype declaration.- Returns:
- the doctype.
-
-