Template

public class Template

A Template is a parser which tokenizes a given template into a list of template elements. There are two types of template elements:

  1. Text
  2. Template Tag

Hence, a template is composed of a mixture of text and template tags. A template tag is recognized by the following pattern in the content: <!--[\\s]*template-((.*?))[\\s]*-->

Author:Hugo Y. K. Lam

See also: TemplateElement

Constructors

Template

public Template(String s)

Creates a new instance of Template.

Parameters:
  • s – the template.

Methods

hasMoreElements

public boolean hasMoreElements()

Checks if there are anymore elements in this template. This method will always return false if this template is not yet parsed. More, each invocation of nextElement() may also affect the result of this method.

Returns:true if there are more elements in this template.

See also: .nextElement()

nextElement

public TemplateElement nextElement()

Gets the next template element. This method will always return null if this template is not yet parsed.

Returns:the next template element.

parse

public void parse()

Parses the template content and initializes this template.

toString

public String toString()

Returns a string representation of this template. This method simply returns the original template content.

Returns:a string representation of this template.

See also: java.lang.Object.toString()