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
26
27
28
29 public class TextBuilder extends AbstractBuilder {
30
31 private String text;
32
33
34
35
36
37
38 public TextBuilder setSimpleText(String text) {
39 this.text = text.trim();
40 if (StringUtils.isBlank(text)) {
41 throw new ConfigurationException("'text' may not be null");
42 }
43 return this;
44 }
45
46 @Override
47 public SimpleTextMatcher build() {
48 if (StringUtils.isBlank(text)) {
49 throw new ConfigurationException("text value is required");
50 }
51 boolean complex = text.contains(" ") | text.contains("\\t") | text.contains("\\n") | text.contains("\\r")
52 | text.contains("\\f") | text.contains("\\v");
53
54 return complex ? new FullTextMatcher(getId(), text) : new SimpleTextMatcher(getId(), text);
55 }
56
57 @Override
58 public String toString() {
59 if (text.length() > 20) {
60 return "TextBuilder: " + text.substring(0, 20) + "...";
61 }
62 return "TextBuilder: " + text;
63 }
64 }