View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd;
5   
6   public class ExternalRuleID {
7   
8       private String filename;
9       private String ruleName;
10  
11      public ExternalRuleID(String id) {
12          int afterXML = id.indexOf(".xml") + 5;
13          if (afterXML >= id.length()) {
14              throw new RuntimeException("Unable to parse reference to external rule " + id + ".  These references need to be in the form <rulesetname>/<rulename>, i.e., <rule ref=\"rulesets/unusedcode.xml/UnusedPrivateField\"/>");
15          }
16          filename = id.substring(0, afterXML - 1);
17          ruleName = id.substring(afterXML);
18      }
19  
20      public String getFilename() {
21          return filename;
22      }
23  
24      public String getRuleName() {
25          return ruleName;
26      }
27  
28      public String toString() {
29          return filename + "/" + ruleName;
30      }
31  }