Skip to content

Commit d053411

Browse files
committed
PDFBOX-6121: avoid ClassCastException elsewhere
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930492 13f79535-47bb-0310-9956-ffa450edef68
1 parent 68aa2cf commit d053411

File tree

8 files changed

+91
-94
lines changed

8 files changed

+91
-94
lines changed

xmpbox/src/main/java/org/apache/xmpbox/schema/AdobePDFSchema.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public AdobePDFSchema(XMPMetadata metadata, String ownPrefix)
8080
*/
8181
public void setKeywords(String value)
8282
{
83-
TextType keywords;
84-
keywords = createTextType(KEYWORDS, value);
83+
TextType keywords = createTextType(KEYWORDS, value);
8584
addProperty(keywords);
8685
}
8786

@@ -104,8 +103,7 @@ public void setKeywordsProperty(TextType keywords)
104103
*/
105104
public void setPDFVersion(String value)
106105
{
107-
TextType version;
108-
version = createTextType(PDF_VERSION, value);
106+
TextType version = createTextType(PDF_VERSION, value);
109107
addProperty(version);
110108

111109
}
@@ -129,8 +127,7 @@ public void setPDFVersionProperty(TextType version)
129127
*/
130128
public void setProducer(String value)
131129
{
132-
TextType producer;
133-
producer = createTextType(PRODUCER, value);
130+
TextType producer = createTextType(PRODUCER, value);
134131
addProperty(producer);
135132
}
136133

xmpbox/src/main/java/org/apache/xmpbox/schema/ExifSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public ExifSchema(XMPMetadata metadata, String ownPrefix)
295295
*/
296296
public ArrayProperty getUserCommentProperty()
297297
{
298-
return (ArrayProperty) getProperty(USER_COMMENT);
298+
return getPropertyAs(USER_COMMENT, ArrayProperty.class);
299299
}
300300

301301
/**

xmpbox/src/main/java/org/apache/xmpbox/schema/PDFAExtensionSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public PDFAExtensionSchema(XMPMetadata metadata, String prefix)
6363
*/
6464
public ArrayProperty getSchemasProperty()
6565
{
66-
return (ArrayProperty) getProperty(SCHEMAS);
66+
return getPropertyAs(SCHEMAS, ArrayProperty.class);
6767
}
6868

6969
}

xmpbox/src/main/java/org/apache/xmpbox/schema/PhotoshopSchema.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ public PhotoshopSchema(XMPMetadata metadata, String ownPrefix)
117117

118118
public URIType getAncestorIDProperty()
119119
{
120-
return (URIType) getProperty(ANCESTORID);
120+
return getPropertyAs(ANCESTORID, URIType.class);
121121
}
122122

123123
public String getAncestorID()
124124
{
125-
TextType tt = ((TextType) getProperty(ANCESTORID));
125+
TextType tt = getAncestorIDProperty();
126126
return tt == null ? null : tt.getStringValue();
127127
}
128128

@@ -139,12 +139,12 @@ public void setAncestorIDProperty(URIType text)
139139

140140
public TextType getAuthorsPositionProperty()
141141
{
142-
return (TextType) getProperty(AUTHORS_POSITION);
142+
return getPropertyAs(AUTHORS_POSITION, TextType.class);
143143
}
144144

145145
public String getAuthorsPosition()
146146
{
147-
TextType tt = ((TextType) getProperty(AUTHORS_POSITION));
147+
TextType tt = getAuthorsPositionProperty();
148148
return tt == null ? null : tt.getStringValue();
149149
}
150150

@@ -161,12 +161,12 @@ public void setAuthorsPositionProperty(TextType text)
161161

162162
public TextType getCaptionWriterProperty()
163163
{
164-
return (TextType) getProperty(CAPTION_WRITER);
164+
return getPropertyAs(CAPTION_WRITER, TextType.class);
165165
}
166166

167167
public String getCaptionWriter()
168168
{
169-
TextType tt = ((TextType) getProperty(CAPTION_WRITER));
169+
TextType tt = getCaptionWriterProperty();
170170
return tt == null ? null : tt.getStringValue();
171171
}
172172

@@ -183,12 +183,12 @@ public void setCaptionWriterProperty(ProperNameType text)
183183

184184
public TextType getCategoryProperty()
185185
{
186-
return (TextType) getProperty(CATEGORY);
186+
return getPropertyAs(CATEGORY, TextType.class);
187187
}
188188

189189
public String getCategory()
190190
{
191-
TextType tt = ((TextType) getProperty(CATEGORY));
191+
TextType tt = getCategoryProperty();
192192
return tt == null ? null : tt.getStringValue();
193193
}
194194

@@ -205,12 +205,12 @@ public void setCategoryProperty(TextType text)
205205

