1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.javadpkg.field.impl;
20
21 import net.sourceforge.javadpkg.field.Field;
22
23
24
25
26
27
28
29
30
31 public abstract class AbstractField implements Field {
32
33
34
35 private boolean nameless;
36
37 private boolean empty;
38
39
40
41
42
43
44
45
46
47
48
49
50 public AbstractField(boolean nameless, boolean empty) {
51 super();
52
53 this.nameless = nameless;
54 this.empty = empty;
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 protected String formatValue(String value) {
71 StringBuilder sb;
72 String[] lines;
73
74
75 if (value == null)
76 return null;
77
78 sb = new StringBuilder();
79 lines = value.split("\n", -1);
80 for (String line : lines) {
81 if (sb.length() > 0) {
82 sb.append('\n');
83 }
84 if (line.isEmpty()) {
85 sb.append('.');
86 } else {
87 sb.append(line);
88 }
89 }
90 return sb.toString();
91 }
92
93
94 @Override
95 public boolean isNameless() {
96 return this.nameless;
97 }
98
99
100 @Override
101 public String getFormattedValue() {
102 StringBuilder sb;
103 String value;
104 String[] lines;
105
106
107 value = this.getValue();
108 if (value == null)
109 return null;
110
111 sb = new StringBuilder();
112 lines = value.split("\n", -1);
113 for (String line : lines) {
114 if (sb.length() > 0) {
115 sb.append('\n');
116 }
117 if (!".".equals(line)) {
118 sb.append(line);
119 }
120 }
121 return sb.toString();
122 }
123
124
125 @Override
126 public boolean isEmpty() {
127 return this.empty;
128 }
129
130
131 }