1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.yaml.snakeyaml; |
18 | |
|
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.yaml.snakeyaml.emitter.Emitter; |
22 | |
import org.yaml.snakeyaml.emitter.ScalarAnalysis; |
23 | |
import org.yaml.snakeyaml.error.YAMLException; |
24 | |
import org.yaml.snakeyaml.nodes.Tag; |
25 | |
|
26 | 6086 | public class DumperOptions { |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 365 | public enum ScalarStyle { |
37 | 1 | DOUBLE_QUOTED(new Character('"')), SINGLE_QUOTED(new Character('\'')), LITERAL( |
38 | 1 | new Character('|')), FOLDED(new Character('>')), PLAIN(null); |
39 | |
private Character styleChar; |
40 | |
|
41 | 5 | private ScalarStyle(Character style) { |
42 | 5 | this.styleChar = style; |
43 | 5 | } |
44 | |
|
45 | |
public Character getChar() { |
46 | 615613 | return styleChar; |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
public String toString() { |
51 | 1 | return "Scalar style: '" + styleChar + "'"; |
52 | |
} |
53 | |
|
54 | |
public static ScalarStyle createStyle(Character style) { |
55 | 604870 | if (style == null) { |
56 | 379176 | return PLAIN; |
57 | |
} else { |
58 | 225694 | switch (style) { |
59 | |
case '"': |
60 | 4399 | return DOUBLE_QUOTED; |
61 | |
case '\'': |
62 | 220362 | return SINGLE_QUOTED; |
63 | |
case '|': |
64 | 476 | return LITERAL; |
65 | |
case '>': |
66 | 457 | return FOLDED; |
67 | |
default: |
68 | 0 | throw new YAMLException("Unknown scalar style character: " + style); |
69 | |
} |
70 | |
} |
71 | |
} |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | 2 | public enum FlowStyle { |
82 | 1 | FLOW(Boolean.TRUE), BLOCK(Boolean.FALSE), AUTO(null); |
83 | |
|
84 | |
private Boolean styleBoolean; |
85 | |
|
86 | 3 | private FlowStyle(Boolean flowStyle) { |
87 | 3 | styleBoolean = flowStyle; |
88 | 3 | } |
89 | |
|
90 | |
public Boolean getStyleBoolean() { |
91 | 48295 | return styleBoolean; |
92 | |
} |
93 | |
|
94 | |
@Override |
95 | |
public String toString() { |
96 | 1 | return "Flow style: '" + styleBoolean + "'"; |
97 | |
} |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 7 | public enum LineBreak { |
104 | 1 | WIN("\r\n"), MAC("\r"), UNIX("\n"); |
105 | |
|
106 | |
private String lineBreak; |
107 | |
|
108 | 3 | private LineBreak(String lineBreak) { |
109 | 3 | this.lineBreak = lineBreak; |
110 | 3 | } |
111 | |
|
112 | |
public String getString() { |
113 | 18515 | return lineBreak; |
114 | |
} |
115 | |
|
116 | |
@Override |
117 | |
public String toString() { |
118 | 1 | return "Line break: " + name(); |
119 | |
} |
120 | |
|
121 | |
public static LineBreak getPlatformLineBreak() { |
122 | 6 | String platformLineBreak = System.getProperty("line.separator"); |
123 | 16 | for (LineBreak lb : values()) { |
124 | 15 | if (lb.lineBreak.equals(platformLineBreak)) { |
125 | 5 | return lb; |
126 | |
} |
127 | |
} |
128 | 1 | return LineBreak.UNIX; |
129 | |
} |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 1 | public enum Version { |
136 | 1 | V1_0(new Integer[] { 1, 0 }), V1_1(new Integer[] { 1, 1 }); |
137 | |
|
138 | |
private Integer[] version; |
139 | |
|
140 | 2 | private Version(Integer[] version) { |
141 | 2 | this.version = version; |
142 | 2 | } |
143 | |
|
144 | |
public Integer[] getArray() { |
145 | 2 | return version; |
146 | |
} |
147 | |
|
148 | |
@Override |
149 | |
public String toString() { |
150 | 1 | return "Version: " + version[0] + "." + version[1]; |
151 | |
} |
152 | |
} |
153 | |
|
154 | 6086 | private ScalarStyle defaultStyle = ScalarStyle.PLAIN; |
155 | 6086 | private FlowStyle defaultFlowStyle = FlowStyle.AUTO; |
156 | 6086 | private boolean canonical = false; |
157 | 6086 | private boolean allowUnicode = true; |
158 | 6086 | private boolean allowReadOnlyProperties = false; |
159 | 6086 | private int indent = 2; |
160 | 6086 | private int bestWidth = 80; |
161 | 6086 | private LineBreak lineBreak = LineBreak.UNIX; |
162 | 6086 | private boolean explicitStart = false; |
163 | 6086 | private boolean explicitEnd = false; |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | 6086 | private Tag explicitRoot = null; |
169 | 6086 | private Version version = null; |
170 | 6086 | private Map<String, String> tags = null; |
171 | 6086 | private Boolean prettyFlow = false; |
172 | |
|
173 | |
public boolean isAllowUnicode() { |
174 | 18507 | return allowUnicode; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public void setAllowUnicode(boolean allowUnicode) { |
186 | 1 | this.allowUnicode = allowUnicode; |
187 | 1 | } |
188 | |
|
189 | |
public ScalarStyle getDefaultScalarStyle() { |
190 | 3963 | return defaultStyle; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
public void setDefaultScalarStyle(ScalarStyle defaultStyle) { |
201 | 27 | if (defaultStyle == null) { |
202 | 1 | throw new NullPointerException("Use ScalarStyle enum."); |
203 | |
} |
204 | 26 | this.defaultStyle = defaultStyle; |
205 | 26 | } |
206 | |
|
207 | |
public void setIndent(int indent) { |
208 | 8 | if (indent < Emitter.MIN_INDENT) { |
209 | 2 | throw new YAMLException("Indent must be at least " + Emitter.MIN_INDENT); |
210 | |
} |
211 | 6 | if (indent > Emitter.MAX_INDENT) { |
212 | 1 | throw new YAMLException("Indent must be at most " + Emitter.MAX_INDENT); |
213 | |
} |
214 | 5 | this.indent = indent; |
215 | 5 | } |
216 | |
|
217 | |
public int getIndent() { |
218 | 55521 | return this.indent; |
219 | |
} |
220 | |
|
221 | |
public void setVersion(Version version) { |
222 | 2 | this.version = version; |
223 | 2 | } |
224 | |
|
225 | |
public Version getVersion() { |
226 | 16397 | return this.version; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public void setCanonical(boolean canonical) { |
237 | 279 | this.canonical = canonical; |
238 | 279 | } |
239 | |
|
240 | |
public boolean isCanonical() { |
241 | 18507 | return this.canonical; |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
public void setPrettyFlow(boolean prettyFlow) { |
252 | 7 | this.prettyFlow = prettyFlow; |
253 | 7 | } |
254 | |
|
255 | |
public boolean isPrettyFlow() { |
256 | 18507 | return this.prettyFlow; |
257 | |
} |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
public void setWidth(int bestWidth) { |
268 | 4 | this.bestWidth = bestWidth; |
269 | 4 | } |
270 | |
|
271 | |
public int getWidth() { |
272 | 37014 | return this.bestWidth; |
273 | |
} |
274 | |
|
275 | |
public LineBreak getLineBreak() { |
276 | 18507 | return lineBreak; |
277 | |
} |
278 | |
|
279 | |
public void setDefaultFlowStyle(FlowStyle defaultFlowStyle) { |
280 | 39 | if (defaultFlowStyle == null) { |
281 | 1 | throw new NullPointerException("Use FlowStyle enum."); |
282 | |
} |
283 | 38 | this.defaultFlowStyle = defaultFlowStyle; |
284 | 38 | } |
285 | |
|
286 | |
public FlowStyle getDefaultFlowStyle() { |
287 | 3963 | return defaultFlowStyle; |
288 | |
} |
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
public Tag getExplicitRoot() { |
294 | 3321 | return explicitRoot; |
295 | |
} |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
public void setExplicitRoot(String expRoot) { |
304 | 0 | setExplicitRoot(new Tag(expRoot)); |
305 | 0 | } |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
public void setExplicitRoot(Tag expRoot) { |
314 | 6 | if (expRoot == null) { |
315 | 1 | throw new NullPointerException("Root tag must be specified."); |
316 | |
} |
317 | 5 | this.explicitRoot = expRoot; |
318 | 5 | } |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
public void setLineBreak(LineBreak lineBreak) { |
326 | 3 | if (lineBreak == null) { |
327 | 1 | throw new NullPointerException("Specify line break."); |
328 | |
} |
329 | 2 | this.lineBreak = lineBreak; |
330 | 2 | } |
331 | |
|
332 | |
public boolean isExplicitStart() { |
333 | 16395 | return explicitStart; |
334 | |
} |
335 | |
|
336 | |
public void setExplicitStart(boolean explicitStart) { |
337 | 11 | this.explicitStart = explicitStart; |
338 | 11 | } |
339 | |
|
340 | |
public boolean isExplicitEnd() { |
341 | 16395 | return explicitEnd; |
342 | |
} |
343 | |
|
344 | |
public void setExplicitEnd(boolean explicitEnd) { |
345 | 6 | this.explicitEnd = explicitEnd; |
346 | 6 | } |
347 | |
|
348 | |
public Map<String, String> getTags() { |
349 | 16395 | return tags; |
350 | |
} |
351 | |
|
352 | |
|
353 | |
public void setTags(Map<String, String> tags) { |
354 | 1 | this.tags = tags; |
355 | 1 | } |
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
public ScalarStyle calculateScalarStyle(ScalarAnalysis analysis, ScalarStyle style) { |
367 | 604869 | return style; |
368 | |
} |
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
public boolean isAllowReadOnlyProperties() { |
377 | 3963 | return allowReadOnlyProperties; |
378 | |
} |
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
public void setAllowReadOnlyProperties(boolean allowReadOnlyProperties) { |
389 | 12 | this.allowReadOnlyProperties = allowReadOnlyProperties; |
390 | 12 | } |
391 | |
} |