int count = template.getTokenCount();
for (int i = 0; i < count; i++)
{
TemplateToken token = template.getToken(i);
TokenType type = token.getType();
if (type == TokenType.TEXT)
{
write(writer, (TextToken) token);
continue;
}
if (type == TokenType.CLOSE)
{
write(writer, (CloseToken) token);
continue;
}
if (token.getType() == TokenType.LOCALIZATION)
{
write(writer, (LocalizationToken) token);
continue;
}
if (token.getType() == TokenType.OPEN)
{
boolean nextIsClose = (i + 1 < count)
&& (template.getToken(i + 1).getType() == TokenType.CLOSE);
write(writer, nextIsClose, (OpenToken) token);