1 package org.apache.velocity.tools.config;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Iterator;
23
24
25
26
27
28
29
30 public class ConfigurationCleaner extends LogSupport
31 {
32 private static final String LOG_PREFIX = "ConfigurationCleaner : ";
33
34 @Override
35 protected String logPrefix()
36 {
37 return LOG_PREFIX;
38 }
39
40 public void clean(FactoryConfiguration factory)
41 {
42 if (isTraceEnabled())
43 {
44 trace("Cleaning factory: "+factory);
45 }
46
47 cleanProperties(factory);
48
49
50 Iterator<Data> i = factory.getData().iterator();
51 while (i.hasNext())
52 {
53 Data datum = i.next();
54 try
55 {
56 datum.validate();
57 }
58 catch (ConfigurationException ce)
59 {
60 if (isDebugEnabled())
61 {
62 debug(ce.getMessage());
63 }
64 if (isWarnEnabled())
65 {
66 warn("Removing "+datum);
67 }
68 i.remove();
69 }
70 }
71
72
73 for (ToolboxConfiguration toolbox : factory.getToolboxes())
74 {
75 clean(toolbox);
76 }
77 }
78
79 public void clean(ToolboxConfiguration toolbox)
80 {
81 cleanProperties(toolbox);
82
83
84 Iterator<ToolConfiguration> i = toolbox.getTools().iterator();
85 while (i.hasNext())
86 {
87 ToolConfiguration tool = i.next();
88 cleanProperties(tool);
89 try
90 {
91 tool.validate();
92 }
93 catch (ConfigurationException ce)
94 {
95 if (isDebugEnabled())
96 {
97 debug(ce.getMessage());
98 }
99 if (isWarnEnabled())
100 {
101 warn("Removing "+tool);
102 }
103 i.remove();
104 }
105 }
106
107
108 }
109
110 public void clean(Configuration config)
111 {
112
113 if (config instanceof FactoryConfiguration)
114 {
115 clean((FactoryConfiguration)config);
116 }
117 else if (config instanceof ToolboxConfiguration)
118 {
119 clean((ToolboxConfiguration)config);
120 }
121 else
122 {
123 cleanProperties(config);
124 }
125 }
126
127 public void cleanProperties(Configuration config)
128 {
129
130 Iterator<Property> i = config.getProperties().iterator();
131 while (i.hasNext())
132 {
133 Property prop = i.next();
134 try
135 {
136 prop.validate();
137 }
138 catch (ConfigurationException ce)
139 {
140 if (isDebugEnabled())
141 {
142 debug(ce.getMessage());
143 }
144 if (isWarnEnabled())
145 {
146 warn("Removing "+prop);
147 }
148 i.remove();
149 }
150 }
151 }
152
153 }