• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão5a6a881cd8e38b18789cb5b0d9a4d7a87a88f0b5 (tree)
Hora2014-01-02 09:44:55
Autortakahiro <takahiro@192....>
Commitertakahiro

Mensagem de Log

TemplateEngine追加

Mudança Sumário

Diff

--- a/pom.xml
+++ b/pom.xml
@@ -38,5 +38,10 @@
3838 <artifactId>slf4j-api</artifactId>
3939 <version>1.6.4</version>
4040 </dependency>
41+ <dependency>
42+ <groupId>io.vertx</groupId>
43+ <artifactId>vertx-core</artifactId>
44+ <version>2.1M2</version>
45+ </dependency>
4146 </dependencies>
4247 </project>
--- /dev/null
+++ b/src/main/java/org/infodb/junk/TemplateEngine.java
@@ -0,0 +1,28 @@
1+package org.infodb.junk;
2+
3+import java.util.Map;
4+import java.util.regex.Matcher;
5+import java.util.regex.Pattern;
6+import org.vertx.java.core.buffer.Buffer;
7+
8+public class TemplateEngine {
9+ private final Pattern pattern;
10+
11+ public TemplateEngine() {
12+ pattern = Pattern.compile("\\{(\\w+)\\}");
13+ }
14+
15+ public Buffer execute(String source, Map<String, String> params) {
16+ Matcher matcher = pattern.matcher(source);
17+ Buffer buffer = new Buffer();
18+ int lastEnd = 0;
19+ while(matcher.find()) {
20+ buffer.appendString(source.substring(lastEnd, matcher.start()));
21+ lastEnd = matcher.end();
22+ buffer.appendString(params.get(matcher.group(1)));
23+ }
24+ buffer.appendString(source.substring(lastEnd));
25+ return buffer;
26+ }
27+
28+}