| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
package com.adobe.internal.xmp.impl; |
| 11 |
|
| 12 |
import java.util.ArrayList; |
| 13 |
import java.util.Calendar; |
| 14 |
import java.util.HashMap; |
| 15 |
import java.util.Iterator; |
| 16 |
import java.util.List; |
| 17 |
import java.util.Map; |
| 18 |
|
| 19 |
import com.adobe.internal.xmp.XMPConst; |
| 20 |
import com.adobe.internal.xmp.XMPDateTime; |
| 21 |
import com.adobe.internal.xmp.XMPError; |
| 22 |
import com.adobe.internal.xmp.XMPException; |
| 23 |
import com.adobe.internal.xmp.XMPMeta; |
| 24 |
import com.adobe.internal.xmp.XMPMetaFactory; |
| 25 |
import com.adobe.internal.xmp.XMPUtils; |
| 26 |
import com.adobe.internal.xmp.impl.xpath.XMPPath; |
| 27 |
import com.adobe.internal.xmp.impl.xpath.XMPPathParser; |
| 28 |
import com.adobe.internal.xmp.options.ParseOptions; |
| 29 |
import com.adobe.internal.xmp.options.PropertyOptions; |
| 30 |
import com.adobe.internal.xmp.properties.XMPAliasInfo; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class XMPNormalizer |
| 38 |
{ |
| 39 |
|
| 40 |
private static Map dcArrayForms; |
| 41 |
|
| 42 |
static |
| 43 |
{ |
| 44 |
initDCArrays(); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
private XMPNormalizer() |
| 52 |
{ |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
static XMPMeta process(XMPMetaImpl xmp, ParseOptions options) throws XMPException |
| 65 |
{ |
| 66 |
XMPNode tree = xmp.getRoot(); |
| 67 |
|
| 68 |
touchUpDataModel(xmp); |
| 69 |
|
| 70 |
|
| 71 |
moveExplicitAliases(tree, options); |
| 72 |
|
| 73 |
tweakOldXMP(tree); |
| 74 |
|
| 75 |
deleteEmptySchemas(tree); |
| 76 |
|
| 77 |
return xmp; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
private static void tweakOldXMP(XMPNode tree) throws XMPException |
| 95 |
{ |
| 96 |
if (tree.getName() != null && tree.getName().length() >= Utils.UUID_LENGTH) |
| 97 |
{ |
| 98 |
String nameStr = tree.getName().toLowerCase(); |
| 99 |
if (nameStr.startsWith("uuid:")) |
| 100 |
{ |
| 101 |
nameStr = nameStr.substring(5); |
| 102 |
} |
| 103 |
|
| 104 |
if (Utils.checkUUIDFormat(nameStr)) |
| 105 |
{ |
| 106 |
|
| 107 |
XMPPath path = XMPPathParser.expandXPath(XMPConst.NS_XMP_MM, "InstanceID"); |
| 108 |
XMPNode idNode = XMPNodeUtils.findNode (tree, path, true, null); |
| 109 |
if (idNode != null) |
| 110 |
{ |
| 111 |
idNode.setOptions(null); |
| 112 |
idNode.setValue("uuid:" + nameStr); |
| 113 |
idNode.removeChildren(); |
| 114 |
idNode.removeQualifiers(); |
| 115 |
tree.setName(null); |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
throw new XMPException("Failure creating xmpMM:InstanceID", |
| 120 |
XMPError.INTERNALFAILURE); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
private static void touchUpDataModel(XMPMetaImpl xmp) throws XMPException |
| 134 |
{ |
| 135 |
|
| 136 |
|
| 137 |
XMPNodeUtils.findSchemaNode(xmp.getRoot(), XMPConst.NS_DC, true); |
| 138 |
|
| 139 |
|
| 140 |
for (Iterator it = xmp.getRoot().iterateChildren(); it.hasNext();) |
| 141 |
{ |
| 142 |
XMPNode currSchema = (XMPNode) it.next(); |
| 143 |
if (XMPConst.NS_DC.equals(currSchema.getName())) |
| 144 |
{ |
| 145 |
normalizeDCArrays(currSchema); |
| 146 |
} |
| 147 |
else if (XMPConst.NS_EXIF.equals(currSchema.getName())) |
| 148 |
{ |
| 149 |
|
| 150 |
fixGPSTimeStamp(currSchema); |
| 151 |
XMPNode userComment = XMPNodeUtils.findChildNode(currSchema, "exif:UserComment", |
| 152 |
false); |
| 153 |
if (userComment != null) |
| 154 |
{ |
| 155 |
if(userComment.getOptions().isSimple()){ |
| 156 |
XMPNode newNode = new XMPNode(XMPConst.ARRAY_ITEM_NAME, userComment.getValue(), |
| 157 |
userComment.getOptions()); |
| 158 |
newNode.setParent(userComment); |
| 159 |
|
| 160 |
int QualNo = userComment.getQualifierLength(); |
| 161 |
while(QualNo > 0){ |
| 162 |
newNode.addQualifier(userComment.getQualifier(userComment.getQualifierLength() - QualNo)); |
| 163 |
--QualNo; |
| 164 |
} |
| 165 |
|
| 166 |
userComment.removeQualifiers(); |
| 167 |
if ( ! newNode.getOptions().getHasLanguage() ) { |
| 168 |
XMPNode langQual = new XMPNode ( "xml:lang", "x-default", new PropertyOptions().setQualifier(true) ); |
| 169 |
newNode.addQualifier( langQual ); |
| 170 |
newNode.getOptions().setHasQualifiers(true); |
| 171 |
newNode.getOptions().setHasLanguage(true); |
| 172 |
} |
| 173 |
userComment.addChild(newNode); |
| 174 |
userComment.setOptions(new PropertyOptions(PropertyOptions.ARRAY | PropertyOptions.ARRAY_ORDERED |
| 175 |
|PropertyOptions.ARRAY_ALT_TEXT | PropertyOptions.ARRAY_ALTERNATE)); |
| 176 |
userComment.setValue(""); |
| 177 |
|
| 178 |
|
| 179 |
} |
| 180 |
repairAltText(userComment); |
| 181 |
} |
| 182 |
} |
| 183 |
else if (XMPConst.NS_DM.equals(currSchema.getName())) |
| 184 |
{ |
| 185 |
|
| 186 |
|
| 187 |
XMPNode dmCopyright = XMPNodeUtils.findChildNode(currSchema, "xmpDM:copyright", |
| 188 |
false); |
| 189 |
if (dmCopyright != null) |
| 190 |
{ |
| 191 |
migrateAudioCopyright(xmp, dmCopyright); |
| 192 |
} |
| 193 |
} |
| 194 |
else if (XMPConst.NS_XMP_RIGHTS.equals(currSchema.getName())) |
| 195 |
{ |
| 196 |
XMPNode arrayNode = XMPNodeUtils.findChildNode(currSchema, "xmpRights:UsageTerms", |
| 197 |
false); |
| 198 |
if (arrayNode != null) |
| 199 |
{ |
| 200 |
repairAltText(arrayNode); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
private static void normalizeDCArrays(XMPNode dcSchema) throws XMPException |
| 218 |
{ |
| 219 |
for (int i = 1; i <= dcSchema.getChildrenLength(); i++) |
| 220 |
{ |
| 221 |
XMPNode currProp = dcSchema.getChild(i); |
| 222 |
|
| 223 |
PropertyOptions arrayForm = (PropertyOptions) dcArrayForms.get(currProp.getName()); |
| 224 |
if (arrayForm == null) |
| 225 |
{ |
| 226 |
continue; |
| 227 |
} |
| 228 |
else if (currProp.getOptions().isSimple()) |
| 229 |
{ |
| 230 |
|
| 231 |
|
| 232 |
XMPNode newArray = new XMPNode(currProp.getName(), arrayForm); |
| 233 |
currProp.setName(XMPConst.ARRAY_ITEM_NAME); |
| 234 |
newArray.addChild(currProp); |
| 235 |
dcSchema.replaceChild(i, newArray); |
| 236 |
|
| 237 |
|
| 238 |
if (arrayForm.isArrayAltText() && !currProp.getOptions().getHasLanguage()) |
| 239 |
{ |
| 240 |
XMPNode newLang = new XMPNode(XMPConst.XML_LANG, XMPConst.X_DEFAULT, null); |
| 241 |
currProp.addQualifier(newLang); |
| 242 |
} |
| 243 |
} |
| 244 |
else |
| 245 |
{ |
| 246 |
|
| 247 |
currProp.getOptions().setOption( |
| 248 |
PropertyOptions.ARRAY | |
| 249 |
PropertyOptions.ARRAY_ORDERED | |
| 250 |
PropertyOptions.ARRAY_ALTERNATE | |
| 251 |
PropertyOptions.ARRAY_ALT_TEXT, |
| 252 |
false); |
| 253 |
currProp.getOptions().mergeWith(arrayForm); |
| 254 |
|
| 255 |
if (arrayForm.isArrayAltText()) |
| 256 |
{ |
| 257 |
|
| 258 |
repairAltText(currProp); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
private static void repairAltText(XMPNode arrayNode) throws XMPException |
| 274 |
{ |
| 275 |
if (arrayNode == null || |
| 276 |
!arrayNode.getOptions().isArray()) |
| 277 |
{ |
| 278 |
|
| 279 |
return; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
arrayNode.getOptions().setArrayOrdered(true).setArrayAlternate(true).setArrayAltText(true); |
| 284 |
|
| 285 |
for (Iterator it = arrayNode.iterateChildren(); it.hasNext();) |
| 286 |
{ |
| 287 |
XMPNode currChild = (XMPNode) it.next(); |
| 288 |
if (currChild.getOptions().isCompositeProperty()) |
| 289 |
{ |
| 290 |
|
| 291 |
it.remove(); |
| 292 |
} |
| 293 |
else if (!currChild.getOptions().getHasLanguage()) |
| 294 |
{ |
| 295 |
String childValue = currChild.getValue(); |
| 296 |
if (childValue == null || childValue.length() == 0) |
| 297 |
{ |
| 298 |
|
| 299 |
it.remove(); |
| 300 |
} |
| 301 |
else |
| 302 |
{ |
| 303 |
|
| 304 |
XMPNode repairLang = new XMPNode(XMPConst.XML_LANG, "x-repair", null); |
| 305 |
currChild.addQualifier(repairLang); |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
private static void moveExplicitAliases(XMPNode tree, ParseOptions options) |
| 322 |
throws XMPException |
| 323 |
{ |
| 324 |
if (!tree.getHasAliases()) |
| 325 |
{ |
| 326 |
return; |
| 327 |
} |
| 328 |
tree.setHasAliases(false); |
| 329 |
|
| 330 |
boolean strictAliasing = options.getStrictAliasing(); |
| 331 |
|
| 332 |
for (Iterator schemaIt = tree.getUnmodifiableChildren().iterator(); schemaIt.hasNext();) |
| 333 |
{ |
| 334 |
XMPNode currSchema = (XMPNode) schemaIt.next(); |
| 335 |
if (!currSchema.getHasAliases()) |
| 336 |
{ |
| 337 |
continue; |
| 338 |
} |
| 339 |
|
| 340 |
for (Iterator propertyIt = currSchema.iterateChildren(); propertyIt.hasNext();) |
| 341 |
{ |
| 342 |
XMPNode currProp = (XMPNode) propertyIt.next(); |
| 343 |
|
| 344 |
if (!currProp.isAlias()) |
| 345 |
{ |
| 346 |
continue; |
| 347 |
} |
| 348 |
|
| 349 |
currProp.setAlias(false); |
| 350 |
|
| 351 |
|
| 352 |
XMPAliasInfo info = XMPMetaFactory.getSchemaRegistry() |
| 353 |
.findAlias(currProp.getName()); |
| 354 |
if (info != null) |
| 355 |
{ |
| 356 |
|
| 357 |
XMPNode baseSchema = XMPNodeUtils.findSchemaNode(tree, info |
| 358 |
.getNamespace(), null, true); |
| 359 |
baseSchema.setImplicit(false); |
| 360 |
|
| 361 |
XMPNode baseNode = XMPNodeUtils |
| 362 |
.findChildNode(baseSchema, |
| 363 |
info.getPrefix() + info.getPropName(), false); |
| 364 |
if (baseNode == null) |
| 365 |
{ |
| 366 |
if (info.getAliasForm().isSimple()) |
| 367 |
{ |
| 368 |
|
| 369 |
|
| 370 |
String qname = info.getPrefix() + info.getPropName(); |
| 371 |
currProp.setName(qname); |
| 372 |
baseSchema.addChild(currProp); |
| 373 |
|
| 374 |
propertyIt.remove(); |
| 375 |
} |
| 376 |
else |
| 377 |
{ |
| 378 |
|
| 379 |
|
| 380 |
baseNode = new XMPNode(info.getPrefix() + info.getPropName(), info |
| 381 |
.getAliasForm().toPropertyOptions()); |
| 382 |
baseSchema.addChild(baseNode); |
| 383 |
transplantArrayItemAlias (propertyIt, currProp, baseNode); |
| 384 |
} |
| 385 |
|
| 386 |
} |
| 387 |
else if (info.getAliasForm().isSimple()) |
| 388 |
{ |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
if (strictAliasing) |
| 393 |
{ |
| 394 |
compareAliasedSubtrees (currProp, baseNode, true); |
| 395 |
} |
| 396 |
|
| 397 |
propertyIt.remove(); |
| 398 |
} |
| 399 |
else |
| 400 |
{ |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
XMPNode itemNode = null; |
| 406 |
if (info.getAliasForm().isArrayAltText()) |
| 407 |
{ |
| 408 |
int xdIndex = XMPNodeUtils.lookupLanguageItem(baseNode, |
| 409 |
XMPConst.X_DEFAULT); |
| 410 |
if (xdIndex != -1) |
| 411 |
{ |
| 412 |
itemNode = baseNode.getChild(xdIndex); |
| 413 |
} |
| 414 |
} |
| 415 |
else if (baseNode.hasChildren()) |
| 416 |
{ |
| 417 |
itemNode = baseNode.getChild(1); |
| 418 |
} |
| 419 |
|
| 420 |
if (itemNode == null) |
| 421 |
{ |
| 422 |
transplantArrayItemAlias (propertyIt, currProp, baseNode); |
| 423 |
} |
| 424 |
else |
| 425 |
{ |
| 426 |
if (strictAliasing) |
| 427 |
{ |
| 428 |
compareAliasedSubtrees (currProp, itemNode, true); |
| 429 |
} |
| 430 |
|
| 431 |
propertyIt.remove(); |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
currSchema.setHasAliases(false); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
private static void transplantArrayItemAlias(Iterator propertyIt, XMPNode childNode, |
| 449 |
XMPNode baseArray) throws XMPException |
| 450 |
{ |
| 451 |
if (baseArray.getOptions().isArrayAltText()) |
| 452 |
{ |
| 453 |
if (childNode.getOptions().getHasLanguage()) |
| 454 |
{ |
| 455 |
|
| 456 |
throw new XMPException("Alias to x-default already has a language qualifier", |
| 457 |
XMPError.BADXMP); |
| 458 |
} |
| 459 |
|
| 460 |
XMPNode langQual = new XMPNode(XMPConst.XML_LANG, XMPConst.X_DEFAULT, null); |
| 461 |
childNode.addQualifier(langQual); |
| 462 |
} |
| 463 |
|
| 464 |
propertyIt.remove(); |
| 465 |
childNode.setName(XMPConst.ARRAY_ITEM_NAME); |
| 466 |
baseArray.addChild(childNode); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
private static void fixGPSTimeStamp(XMPNode exifSchema) |
| 476 |
throws XMPException |
| 477 |
{ |
| 478 |
|
| 479 |
|
| 480 |
XMPNode gpsDateTime = XMPNodeUtils.findChildNode(exifSchema, "exif:GPSTimeStamp", false); |
| 481 |
if (gpsDateTime == null) |
| 482 |
{ |
| 483 |
return; |
| 484 |
} |
| 485 |
|
| 486 |
try |
| 487 |
{ |
| 488 |
XMPDateTime binGPSStamp; |
| 489 |
XMPDateTime binOtherDate; |
| 490 |
|
| 491 |
binGPSStamp = XMPUtils.convertToDate(gpsDateTime.getValue()); |
| 492 |
if (binGPSStamp.getYear() != 0 || |
| 493 |
binGPSStamp.getMonth() != 0 || |
| 494 |
binGPSStamp.getDay() != 0) |
| 495 |
{ |
| 496 |
return; |
| 497 |
} |
| 498 |
|
| 499 |
XMPNode otherDate = XMPNodeUtils.findChildNode(exifSchema, "exif:DateTimeOriginal", |
| 500 |
false); |
| 501 |
if (otherDate == null) |
| 502 |
{ |
| 503 |
otherDate = XMPNodeUtils.findChildNode(exifSchema, "exif:DateTimeDigitized", false); |
| 504 |
} |
| 505 |
if(otherDate == null) |
| 506 |
return; |
| 507 |
|
| 508 |
binOtherDate = XMPUtils.convertToDate(otherDate.getValue()); |
| 509 |
Calendar cal = binGPSStamp.getCalendar(); |
| 510 |
cal.set(Calendar.YEAR, binOtherDate.getYear()); |
| 511 |
cal.set(Calendar.MONTH, binOtherDate.getMonth()); |
| 512 |
cal.set(Calendar.DAY_OF_MONTH, binOtherDate.getDay()); |
| 513 |
binGPSStamp = new XMPDateTimeImpl(cal); |
| 514 |
gpsDateTime.setValue(XMPUtils.convertFromDate (binGPSStamp)); |
| 515 |
} |
| 516 |
catch (XMPException e) |
| 517 |
{ |
| 518 |
|
| 519 |
return; |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
private static void deleteEmptySchemas(XMPNode tree) |
| 530 |
{ |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
for (Iterator it = tree.iterateChildren(); it.hasNext();) |
| 535 |
{ |
| 536 |
XMPNode schema = (XMPNode) it.next(); |
| 537 |
if (!schema.hasChildren()) |
| 538 |
{ |
| 539 |
it.remove(); |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
private static void compareAliasedSubtrees(XMPNode aliasNode, XMPNode baseNode, |
| 556 |
boolean outerCall) throws XMPException |
| 557 |
{ |
| 558 |
if (!aliasNode.getValue().equals(baseNode.getValue()) || |
| 559 |
aliasNode.getChildrenLength() != baseNode.getChildrenLength()) |
| 560 |
{ |
| 561 |
throw new XMPException("Mismatch between alias and base nodes", XMPError.BADXMP); |
| 562 |
} |
| 563 |
|
| 564 |
if ( |
| 565 |
!outerCall && |
| 566 |
(!aliasNode.getName().equals(baseNode.getName()) || |
| 567 |
!aliasNode.getOptions().equals(baseNode.getOptions()) || |
| 568 |
aliasNode.getQualifierLength() != baseNode.getQualifierLength()) |
| 569 |
) |
| 570 |
{ |
| 571 |
throw new XMPException("Mismatch between alias and base nodes", |
| 572 |
XMPError.BADXMP); |
| 573 |
} |
| 574 |
|
| 575 |
for (Iterator an = aliasNode.iterateChildren(), |
| 576 |
bn = baseNode.iterateChildren(); |
| 577 |
an.hasNext() && bn.hasNext();) |
| 578 |
{ |
| 579 |
XMPNode aliasChild = (XMPNode) an.next(); |
| 580 |
XMPNode baseChild = (XMPNode) bn.next(); |
| 581 |
compareAliasedSubtrees (aliasChild, baseChild, false); |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
for (Iterator an = aliasNode.iterateQualifier(), |
| 586 |
bn = baseNode.iterateQualifier(); |
| 587 |
an.hasNext() && bn.hasNext();) |
| 588 |
{ |
| 589 |
XMPNode aliasQual = (XMPNode) an.next(); |
| 590 |
XMPNode baseQual = (XMPNode) bn.next(); |
| 591 |
compareAliasedSubtrees (aliasQual, baseQual, false); |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
private static void migrateAudioCopyright (XMPMeta xmp, XMPNode dmCopyright) |
| 625 |
{ |
| 626 |
try |
| 627 |
{ |
| 628 |
XMPNode dcSchema = XMPNodeUtils.findSchemaNode( |
| 629 |
((XMPMetaImpl) xmp).getRoot(), XMPConst.NS_DC, true); |
| 630 |
|
| 631 |
String dmValue = dmCopyright.getValue(); |
| 632 |
String doubleLF = "\n\n"; |
| 633 |
|
| 634 |
XMPNode dcRightsArray = XMPNodeUtils.findChildNode (dcSchema, "dc:rights", false); |
| 635 |
|
| 636 |
if (dcRightsArray == null || !dcRightsArray.hasChildren()) |
| 637 |
{ |
| 638 |
|
| 639 |
dmValue = doubleLF + dmValue; |
| 640 |
xmp.setLocalizedText(XMPConst.NS_DC, "rights", "", XMPConst.X_DEFAULT, dmValue, |
| 641 |
null); |
| 642 |
} |
| 643 |
else |
| 644 |
{ |
| 645 |
int xdIndex = XMPNodeUtils.lookupLanguageItem(dcRightsArray, XMPConst.X_DEFAULT); |
| 646 |
|
| 647 |
if (xdIndex < 0) |
| 648 |
{ |
| 649 |
|
| 650 |
String firstValue = dcRightsArray.getChild(1).getValue(); |
| 651 |
xmp.setLocalizedText (XMPConst.NS_DC, "rights", "", XMPConst.X_DEFAULT, |
| 652 |
firstValue, null); |
| 653 |
xdIndex = XMPNodeUtils.lookupLanguageItem(dcRightsArray, XMPConst.X_DEFAULT); |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
XMPNode defaultNode = dcRightsArray.getChild(xdIndex); |
| 658 |
String defaultValue = defaultNode.getValue(); |
| 659 |
int lfPos = defaultValue.indexOf(doubleLF); |
| 660 |
|
| 661 |
if (lfPos < 0) |
| 662 |
{ |
| 663 |
|
| 664 |
if (!dmValue.equals(defaultValue)) |
| 665 |
{ |
| 666 |
|
| 667 |
|
| 668 |
defaultNode.setValue(defaultValue + doubleLF + dmValue); |
| 669 |
} |
| 670 |
} |
| 671 |
else |
| 672 |
{ |
| 673 |
|
| 674 |
if (!defaultValue.substring(lfPos + 2).equals(dmValue)) |
| 675 |
{ |
| 676 |
|
| 677 |
defaultNode.setValue(defaultValue.substring(0, lfPos + 2) + dmValue); |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
dmCopyright.getParent().removeChild(dmCopyright); |
| 685 |
} |
| 686 |
catch (XMPException e) |
| 687 |
{ |
| 688 |
|
| 689 |
|
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
private static void initDCArrays() |
| 699 |
{ |
| 700 |
dcArrayForms = new HashMap(); |
| 701 |
|
| 702 |
|
| 703 |
PropertyOptions bagForm = new PropertyOptions(); |
| 704 |
bagForm.setArray(true); |
| 705 |
dcArrayForms.put("dc:contributor", bagForm); |
| 706 |
dcArrayForms.put("dc:language", bagForm); |
| 707 |
dcArrayForms.put("dc:publisher", bagForm); |
| 708 |
dcArrayForms.put("dc:relation", bagForm); |
| 709 |
dcArrayForms.put("dc:subject", bagForm); |
| 710 |
dcArrayForms.put("dc:type", bagForm); |
| 711 |
|
| 712 |
|
| 713 |
PropertyOptions seqForm = new PropertyOptions(); |
| 714 |
seqForm.setArray(true); |
| 715 |
seqForm.setArrayOrdered(true); |
| 716 |
dcArrayForms.put("dc:creator", seqForm); |
| 717 |
dcArrayForms.put("dc:date", seqForm); |
| 718 |
|
| 719 |
|
| 720 |
PropertyOptions altTextForm = new PropertyOptions(); |
| 721 |
altTextForm.setArray(true); |
| 722 |
altTextForm.setArrayOrdered(true); |
| 723 |
altTextForm.setArrayAlternate(true); |
| 724 |
altTextForm.setArrayAltText(true); |
| 725 |
dcArrayForms.put("dc:description", altTextForm); |
| 726 |
dcArrayForms.put("dc:rights", altTextForm); |
| 727 |
dcArrayForms.put("dc:title", altTextForm); |
| 728 |
} |
| 729 |
} |