KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > SimpleRuleSetNameMapper


1 package net.sourceforge.pmd;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.util.StringTokenizer JavaDoc;
6
7 public class SimpleRuleSetNameMapper {
8
9     private StringBuffer JavaDoc rulesets = new StringBuffer JavaDoc();
10     private Map JavaDoc nameMap = new HashMap JavaDoc();
11
12     public SimpleRuleSetNameMapper(String JavaDoc ruleString) {
13         populateNameMap();
14         if (ruleString.indexOf(',') == -1) {
15             check(ruleString);
16             return;
17         }
18         for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(ruleString, ","); st.hasMoreTokens();) {
19             String JavaDoc tok = st.nextToken();
20             check(tok);
21         }
22     }
23
24     public String JavaDoc getRuleSets() {
25         return rulesets.toString();
26     }
27
28     private void check(String JavaDoc name) {
29         if (name.indexOf("rulesets") == -1 && nameMap.containsKey(name)) {
30             append((String JavaDoc) nameMap.get(name));
31         } else {
32             append(name);
33         }
34     }
35
36     private void append(String JavaDoc name) {
37         if (rulesets.length() > 0) {
38             rulesets.append(',');
39         }
40         rulesets.append(name);
41     }
42
43     private void populateNameMap() {
44         nameMap.put("basic", "rulesets/basic.xml");
45         nameMap.put("jsp", "rulesets/basic-jsp.xml");
46         nameMap.put("jsf", "rulesets/basic-jsf.xml");
47         nameMap.put("braces", "rulesets/braces.xml");
48         nameMap.put("clone", "rulesets/clone.xml");
49         nameMap.put("codesize", "rulesets/codesize.xml");
50         nameMap.put("controversial", "rulesets/controversial.xml");
51         nameMap.put("coupling", "rulesets/coupling.xml");
52         nameMap.put("design", "rulesets/design.xml");
53         nameMap.put("finalizers", "rulesets/finalizers.xml");
54         nameMap.put("imports", "rulesets/imports.xml");
55         nameMap.put("j2ee", "rulesets/j2ee.xml");
56         nameMap.put("junit", "rulesets/junit.xml");
57         nameMap.put("javabeans", "rulesets/javabeans.xml");
58         nameMap.put("logging-java", "rulesets/logging-java.xml");
59         nameMap.put("logging-jakarta", "rulesets/logging-jakarta-commons.xml");
60         nameMap.put("logging-jakarta-commons", "rulesets/logging-jakarta-commons.xml");
61         nameMap.put("migrating", "rulesets/migrating.xml");
62         nameMap.put("naming", "rulesets/naming.xml");
63         nameMap.put("optimizations", "rulesets/optimizations.xml");
64         nameMap.put("scratchpad", "rulesets/scratchpad.xml");
65         nameMap.put("strictexception", "rulesets/strictexception.xml");
66         nameMap.put("strings", "rulesets/strings.xml");
67         nameMap.put("sunsecure", "rulesets/sunsecure.xml");
68         nameMap.put("typeresolution", "rulesets/typeresolution.xml");
69         nameMap.put("unusedcode", "rulesets/unusedcode.xml");
70         nameMap.put("33", "rulesets/releases/33.xml");
71         nameMap.put("34", "rulesets/releases/34.xml");
72         nameMap.put("35", "rulesets/releases/35.xml");
73         nameMap.put("36", "rulesets/releases/36.xml");
74         nameMap.put("37", "rulesets/releases/37.xml");
75         nameMap.put("38", "rulesets/releases/38.xml");
76         nameMap.put("39", "rulesets/releases/39.xml");
77     }
78 }
79
Popular Tags