1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.strategy.cache;
|
5
|
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.HashSet;
|
8
|
import java.util.List;
|
9
|
import java.util.Set;
|
10
|
import java.util.SortedSet;
|
11
|
import java.util.TreeSet;
|
12
|
|
13
|
/**
|
14
|
* Rules to define tagging for HTML tagged string output.
|
15
|
*
|
16
|
* @author a.mueller
|
17
|
* @created 14/02/2012
|
18
|
*
|
19
|
*/
|
20
|
public class HTMLTagRules {
|
21
|
|
22
|
private List<TagRule> rules = new ArrayList<HTMLTagRules.TagRule>();
|
23
|
|
24
|
private class TagRule{
|
25
|
private TagRule(TagEnum type, String htmlTag){this.type = type; this.htmlTag = htmlTag;}
|
26
|
private TagEnum type;
|
27
|
private String htmlTag;
|
28
|
// public TagEnum getType(){return this.type;}
|
29
|
// public String getString(){return this.htmlTag;}
|
30
|
@Override public String toString(){return type.name() + "-><" + htmlTag + ">";}
|
31
|
}
|
32
|
|
33
|
|
34
|
public HTMLTagRules addRule(TagEnum type, String htmlTag){
|
35
|
if (type == null || htmlTag == null){
|
36
|
throw new NullPointerException("Null tpye or htmlTag not allowed for HTMLTagRule");
|
37
|
}
|
38
|
rules.add(new TagRule(type, htmlTag));
|
39
|
return this;
|
40
|
}
|
41
|
|
42
|
public SortedSet<String> getRule(TagEnum type){
|
43
|
SortedSet<String> result = new TreeSet<String>();
|
44
|
for (TagRule rule : rules){
|
45
|
if (rule.type.equals(type)){
|
46
|
result.add(rule.htmlTag);
|
47
|
}
|
48
|
}
|
49
|
return result;
|
50
|
}
|
51
|
|
52
|
public boolean hasRule(TagEnum type, String htmlTag){
|
53
|
for (TagRule rule : rules){
|
54
|
if (rule.type.equals(type) && htmlTag.equals(htmlTag)){
|
55
|
return true;
|
56
|
}
|
57
|
}
|
58
|
return false;
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public String toString(){
|
63
|
String result = "HTMLTagRules[";
|
64
|
for (TagRule rule : rules){
|
65
|
result += rule.toString() + ";";
|
66
|
}
|
67
|
result = result.substring(0, result.length() -1) + "]";
|
68
|
return result;
|
69
|
}
|
70
|
|
71
|
|
72
|
}
|