1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.configuration.builders;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.apache.rat.ConfigurationException;
23 import org.apache.rat.analysis.matchers.FullTextMatcher;
24 import org.apache.rat.analysis.matchers.SimpleTextMatcher;
25 import org.apache.rat.config.parameters.MatcherBuilder;
26
27
28
29
30 @MatcherBuilder(SimpleTextMatcher.class)
31 public class TextBuilder extends AbstractBuilder {
32
33 private static final int MAX_DISPLAY_LENGTH = 20;
34
35 private String text;
36
37
38
39
40
41
42 public TextBuilder setSimpleText(final String text) {
43 this.text = text.trim();
44 if (StringUtils.isBlank(text)) {
45 throw new ConfigurationException("'text' may not be empty");
46 }
47 return this;
48 }
49
50 @Override
51 public SimpleTextMatcher build() {
52 if (StringUtils.isBlank(text)) {
53 throw new ConfigurationException("text value is required");
54 }
55 boolean complex = text.contains(" ") | text.contains("\\t") | text.contains("\\n") | text.contains("\\r")
56 | text.contains("\\f") | text.contains("\\v");
57
58 return complex ? new FullTextMatcher(getId(), text) : new SimpleTextMatcher(getId(), text);
59 }
60
61 @Override
62 public String toString() {
63 if (text.length() > MAX_DISPLAY_LENGTH) {
64 return "TextBuilder: " + text.substring(0, MAX_DISPLAY_LENGTH) + "...";
65 }
66 return "TextBuilder: " + text;
67 }
68 }