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