@@ -153,32 +153,24 @@ public String toString() {
153
153
154
154
protected String extractCategory (Element body ) {
155
155
String locator = ObjectUtils .firstNonNull (categoryLocator , shortDescriptionLocator );
156
- if (locator == null ) {
157
- return null ;
158
- }
159
156
160
- Element elem = body . selectFirst ( locator );
161
- if (elem == null ) {
157
+ String category = getTextOfTheFirstElement ( body , locator );
158
+ if (category == null ) {
162
159
return null ;
163
160
}
164
161
165
- String category = elem .text ();
166
162
LOG .debug ("Extracted category: '{}'" , category );
167
163
return category ;
168
164
}
169
165
170
166
protected String extractCountry (Element body ) {
171
167
String locator = ObjectUtils .firstNonNull (countryLocator , shortDescriptionLocator );
172
- if (locator == null ) {
173
- return null ;
174
- }
175
168
176
- Element elem = body . selectFirst ( locator );
177
- if (elem == null ) {
169
+ String country = getTextOfTheFirstElement ( body , locator );
170
+ if (country == null ) {
178
171
return null ;
179
172
}
180
173
181
- String country = elem .text ();
182
174
LOG .debug ("Extracted country: '{}'" , country );
183
175
return country ;
184
176
}
@@ -201,39 +193,37 @@ protected String extractImageUrl(Element body) {
201
193
202
194
protected String extractIssueDate (Element body ) {
203
195
String locator = ObjectUtils .firstNonNull (issueDateLocator , shortDescriptionLocator );
204
- if (locator == null ) {
205
- return null ;
206
- }
207
196
208
- Element elem = body . selectFirst ( locator );
209
- if (elem == null ) {
197
+ String date = getTextOfTheFirstElement ( body , locator );
198
+ if (date == null ) {
210
199
return null ;
211
200
}
212
201
213
- String date = elem .text ();
214
202
LOG .debug ("Extracted issue date: '{}'" , date );
215
203
return date ;
216
204
}
217
205
218
206
protected String extractQuantity (Element body ) {
219
- String locator = shortDescriptionLocator ;
220
- if (locator == null ) {
221
- return null ;
222
- }
223
-
224
- Element elem = body .selectFirst (locator );
225
- if (elem == null ) {
207
+ String quantity = getTextOfTheFirstElement (body , shortDescriptionLocator );
208
+ if (quantity == null ) {
226
209
return null ;
227
210
}
228
211
229
- String quantity = elem .text ();
230
212
LOG .debug ("Extracted quantity: '{}'" , quantity );
231
213
return quantity ;
232
214
}
233
215
234
- // @todo #782 SiteParser: reduce duplication between extractQuantity() and extractPerforated()
235
216
protected String extractPerforated (Element body ) {
236
- String locator = shortDescriptionLocator ;
217
+ String perforated = getTextOfTheFirstElement (body , shortDescriptionLocator );
218
+ if (perforated == null ) {
219
+ return null ;
220
+ }
221
+
222
+ LOG .debug ("Extracted perforated flag: '{}'" , perforated );
223
+ return perforated ;
224
+ }
225
+
226
+ private static String getTextOfTheFirstElement (Element body , String locator ) {
237
227
if (locator == null ) {
238
228
return null ;
239
229
}
@@ -243,9 +233,7 @@ protected String extractPerforated(Element body) {
243
233
return null ;
244
234
}
245
235
246
- String perforated = elem .text ();
247
- LOG .debug ("Extracted perforated flag: '{}'" , perforated );
248
- return perforated ;
236
+ return elem .text ();
249
237
}
250
238
251
239
}
0 commit comments