206206
public TextType getCityProperty()
207207
{
208-
return (TextType) getProperty(CITY);
208+
return getPropertyAs(CITY, TextType.class);
209209
}
210210

211211
public String getCity()
212212
{
213-
TextType tt = ((TextType) getProperty(CITY));
213+
TextType tt = getCityProperty();
214214
return tt == null ? null : tt.getStringValue();
215215
}
216216

@@ -227,12 +227,12 @@ public void setCityProperty(TextType text)
227227

228228
public IntegerType getColorModeProperty()
229229
{
230-
return (IntegerType) getProperty(COLOR_MODE);
230+
return getPropertyAs(COLOR_MODE, IntegerType.class);
231231
}
232232

233233
public Integer getColorMode()
234234
{
235-
IntegerType tt = ((IntegerType) getProperty(COLOR_MODE));
235+
IntegerType tt = getColorModeProperty();
236236
return tt == null ? null : tt.getValue();
237237
}
238238

@@ -249,12 +249,12 @@ public void setColorModeProperty(IntegerType text)
249249

250250
public TextType getCountryProperty()
251251
{
252-
return (TextType) getProperty(COUNTRY);
252+
return getPropertyAs(COUNTRY, TextType.class);
253253
}
254254

255255
public String getCountry()
256256
{
257-
TextType tt = ((TextType) getProperty(COUNTRY));
257+
TextType tt = getCountryProperty();
258258
return tt == null ? null : tt.getStringValue();
259259
}
260260

@@ -271,12 +271,12 @@ public void setCountryProperty(TextType text)
271271

272272
public TextType getCreditProperty()
273273
{
274-
return (TextType) getProperty(CREDIT);
274+
return getPropertyAs(CREDIT, TextType.class);
275275
}
276276

277277
public String getCredit()
278278
{
279-
TextType tt = ((TextType) getProperty(CREDIT));
279+
TextType tt = getCreditProperty();
280280
return tt == null ? null : tt.getStringValue();
281281
}
282282

@@ -293,12 +293,12 @@ public void setCreditProperty(TextType text)
293293

294294
public DateType getDateCreatedProperty()
295295
{
296-
return (DateType) getProperty(DATE_CREATED);
296+
return getPropertyAs(DATE_CREATED, DateType.class);
297297
}
298298

299299
public String getDateCreated()
300300
{
301-
TextType tt = ((TextType) getProperty(DATE_CREATED));
301+
TextType tt = ((TextType) getProperty(DATE_CREATED)); //TODO cast looks highly suspicious
302302
return tt == null ? null : tt.getStringValue();
303303
}
304304

@@ -320,7 +320,7 @@ public void addDocumentAncestors(String text)
320320

321321
public ArrayProperty getDocumentAncestorsProperty()
322322
{
323-
return (ArrayProperty) getProperty(DOCUMENT_ANCESTORS);
323+
return getPropertyAs(DOCUMENT_ANCESTORS, ArrayProperty.class);
324324
}
325325

326326
public List<String> getDocumentAncestors()
@@ -330,12 +330,12 @@ public List<String> getDocumentAncestors()
330330

331331
public TextType getHeadlineProperty()
332332
{
333-
return (TextType) getProperty(HEADLINE);
333+
return getPropertyAs(HEADLINE, TextType.class);
334334
}
335335

336336
public String getHeadline()
337337
{
338-
TextType tt = ((TextType) getProperty(HEADLINE));
338+
TextType tt = getHeadlineProperty();
339339
return tt == null ? null : tt.getStringValue();
340340
}
341341

@@ -352,12 +352,12 @@ public void setHeadlineProperty(TextType text)
352352

353353
public TextType getHistoryProperty()
354354
{
355-
return (TextType) getProperty(HISTORY);
355+
return getPropertyAs(HISTORY, TextType.class);
356356
}
357357

358358
public String getHistory()
359359
{
360-
TextType tt = ((TextType) getProperty(HISTORY));
360+
TextType tt = getHistoryProperty();
361361
return tt == null ? null : tt.getStringValue();
362362
}
363363

@@ -374,12 +374,12 @@ public void setHistoryProperty(TextType text)
374374

375375
public TextType getICCProfileProperty()
376376
{
377-
return (TextType) getProperty(ICC_PROFILE);
377+
return getPropertyAs(ICC_PROFILE, TextType.class);
378378
}
379379

380380
public String getICCProfile()
381381
{
382-
TextType tt = ((TextType) getProperty(ICC_PROFILE));
382+
TextType tt = getICCProfileProperty();
383383
return tt == null ? null : tt.getStringValue();
384384
}
385385

@@ -396,12 +396,12 @@ public void setICCProfileProperty(TextType text)
396396

