+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2007 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// Template.java\r
-// Since: Jul 25, 2007 4:11:06 PM\r
-//\r
-// $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/util/template/Template.java $\r
-// $Author: leo $\r
-//--------------------------------------\r
-package org.xerial.util.template;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.io.PrintWriter;\r
-import java.io.StringWriter;\r
-import java.util.Properties;\r
-\r
-import org.antlr.stringtemplate.StringTemplate;\r
-\r
-/**\r
- * Searches a <pre>$propertyKey$</pre> in a template, replaces it with the corresponding property value. \r
- * \r
- * @author leo\r
- *\r
- */\r
-public class Template\r
-{\r
- private StringTemplate template;\r
- \r
- public Template(String templateString)\r
- {\r
- template = new StringTemplate(templateString);\r
- }\r
- public Template(InputStream templateStream) throws IOException\r
- {\r
- BufferedReader reader = new BufferedReader(new InputStreamReader(templateStream));\r
- StringWriter buf = new StringWriter();\r
- PrintWriter writer = new PrintWriter(buf);\r
- \r
- String line;\r
- while((line = reader.readLine()) != null)\r
- {\r
- writer.println(line);\r
- }\r
- \r
- template = new StringTemplate(buf.toString());\r
- }\r
- \r
- public String apply(Properties property)\r
- {\r
- for(Object keyObj : property.keySet()) {\r
- String key = keyObj.toString();\r
- template.setAttribute(key, property.get(keyObj));\r
- }\r
- return template.toString();\r
- }\r
-\r
-}\r