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