//**************************************************************** //* Copyright (c) 2014 Ford Motor Company. All Rights Reserved. //**************************************************************** package com.ford.it.jsftest; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; import javax.annotation.PostConstruct; /** * Builds a phrase for the Greeting Bean to display */ public class PhraseBuilder { private Map templates; /** * Builds a new template entry keyed by id * * @param id the key into the template map * @param phrase the String representing the phrase to add */ public void addNewTemplateEntry(final String id, final String phrase) { if (this.templates == null) { this.templates = new HashMap(); } this.templates.put(id, phrase); } /** * Returns a phase from the phrase list * * @param id the key into the phrase list * @param args the replacement arguments * @return the formatted phrase */ public String buildPhrase(final String id, final Object... args) { return MessageFormat.format(this.templates.get(id), args); } /** * Post constructor for the PhraseBuilder that builds a simple "hello" template and * adds that template to the PhraseBuilder template map */ @PostConstruct public void initialize() { System.out.println("PostConstuct of PhraseBuilder called"); this.templates = new HashMap(); this.templates.put("hello", "Hello, {0}!"); } }