397397
public TextType getInstructionsProperty()
398398
{
399-
return (TextType) getProperty(INSTRUCTIONS);
399+
return getPropertyAs(INSTRUCTIONS, TextType.class);
400400
}
401401

402402
public String getInstructions()
403403
{
404-
TextType tt = ((TextType) getProperty(INSTRUCTIONS));
404+
TextType tt = getInstructionsProperty();
405405
return tt == null ? null : tt.getStringValue();
406406
}
407407

@@ -419,12 +419,12 @@ public void setInstructionsProperty(TextType text)
419419

420420
public TextType getSourceProperty()
421421
{
422-
return (TextType) getProperty(SOURCE);
422+
return getPropertyAs(SOURCE, TextType.class);
423423
}
424424

425425
public String getSource()
426426
{
427-
TextType tt = ((TextType) getProperty(SOURCE));
427+
TextType tt = getSourceProperty();
428428
return tt == null ? null : tt.getStringValue();
429429
}
430430

@@ -441,12 +441,12 @@ public void setSourceProperty(TextType text)
441441

442442
public TextType getStateProperty()
443443
{
444-
return (TextType) getProperty(STATE);
444+
return getPropertyAs(STATE, TextType.class);
445445
}
446446

447447
public String getState()
448448
{
449-
TextType tt = ((TextType) getProperty(STATE));
449+
TextType tt = getStateProperty();
450450
return tt == null ? null : tt.getStringValue();
451451
}
452452

@@ -463,12 +463,12 @@ public void setStateProperty(TextType text)
463463

464464
public TextType getSupplementalCategoriesProperty()
465465
{
466-
return (TextType) getProperty(SUPPLEMENTAL_CATEGORIES);
466+
return getPropertyAs(SUPPLEMENTAL_CATEGORIES, TextType.class);
467467
}
468468

469469
public String getSupplementalCategories()
470470
{
471-
TextType tt = ((TextType) getProperty(SUPPLEMENTAL_CATEGORIES));
471+
TextType tt = getSupplementalCategoriesProperty();
472472
return tt == null ? null : tt.getStringValue();
473473
}
474474

@@ -522,12 +522,12 @@ public List<LayerType> getTextLayers() throws BadFieldValueException
522522

523523
public TextType getTransmissionReferenceProperty()
524524
{
525-
return (TextType) getProperty(TRANSMISSION_REFERENCE);
525+
return getPropertyAs(TRANSMISSION_REFERENCE, TextType.class);
526526
}
527527

528528
public String getTransmissionReference()
529529
{
530-
TextType tt = ((TextType) getProperty(TRANSMISSION_REFERENCE));
530+
TextType tt = getTransmissionReferenceProperty();
531531
return tt == null ? null : tt.getStringValue();
532532
}
533533

@@ -544,12 +544,12 @@ public void setTransmissionReferenceProperty(TextType text)
544544

545545
public IntegerType getUrgencyProperty()
546546
{
547-
return (IntegerType) getProperty(URGENCY);
547+
return getPropertyAs(URGENCY, IntegerType.class);
548548
}
549549

550550
public Integer getUrgency()
551551
{
552-
IntegerType tt = ((IntegerType) getProperty(URGENCY));
552+
IntegerType tt = getUrgencyProperty();
553553
return tt == null ? null : tt.getValue();
554554
}
555555

xmpbox/src/main/java/org/apache/xmpbox/schema/TiffSchema.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public TiffSchema(XMPMetadata metadata, String prefix)
126126
*/
127127
public ProperNameType getArtistProperty()
128128
{
129-
return (ProperNameType) getProperty(ARTIST);
129+
return getPropertyAs(ARTIST, ProperNameType.class);
130130
}
131131

132132
/**
@@ -136,7 +136,7 @@ public ProperNameType getArtistProperty()
136136
*/
137137
public String getArtist()
138138
{
139-
ProperNameType tt = (ProperNameType) getProperty(ARTIST);
139+
ProperNameType tt = getArtistProperty();
140140
return tt == null ? null : tt.getStringValue();
141141
}
142142

@@ -157,7 +157,7 @@ public void setArtist(String text)
157157
*/
158158
public ArrayProperty getImageDescriptionProperty()
159159
{
160-
return (ArrayProperty) getProperty(IMAGE_DESCRIPTION);
160+
return getPropertyAs(IMAGE_DESCRIPTION, ArrayProperty.class);
161161
}
162162

163163
/**
@@ -215,7 +215,7 @@ public void addImageDescription(String lang, String value)
215215
*/
216216
public ArrayProperty getCopyrightProperty()
217217
{
218-
return (ArrayProperty) getProperty(COPYRIGHT);
218+
return getPropertyAs(COPYRIGHT, ArrayProperty.class);
219219
}
220220

221221
/**

0 commit comments

Comments
 (0)