chris@0: /* chris@0: * StarOffice News Server chris@0: * see AUTHORS for the list of contributors chris@0: * chris@0: * This program is free software: you can redistribute it and/or modify chris@0: * it under the terms of the GNU General Public License as published by chris@0: * the Free Software Foundation, either version 3 of the License, or chris@0: * (at your option) any later version. chris@0: * chris@0: * This program is distributed in the hope that it will be useful, chris@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@0: * GNU General Public License for more details. chris@0: * chris@0: * You should have received a copy of the GNU General Public License chris@0: * along with this program. If not, see . chris@0: */ chris@0: chris@0: package com.so.news.util; chris@0: chris@0: import java.util.HashMap; chris@0: chris@0: /** chris@0: * Class that allows simple String template handling. chris@0: * @author Christian Lins (christian.lins@web.de) chris@0: */ chris@0: public class StringTemplate chris@0: { chris@0: private String str = null; chris@0: private String templateDelimiter = "%"; chris@0: private HashMap templateValues = new HashMap(); chris@0: chris@0: public StringTemplate(String str, String templateDelimiter) chris@0: { chris@0: this.str = str; chris@0: this.templateDelimiter = templateDelimiter; chris@0: } chris@0: chris@0: public StringTemplate(String str) chris@0: { chris@0: this(str, "%"); chris@0: } chris@0: chris@0: public void set(String template, String value) chris@0: { chris@0: this.templateValues.put(template, value); chris@0: } chris@0: chris@0: public void set(String template, long value) chris@0: { chris@0: set(template, Long.toString(value)); chris@0: } chris@0: chris@0: public void set(String template, double value) chris@0: { chris@0: set(template, Double.toString(value)); chris@0: } chris@0: chris@0: public void set(String template, Object obj) chris@0: { chris@0: set(template, obj.toString()); chris@0: } chris@0: chris@0: @Override chris@0: public String toString() chris@0: { chris@0: String ret = new String(str); chris@0: chris@0: for(String key : this.templateValues.keySet()) chris@0: { chris@0: String value = this.templateValues.get(key); chris@0: ret = ret.replace(templateDelimiter + key, value); chris@0: } chris@0: chris@0: return ret; chris@0: } chris@0: }