1
2
3
4 package net.sourceforge.pmd.renderers;
5
6 import java.io.IOException;
7 import java.io.Writer;
8 import java.util.LinkedHashMap;
9 import java.util.Map;
10
11 import net.sourceforge.pmd.AbstractPropertySource;
12 import net.sourceforge.pmd.lang.rule.properties.StringProperty;
13
14 import org.apache.commons.io.IOUtils;
15
16
17
18
19 public abstract class AbstractRenderer extends AbstractPropertySource implements Renderer {
20
21 protected String name;
22 protected String description;
23
24 @Deprecated
25
26 protected Map<String, String> propertyDefinitions = new LinkedHashMap<String, String>();
27 protected boolean showSuppressedViolations = true;
28 protected Writer writer;
29
30 public AbstractRenderer(String name, String description) {
31 this.name = name;
32 this.description = description;
33 }
34
35
36
37
38 public String getName() {
39 return name;
40 }
41
42
43
44
45 public void setName(String name) {
46 this.name = name;
47 }
48
49
50
51
52 public String getDescription() {
53 return description;
54 }
55
56
57
58
59 public void setDescription(String description) {
60 this.description = description;
61 }
62
63
64
65
66 @Deprecated
67
68 public Map<String, String> getPropertyDefinitions() {
69 return propertyDefinitions;
70 }
71
72
73
74
75
76
77
78 @Deprecated
79
80
81 protected void defineProperty(String name, String description) {
82 StringProperty propertyDescriptor = new StringProperty(name, description, null, 0);
83 definePropertyDescriptor(propertyDescriptor);
84 propertyDefinitions.put(name, description);
85 }
86
87
88
89
90 public boolean isShowSuppressedViolations() {
91 return showSuppressedViolations;
92 }
93
94
95
96
97 public void setShowSuppressedViolations(boolean showSuppressedViolations) {
98 this.showSuppressedViolations = showSuppressedViolations;
99 }
100
101
102
103
104 public void setWriter(Writer writer) {
105 this.writer = writer;
106 }
107
108
109
110
111 public Writer getWriter() {
112 return writer;
113 }
114
115 public void flush() {
116 try {
117 this.writer.flush();
118 } catch (IOException e) {
119 throw new IllegalStateException(e);
120 } finally {
121 IOUtils.closeQuietly(writer);
122 }
123 }
124 }