1 package org.rpi.plugin.lcddisplay;
2
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
5
6 import org.apache.log4j.Logger;
7
8 public class KeyDefinition {
9 private String name="";
10 private String key = "";
11 private String format = "";
12 private boolean bFormatted =false;
13
14 private Logger log = Logger.getLogger(KeyDefinition.class);
15
16
17 public String getName() {
18 return name;
19 }
20 public void setName(String name) {
21 this.name = name;
22 String sKey = name;
23 if (name.contains("{")) {
24 String sFormat = getFormat(name);
25 sKey = sKey.replace(sFormat, "");
26 sKey = sKey.trim();
27 if(sFormat.startsWith("{"))
28 sFormat = sFormat.substring(1);
29 if(sFormat.endsWith("}"))
30 sFormat = sFormat.substring(0, sFormat.length()-1);
31 log.debug("Setting Format: " + name + " : " + sFormat);
32 setFormat(sFormat);
33 }
34 setKey(sKey);
35 }
36 public String getKey() {
37 return key;
38 }
39 public void setKey(String key) {
40 this.key = key;
41 }
42 public String getFormat() {
43 return format;
44 }
45 public void setFormat(String format) {
46 this.format = format;
47 }
48 public boolean isFormatted() {
49 return bFormatted;
50 }
51 public void setFormatted(boolean bFormatted) {
52 this.bFormatted = bFormatted;
53 }
54
55
56
57
58
59
60 private String getFormat(String text) {
61 String res = "";
62 String p = "\\{([^]]+)\\}";
63 Pattern pattern = Pattern.compile(p);
64 Matcher matcher = pattern.matcher(text);
65 while (matcher.find()) {
66 res = matcher.group();
67 bFormatted = true;
68 return res;
69 }
70 return res;
71 }
72
73 }