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 protected Map<String, String> propertyDefinitions = new LinkedHashMap<String, String>();
26 protected boolean showSuppressedViolations = true;
27 protected Writer writer;
28
29 public AbstractRenderer(String name, String description) {
30 this.name = name;
31 this.description = description;
32 }
33
34
35
36
37 public String getName() {
38 return name;
39 }
40
41
42
43
44 public void setName(String name) {
45 this.name = name;
46 }
47
48
49
50
51 public String getDescription() {
52 return description;
53 }
54
55
56
57
58 public void setDescription(String description) {
59 this.description = description;
60 }
61
62
63
64
65 @Deprecated
66 public Map<String, String> getPropertyDefinitions() {
67 return propertyDefinitions;
68 }
69
70
71
72
73
74
75 @Deprecated
76 protected void defineProperty(String name, String description) {
77 StringProperty propertyDescriptor = new StringProperty(name, description, null, 0);
78 definePropertyDescriptor(propertyDescriptor);
79 propertyDefinitions.put(name, description);
80 }
81
82
83
84
85 public boolean isShowSuppressedViolations() {
86 return showSuppressedViolations;
87 }
88
89
90
91
92 public void setShowSuppressedViolations(boolean showSuppressedViolations) {
93 this.showSuppressedViolations = showSuppressedViolations;
94 }
95
96
97
98
99 public void setWriter(Writer writer) {
100 this.writer = writer;
101 }
102
103
104
105
106 public Writer getWriter() {
107 return writer;
108 }
109
110 public void flush() {
111 try {
112 this.writer.flush();
113 } catch (IOException e) {
114 throw new IllegalStateException(e);
115 } finally {
116 IOUtils.closeQuietly(writer);
117 }
118 }
119 }