| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
package com.adobe.internal.xmp.impl; |
| 11 |
|
| 12 |
import java.util.Calendar; |
| 13 |
import java.util.Iterator; |
| 14 |
|
| 15 |
import com.adobe.internal.xmp.XMPConst; |
| 16 |
import com.adobe.internal.xmp.XMPDateTime; |
| 17 |
import com.adobe.internal.xmp.XMPError; |
| 18 |
import com.adobe.internal.xmp.XMPException; |
| 19 |
import com.adobe.internal.xmp.XMPIterator; |
| 20 |
import com.adobe.internal.xmp.XMPMeta; |
| 21 |
import com.adobe.internal.xmp.XMPPathFactory; |
| 22 |
import com.adobe.internal.xmp.XMPUtils; |
| 23 |
import com.adobe.internal.xmp.impl.xpath.XMPPath; |
| 24 |
import com.adobe.internal.xmp.impl.xpath.XMPPathParser; |
| 25 |
import com.adobe.internal.xmp.options.IteratorOptions; |
| 26 |
import com.adobe.internal.xmp.options.ParseOptions; |
| 27 |
import com.adobe.internal.xmp.options.PropertyOptions; |
| 28 |
import com.adobe.internal.xmp.properties.XMPProperty; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class XMPMetaImpl implements XMPMeta, XMPConst |
| 39 |
{ |
| 40 |
|
| 41 |
private static final int VALUE_STRING = 0; |
| 42 |
|
| 43 |
private static final int VALUE_BOOLEAN = 1; |
| 44 |
|
| 45 |
private static final int VALUE_INTEGER = 2; |
| 46 |
|
| 47 |
private static final int VALUE_LONG = 3; |
| 48 |
|
| 49 |
private static final int VALUE_DOUBLE = 4; |
| 50 |
|
| 51 |
private static final int VALUE_DATE = 5; |
| 52 |
|
| 53 |
private static final int VALUE_CALENDAR = 6; |
| 54 |
|
| 55 |
private static final int VALUE_BASE64 = 7; |
| 56 |
|
| 57 |
|
| 58 |
private XMPNode tree; |
| 59 |
|
| 60 |
private String packetHeader = null; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public XMPMetaImpl() |
| 67 |
{ |
| 68 |
|
| 69 |
tree = new XMPNode(null, null, null); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public XMPMetaImpl(XMPNode tree) |
| 81 |
{ |
| 82 |
this.tree = tree; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public void appendArrayItem(String schemaNS, String arrayName, PropertyOptions arrayOptions, |
| 91 |
String itemValue, PropertyOptions itemOptions) throws XMPException |
| 92 |
{ |
| 93 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 94 |
ParameterAsserts.assertArrayName(arrayName); |
| 95 |
|
| 96 |
if (arrayOptions == null) |
| 97 |
{ |
| 98 |
arrayOptions = new PropertyOptions(); |
| 99 |
} |
| 100 |
if (!arrayOptions.isOnlyArrayOptions()) |
| 101 |
{ |
| 102 |
throw new XMPException("Only array form flags allowed for arrayOptions", |
| 103 |
XMPError.BADOPTIONS); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
arrayOptions = XMPNodeUtils.verifySetOptions(arrayOptions, null); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null); |
| 119 |
|
| 120 |
if (arrayNode != null) |
| 121 |
{ |
| 122 |
|
| 123 |
|
| 124 |
if (!arrayNode.getOptions().isArray()) |
| 125 |
{ |
| 126 |
throw new XMPException("The named property is not an array", XMPError.BADXPATH); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
else |
| 136 |
{ |
| 137 |
|
| 138 |
if (arrayOptions.isArray()) |
| 139 |
{ |
| 140 |
|
| 141 |
arrayNode = XMPNodeUtils.findNode(tree, arrayPath, true, arrayOptions); |
| 142 |
if (arrayNode == null) |
| 143 |
{ |
| 144 |
throw new XMPException("Failure creating array node", XMPError.BADXPATH); |
| 145 |
} |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
|
| 150 |
throw new XMPException("Explicit arrayOptions required to create new array", |
| 151 |
XMPError.BADOPTIONS); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
doSetArrayItem(arrayNode, ARRAY_LAST_ITEM, itemValue, itemOptions, true); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public void appendArrayItem(String schemaNS, String arrayName, String itemValue) |
| 163 |
throws XMPException |
| 164 |
{ |
| 165 |
appendArrayItem(schemaNS, arrayName, null, itemValue, null); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public int countArrayItems(String schemaNS, String arrayName) throws XMPException |
| 174 |
{ |
| 175 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 176 |
ParameterAsserts.assertArrayName(arrayName); |
| 177 |
|
| 178 |
XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName); |
| 179 |
XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null); |
| 180 |
|
| 181 |
if (arrayNode == null) |
| 182 |
{ |
| 183 |
return 0; |
| 184 |
} |
| 185 |
|
| 186 |
if (arrayNode.getOptions().isArray()) |
| 187 |
{ |
| 188 |
return arrayNode.getChildrenLength(); |
| 189 |
} |
| 190 |
else |
| 191 |
{ |
| 192 |
throw new XMPException("The named property is not an array", XMPError.BADXPATH); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public void deleteArrayItem(String schemaNS, String arrayName, int itemIndex) |
| 201 |
{ |
| 202 |
try |
| 203 |
{ |
| 204 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 205 |
ParameterAsserts.assertArrayName(arrayName); |
| 206 |
|
| 207 |
String itemPath = XMPPathFactory.composeArrayItemPath(arrayName, itemIndex); |
| 208 |
deleteProperty(schemaNS, itemPath); |
| 209 |
} |
| 210 |
catch (XMPException e) |
| 211 |
{ |
| 212 |
|
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public void deleteProperty(String schemaNS, String propName) |
| 221 |
{ |
| 222 |
try |
| 223 |
{ |
| 224 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 225 |
ParameterAsserts.assertPropName(propName); |
| 226 |
|
| 227 |
XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName); |
| 228 |
|
| 229 |
XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, false, null); |
| 230 |
if (propNode != null) |
| 231 |
{ |
| 232 |
XMPNodeUtils.deleteNode(propNode); |
| 233 |
} |
| 234 |
} |
| 235 |
catch (XMPException e) |
| 236 |
{ |
| 237 |
|
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
public void deleteQualifier(String schemaNS, String propName, String qualNS, String qualName) |
| 246 |
{ |
| 247 |
try |
| 248 |
{ |
| 249 |
|
| 250 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 251 |
ParameterAsserts.assertPropName(propName); |
| 252 |
|
| 253 |
String qualPath = propName + XMPPathFactory.composeQualifierPath(qualNS, qualName); |
| 254 |
deleteProperty(schemaNS, qualPath); |
| 255 |
} |
| 256 |
catch (XMPException e) |
| 257 |
{ |
| 258 |
|
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
public void deleteStructField(String schemaNS, String structName, String fieldNS, |
| 267 |
String fieldName) |
| 268 |
{ |
| 269 |
try |
| 270 |
{ |
| 271 |
|
| 272 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 273 |
ParameterAsserts.assertStructName(structName); |
| 274 |
|
| 275 |
String fieldPath = structName |
| 276 |
+ XMPPathFactory.composeStructFieldPath(fieldNS, fieldName); |
| 277 |
deleteProperty(schemaNS, fieldPath); |
| 278 |
} |
| 279 |
catch (XMPException e) |
| 280 |
{ |
| 281 |
|
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
public boolean doesPropertyExist(String schemaNS, String propName) |
| 290 |
{ |
| 291 |
try |
| 292 |
{ |
| 293 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 294 |
ParameterAsserts.assertPropName(propName); |
| 295 |
|
| 296 |
XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName); |
| 297 |
final XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, false, null); |
| 298 |
return propNode != null; |
| 299 |
} |
| 300 |
catch (XMPException e) |
| 301 |
{ |
| 302 |
return false; |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public boolean doesArrayItemExist(String schemaNS, String arrayName, int itemIndex) |
| 311 |
{ |
| 312 |
try |
| 313 |
{ |
| 314 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 315 |
ParameterAsserts.assertArrayName(arrayName); |
| 316 |
|
| 317 |
String path = XMPPathFactory.composeArrayItemPath(arrayName, itemIndex); |
| 318 |
return doesPropertyExist(schemaNS, path); |
| 319 |
} |
| 320 |
catch (XMPException e) |
| 321 |
{ |
| 322 |
return false; |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
public boolean doesStructFieldExist(String schemaNS, String structName, String fieldNS, |
| 331 |
String fieldName) |
| 332 |
{ |
| 333 |
try |
| 334 |
{ |
| 335 |
|
| 336 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 337 |
ParameterAsserts.assertStructName(structName); |
| 338 |
|
| 339 |
String path = XMPPathFactory.composeStructFieldPath(fieldNS, fieldName); |
| 340 |
return doesPropertyExist(schemaNS, structName + path); |
| 341 |
} |
| 342 |
catch (XMPException e) |
| 343 |
{ |
| 344 |
return false; |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
public boolean doesQualifierExist(String schemaNS, String propName, String qualNS, |
| 353 |
String qualName) |
| 354 |
{ |
| 355 |
try |
| 356 |
{ |
| 357 |
|
| 358 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 359 |
ParameterAsserts.assertPropName(propName); |
| 360 |
|
| 361 |
String path = XMPPathFactory.composeQualifierPath(qualNS, qualName); |
| 362 |
return doesPropertyExist(schemaNS, propName + path); |
| 363 |
} |
| 364 |
catch (XMPException e) |
| 365 |
{ |
| 366 |
return false; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
public XMPProperty getArrayItem(String schemaNS, String arrayName, int itemIndex) |
| 375 |
throws XMPException |
| 376 |
{ |
| 377 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 378 |
ParameterAsserts.assertArrayName(arrayName); |
| 379 |
|
| 380 |
String itemPath = XMPPathFactory.composeArrayItemPath(arrayName, itemIndex); |
| 381 |
return getProperty(schemaNS, itemPath); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
public XMPProperty getLocalizedText(String schemaNS, String altTextName, String genericLang, |
| 390 |
String specificLang) throws XMPException |
| 391 |
{ |
| 392 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 393 |
ParameterAsserts.assertArrayName(altTextName); |
| 394 |
ParameterAsserts.assertSpecificLang(specificLang); |
| 395 |
|
| 396 |
genericLang = genericLang != null ? Utils.normalizeLangValue(genericLang) : null; |
| 397 |
specificLang = Utils.normalizeLangValue(specificLang); |
| 398 |
|
| 399 |
XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, altTextName); |
| 400 |
|
| 401 |
XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null); |
| 402 |
if (arrayNode == null) |
| 403 |
{ |
| 404 |
return null; |
| 405 |
} |
| 406 |
|
| 407 |
Object[] result = XMPNodeUtils.chooseLocalizedText(arrayNode, genericLang, specificLang); |
| 408 |
int match = ((Integer) result[0]).intValue(); |
| 409 |
final XMPNode itemNode = (XMPNode) result[1]; |
| 410 |
|
| 411 |
if (match != XMPNodeUtils.CLT_NO_VALUES) |
| 412 |
{ |
| 413 |
return new XMPProperty() |
| 414 |
{ |
| 415 |
public String getValue() |
| 416 |
{ |
| 417 |
return itemNode.getValue(); |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
public PropertyOptions getOptions() |
| 422 |
{ |
| 423 |
return itemNode.getOptions(); |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
public String getLanguage() |
| 428 |
{ |
| 429 |
return itemNode.getQualifier(1).getValue(); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
public String toString() |
| 434 |
{ |
| 435 |
return itemNode.getValue().toString(); |
| 436 |
} |
| 437 |
}; |
| 438 |
} |
| 439 |
else |
| 440 |
{ |
| 441 |
return null; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
public void setLocalizedText(String schemaNS, String altTextName, String genericLang, |
| 451 |
String specificLang, String itemValue, PropertyOptions options) throws XMPException |
| 452 |
{ |
| 453 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 454 |
ParameterAsserts.assertArrayName(altTextName); |
| 455 |
ParameterAsserts.assertSpecificLang(specificLang); |
| 456 |
|
| 457 |
genericLang = genericLang != null ? Utils.normalizeLangValue(genericLang) : null; |
| 458 |
specificLang = Utils.normalizeLangValue(specificLang); |
| 459 |
|
| 460 |
XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, altTextName); |
| 461 |
|
| 462 |
|
| 463 |
XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, true, new PropertyOptions( |
| 464 |
PropertyOptions.ARRAY | PropertyOptions.ARRAY_ORDERED |
| 465 |
| PropertyOptions.ARRAY_ALTERNATE | PropertyOptions.ARRAY_ALT_TEXT)); |
| 466 |
|
| 467 |
if (arrayNode == null) |
| 468 |
{ |
| 469 |
throw new XMPException("Failed to find or create array node", XMPError.BADXPATH); |
| 470 |
} |
| 471 |
else if (!arrayNode.getOptions().isArrayAltText()) |
| 472 |
{ |
| 473 |
if (!arrayNode.hasChildren() && arrayNode.getOptions().isArrayAlternate()) |
| 474 |
{ |
| 475 |
arrayNode.getOptions().setArrayAltText(true); |
| 476 |
} |
| 477 |
else |
| 478 |
{ |
| 479 |
throw new XMPException( |
| 480 |
"Specified property is no alt-text array", XMPError.BADXPATH); |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
boolean haveXDefault = false; |
| 486 |
XMPNode xdItem = null; |
| 487 |
|
| 488 |
for (Iterator it = arrayNode.iterateChildren(); it.hasNext();) |
| 489 |
{ |
| 490 |
XMPNode currItem = (XMPNode) it.next(); |
| 491 |
if (!currItem.hasQualifier() |
| 492 |
|| !XMPConst.XML_LANG.equals(currItem.getQualifier(1).getName())) |
| 493 |
{ |
| 494 |
throw new XMPException("Language qualifier must be first", XMPError.BADXPATH); |
| 495 |
} |
| 496 |
else if (XMPConst.X_DEFAULT.equals(currItem.getQualifier(1).getValue())) |
| 497 |
{ |
| 498 |
xdItem = currItem; |
| 499 |
haveXDefault = true; |
| 500 |
break; |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
if (xdItem != null && arrayNode.getChildrenLength() > 1) |
| 506 |
{ |
| 507 |
arrayNode.removeChild(xdItem); |
| 508 |
arrayNode.addChild(1, xdItem); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
Object[] result = XMPNodeUtils.chooseLocalizedText(arrayNode, genericLang, specificLang); |
| 515 |
int match = ((Integer) result[0]).intValue(); |
| 516 |
XMPNode itemNode = (XMPNode) result[1]; |
| 517 |
|
| 518 |
boolean specificXDefault = XMPConst.X_DEFAULT.equals(specificLang); |
| 519 |
|
| 520 |
switch (match) |
| 521 |
{ |
| 522 |
case XMPNodeUtils.CLT_NO_VALUES: |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
XMPNodeUtils.appendLangItem(arrayNode, XMPConst.X_DEFAULT, itemValue); |
| 527 |
haveXDefault = true; |
| 528 |
if (!specificXDefault) |
| 529 |
{ |
| 530 |
XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue); |
| 531 |
} |
| 532 |
break; |
| 533 |
|
| 534 |
case XMPNodeUtils.CLT_SPECIFIC_MATCH: |
| 535 |
|
| 536 |
if (!specificXDefault) |
| 537 |
{ |
| 538 |
|
| 539 |
|
| 540 |
if (haveXDefault && xdItem != itemNode && xdItem != null |
| 541 |
&& xdItem.getValue().equals(itemNode.getValue())) |
| 542 |
{ |
| 543 |
xdItem.setValue(itemValue); |
| 544 |
} |
| 545 |
|
| 546 |
itemNode.setValue(itemValue); |
| 547 |
} |
| 548 |
else |
| 549 |
{ |
| 550 |
|
| 551 |
assert haveXDefault && xdItem == itemNode; |
| 552 |
for (Iterator it = arrayNode.iterateChildren(); it.hasNext();) |
| 553 |
{ |
| 554 |
XMPNode currItem = (XMPNode) it.next(); |
| 555 |
if (currItem == xdItem |
| 556 |
|| !currItem.getValue().equals( |
| 557 |
xdItem != null ? xdItem.getValue() : null)) |
| 558 |
{ |
| 559 |
continue; |
| 560 |
} |
| 561 |
currItem.setValue(itemValue); |
| 562 |
} |
| 563 |
|
| 564 |
if (xdItem != null) |
| 565 |
{ |
| 566 |
xdItem.setValue(itemValue); |
| 567 |
} |
| 568 |
} |
| 569 |
break; |
| 570 |
|
| 571 |
case XMPNodeUtils.CLT_SINGLE_GENERIC: |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
if (haveXDefault && xdItem != itemNode && xdItem != null |
| 576 |
&& xdItem.getValue().equals(itemNode.getValue())) |
| 577 |
{ |
| 578 |
xdItem.setValue(itemValue); |
| 579 |
} |
| 580 |
itemNode.setValue(itemValue); |
| 581 |
|
| 582 |
|
| 583 |
break; |
| 584 |
|
| 585 |
case XMPNodeUtils.CLT_MULTIPLE_GENERIC: |
| 586 |
|
| 587 |
|
| 588 |
XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue); |
| 589 |
if (specificXDefault) |
| 590 |
{ |
| 591 |
haveXDefault = true; |
| 592 |
} |
| 593 |
break; |
| 594 |
|
| 595 |
case XMPNodeUtils.CLT_XDEFAULT: |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
if (xdItem != null && arrayNode.getChildrenLength() == 1) |
| 600 |
{ |
| 601 |
xdItem.setValue(itemValue); |
| 602 |
} |
| 603 |
XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue); |
| 604 |
break; |
| 605 |
|
| 606 |
case XMPNodeUtils.CLT_FIRST_ITEM: |
| 607 |
|
| 608 |
|
| 609 |
XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue); |
| 610 |
if (specificXDefault) |
| 611 |
{ |
| 612 |
haveXDefault = true; |
| 613 |
} |
| 614 |
break; |
| 615 |
|
| 616 |
default: |
| 617 |
|
| 618 |
throw new XMPException("Unexpected result from ChooseLocalizedText", |
| 619 |
XMPError.INTERNALFAILURE); |
| 620 |
|
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
if (!haveXDefault && arrayNode.getChildrenLength() == 1) |
| 625 |
{ |
| 626 |
XMPNodeUtils.appendLangItem(arrayNode, XMPConst.X_DEFAULT, itemValue); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
public void setLocalizedText(String schemaNS, String altTextName, String genericLang, |
| 635 |
String specificLang, String itemValue) throws XMPException |
| 636 |
{ |
| 637 |
setLocalizedText(schemaNS, altTextName, genericLang, specificLang, itemValue, null); |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
public XMPProperty getProperty(String schemaNS, String propName) throws XMPException |
| 646 |
{ |
| 647 |
return getProperty(schemaNS, propName, VALUE_STRING); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
protected XMPProperty getProperty(String schemaNS, String propName, int valueType) |
| 670 |
throws XMPException |
| 671 |
{ |
| 672 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 673 |
ParameterAsserts.assertPropName(propName); |
| 674 |
|
| 675 |
final XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName); |
| 676 |
final XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, false, null); |
| 677 |
|
| 678 |
if (propNode != null) |
| 679 |
{ |
| 680 |
if (valueType != VALUE_STRING && propNode.getOptions().isCompositeProperty()) |
| 681 |
{ |
| 682 |
throw new XMPException("Property must be simple when a value type is requested", |
| 683 |
XMPError.BADXPATH); |
| 684 |
} |
| 685 |
|
| 686 |
final Object value = evaluateNodeValue(valueType, propNode); |
| 687 |
|
| 688 |
return new XMPProperty() |
| 689 |
{ |
| 690 |
public String getValue() |
| 691 |
{ |
| 692 |
return value != null ? value.toString() : null; |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
public PropertyOptions getOptions() |
| 697 |
{ |
| 698 |
return propNode.getOptions(); |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
public String getLanguage() |
| 703 |
{ |
| 704 |
return null; |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
public String toString() |
| 709 |
{ |
| 710 |
return value.toString(); |
| 711 |
} |
| 712 |
}; |
| 713 |
} |
| 714 |
else |
| 715 |
{ |
| 716 |
return null; |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
protected Object getPropertyObject(String schemaNS, String propName, int valueType) |
| 737 |
throws XMPException |
| 738 |
{ |
| 739 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 740 |
ParameterAsserts.assertPropName(propName); |
| 741 |
|
| 742 |
final XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName); |
| 743 |
final XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, false, null); |
| 744 |
|
| 745 |
if (propNode != null) |
| 746 |
{ |
| 747 |
if (valueType != VALUE_STRING && propNode.getOptions().isCompositeProperty()) |
| 748 |
{ |
| 749 |
throw new XMPException("Property must be simple when a value type is requested", |
| 750 |
XMPError.BADXPATH); |
| 751 |
} |
| 752 |
|
| 753 |
return evaluateNodeValue(valueType, propNode); |
| 754 |
} |
| 755 |
else |
| 756 |
{ |
| 757 |
return null; |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
public Boolean getPropertyBoolean(String schemaNS, String propName) throws XMPException |
| 766 |
{ |
| 767 |
return (Boolean) getPropertyObject(schemaNS, propName, VALUE_BOOLEAN); |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
public void setPropertyBoolean(String schemaNS, String propName, boolean propValue, |
| 776 |
PropertyOptions options) throws XMPException |
| 777 |
{ |
| 778 |
setProperty(schemaNS, propName, propValue ? TRUESTR : FALSESTR, options); |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
public void setPropertyBoolean(String schemaNS, String propName, boolean propValue) |
| 786 |
throws XMPException |
| 787 |
{ |
| 788 |
setProperty(schemaNS, propName, propValue ? TRUESTR : FALSESTR, null); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
public Integer getPropertyInteger(String schemaNS, String propName) throws XMPException |
| 796 |
{ |
| 797 |
return (Integer) getPropertyObject(schemaNS, propName, VALUE_INTEGER); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
public void setPropertyInteger(String schemaNS, String propName, int propValue, |
| 805 |
PropertyOptions options) throws XMPException |
| 806 |
{ |
| 807 |
setProperty(schemaNS, propName, new Integer(propValue), options); |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
public void setPropertyInteger(String schemaNS, String propName, int propValue) |
| 815 |
throws XMPException |
| 816 |
{ |
| 817 |
setProperty(schemaNS, propName, new Integer(propValue), null); |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
public Long getPropertyLong(String schemaNS, String propName) throws XMPException |
| 825 |
{ |
| 826 |
return (Long) getPropertyObject(schemaNS, propName, VALUE_LONG); |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
public void setPropertyLong(String schemaNS, String propName, long propValue, |
| 834 |
PropertyOptions options) throws XMPException |
| 835 |
{ |
| 836 |
setProperty(schemaNS, propName, new Long(propValue), options); |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
public void setPropertyLong(String schemaNS, String propName, long propValue) |
| 844 |
throws XMPException |
| 845 |
{ |
| 846 |
setProperty(schemaNS, propName, new Long(propValue), null); |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
public Double getPropertyDouble(String schemaNS, String propName) throws XMPException |
| 854 |
{ |
| 855 |
return (Double) getPropertyObject(schemaNS, propName, VALUE_DOUBLE); |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
public void setPropertyDouble(String schemaNS, String propName, double propValue, |
| 863 |
PropertyOptions options) throws XMPException |
| 864 |
{ |
| 865 |
setProperty(schemaNS, propName, new Double(propValue), options); |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
public void setPropertyDouble(String schemaNS, String propName, double propValue) |
| 873 |
throws XMPException |
| 874 |
{ |
| 875 |
setProperty(schemaNS, propName, new Double(propValue), null); |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
public XMPDateTime getPropertyDate(String schemaNS, String propName) throws XMPException |
| 883 |
{ |
| 884 |
return (XMPDateTime) getPropertyObject(schemaNS, propName, VALUE_DATE); |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
public void setPropertyDate(String schemaNS, String propName, XMPDateTime propValue, |
| 893 |
PropertyOptions options) throws XMPException |
| 894 |
{ |
| 895 |
setProperty(schemaNS, propName, propValue, options); |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
public void setPropertyDate(String schemaNS, String propName, XMPDateTime propValue) |
| 903 |
throws XMPException |
| 904 |
{ |
| 905 |
setProperty(schemaNS, propName, propValue, null); |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
public Calendar getPropertyCalendar(String schemaNS, String propName) throws XMPException |
| 913 |
{ |
| 914 |
return (Calendar) getPropertyObject(schemaNS, propName, VALUE_CALENDAR); |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
public void setPropertyCalendar(String schemaNS, String propName, Calendar propValue, |
| 923 |
PropertyOptions options) throws XMPException |
| 924 |
{ |
| 925 |
setProperty(schemaNS, propName, propValue, options); |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
public void setPropertyCalendar(String schemaNS, String propName, Calendar propValue) |
| 933 |
throws XMPException |
| 934 |
{ |
| 935 |
setProperty(schemaNS, propName, propValue, null); |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
public byte[] getPropertyBase64(String schemaNS, String propName) throws XMPException |
| 943 |
{ |
| 944 |
return (byte[]) getPropertyObject(schemaNS, propName, VALUE_BASE64); |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
public String getPropertyString(String schemaNS, String propName) throws XMPException |
| 952 |
{ |
| 953 |
return (String) getPropertyObject(schemaNS, propName, VALUE_STRING); |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
public void setPropertyBase64(String schemaNS, String propName, byte[] propValue, |
| 961 |
PropertyOptions options) throws XMPException |
| 962 |
{ |
| 963 |
setProperty(schemaNS, propName, propValue, options); |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
public void setPropertyBase64(String schemaNS, String propName, byte[] propValue) |
| 971 |
throws XMPException |
| 972 |
{ |
| 973 |
setProperty(schemaNS, propName, propValue, null); |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
public XMPProperty getQualifier(String schemaNS, String propName, String qualNS, |
| 982 |
String qualName) throws XMPException |
| 983 |
{ |
| 984 |
|
| 985 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 986 |
ParameterAsserts.assertPropName(propName); |
| 987 |
|
| 988 |
String qualPath = propName + XMPPathFactory.composeQualifierPath(qualNS, qualName); |
| 989 |
return getProperty(schemaNS, qualPath); |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
public XMPProperty getStructField(String schemaNS, String structName, String fieldNS, |
| 997 |
String fieldName) throws XMPException |
| 998 |
{ |
| 999 |
|
| 1000 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 1001 |
ParameterAsserts.assertStructName(structName); |
| 1002 |
|
| 1003 |
String fieldPath = structName + XMPPathFactory.composeStructFieldPath(fieldNS, fieldName); |
| 1004 |
return getProperty(schemaNS, fieldPath); |
| 1005 |
} |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
public XMPIterator iterator() throws XMPException |
| 1013 |
{ |
| 1014 |
return iterator(null, null, null); |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
public XMPIterator iterator(IteratorOptions options) throws XMPException |
| 1022 |
{ |
| 1023 |
return iterator(null, null, options); |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
public XMPIterator iterator(String schemaNS, String propName, IteratorOptions options) |
| 1031 |
throws XMPException |
| 1032 |
{ |
| 1033 |
return new XMPIteratorImpl(this, schemaNS, propName, options); |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
public void setArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue, |
| 1042 |
PropertyOptions options) throws XMPException |
| 1043 |
{ |
| 1044 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 1045 |
ParameterAsserts.assertArrayName(arrayName); |
| 1046 |
|
| 1047 |
|
| 1048 |
XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName); |
| 1049 |
XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null); |
| 1050 |
|
| 1051 |
if (arrayNode != null) |
| 1052 |
{ |
| 1053 |
doSetArrayItem(arrayNode, itemIndex, itemValue, options, false); |
| 1054 |
} |
| 1055 |
else |
| 1056 |
{ |
| 1057 |
throw new XMPException("Specified array does not exist", XMPError.BADXPATH); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
public void setArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue) |
| 1066 |
throws XMPException |
| 1067 |
{ |
| 1068 |
setArrayItem(schemaNS, arrayName, itemIndex, itemValue, null); |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
public void insertArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue, |
| 1078 |
PropertyOptions options) throws XMPException |
| 1079 |
{ |
| 1080 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 1081 |
ParameterAsserts.assertArrayName(arrayName); |
| 1082 |
|
| 1083 |
|
| 1084 |
XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName); |
| 1085 |
XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null); |
| 1086 |
|
| 1087 |
if (arrayNode != null) |
| 1088 |
{ |
| 1089 |
doSetArrayItem(arrayNode, itemIndex, itemValue, options, true); |
| 1090 |
} |
| 1091 |
else |
| 1092 |
{ |
| 1093 |
throw new XMPException("Specified array does not exist", XMPError.BADXPATH); |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
public void insertArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue) |
| 1102 |
throws XMPException |
| 1103 |
{ |
| 1104 |
insertArrayItem(schemaNS, arrayName, itemIndex, itemValue, null); |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
public void setProperty(String schemaNS, String propName, Object propValue, |
| 1113 |
PropertyOptions options) throws XMPException |
| 1114 |
{ |
| 1115 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 1116 |
ParameterAsserts.assertPropName(propName); |
| 1117 |
|
| 1118 |
options = XMPNodeUtils.verifySetOptions(options, propValue); |
| 1119 |
|
| 1120 |
XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName); |
| 1121 |
|
| 1122 |
XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, true, options); |
| 1123 |
if (propNode != null) |
| 1124 |
{ |
| 1125 |
setNode(propNode, propValue, options, false); |
| 1126 |
} |
| 1127 |
else |
| 1128 |
{ |
| 1129 |
throw new XMPException("Specified property does not exist", XMPError.BADXPATH); |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
public void setProperty(String schemaNS, String propName, Object propValue) throws XMPException |
| 1138 |
{ |
| 1139 |
setProperty(schemaNS, propName, propValue, null); |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
public void setQualifier(String schemaNS, String propName, String qualNS, String qualName, |
| 1149 |
String qualValue, PropertyOptions options) throws XMPException |
| 1150 |
{ |
| 1151 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 1152 |
ParameterAsserts.assertPropName(propName); |
| 1153 |
|
| 1154 |
if (!doesPropertyExist(schemaNS, propName)) |
| 1155 |
{ |
| 1156 |
throw new XMPException("Specified property does not exist!", XMPError.BADXPATH); |
| 1157 |
} |
| 1158 |
|
| 1159 |
String qualPath = propName + XMPPathFactory.composeQualifierPath(qualNS, qualName); |
| 1160 |
setProperty(schemaNS, qualPath, qualValue, options); |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
public void setQualifier(String schemaNS, String propName, String qualNS, String qualName, |
| 1168 |
String qualValue) throws XMPException |
| 1169 |
{ |
| 1170 |
setQualifier(schemaNS, propName, qualNS, qualName, qualValue, null); |
| 1171 |
|
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
public void setStructField(String schemaNS, String structName, String fieldNS, |
| 1180 |
String fieldName, String fieldValue, PropertyOptions options) throws XMPException |
| 1181 |
{ |
| 1182 |
ParameterAsserts.assertSchemaNS(schemaNS); |
| 1183 |
ParameterAsserts.assertStructName(structName); |
| 1184 |
|
| 1185 |
String fieldPath = structName + XMPPathFactory.composeStructFieldPath(fieldNS, fieldName); |
| 1186 |
setProperty(schemaNS, fieldPath, fieldValue, options); |
| 1187 |
} |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
public void setStructField(String schemaNS, String structName, String fieldNS, |
| 1194 |
String fieldName, String fieldValue) throws XMPException |
| 1195 |
{ |
| 1196 |
setStructField(schemaNS, structName, fieldNS, fieldName, fieldValue, null); |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
public String getObjectName() |
| 1204 |
{ |
| 1205 |
return tree.getName() != null ? tree.getName() : ""; |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
public void setObjectName(String name) |
| 1213 |
{ |
| 1214 |
tree.setName(name); |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
public String getPacketHeader() |
| 1222 |
{ |
| 1223 |
return packetHeader; |
| 1224 |
} |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
public void setPacketHeader(String packetHeader) |
| 1232 |
{ |
| 1233 |
this.packetHeader = packetHeader; |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
public Object clone() |
| 1243 |
{ |
| 1244 |
XMPNode clonedTree = (XMPNode) tree.clone(); |
| 1245 |
return new XMPMetaImpl(clonedTree); |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
public String dumpObject() |
| 1253 |
{ |
| 1254 |
|
| 1255 |
return getRoot().dumpNode(true); |
| 1256 |
} |
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
public void sort() |
| 1263 |
{ |
| 1264 |
this.tree.sort(); |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
public void normalize(ParseOptions options) throws XMPException |
| 1272 |
{ |
| 1273 |
if (options == null) |
| 1274 |
{ |
| 1275 |
options = new ParseOptions(); |
| 1276 |
} |
| 1277 |
XMPNormalizer.process(this, options); |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
public XMPNode getRoot() |
| 1285 |
{ |
| 1286 |
return tree; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
private void doSetArrayItem(XMPNode arrayNode, int itemIndex, String itemValue, |
| 1310 |
PropertyOptions itemOptions, boolean insert) throws XMPException |
| 1311 |
{ |
| 1312 |
XMPNode itemNode = new XMPNode(ARRAY_ITEM_NAME, null); |
| 1313 |
itemOptions = XMPNodeUtils.verifySetOptions(itemOptions, itemValue); |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
int maxIndex = insert ? arrayNode.getChildrenLength() + 1 : arrayNode.getChildrenLength(); |
| 1318 |
if (itemIndex == ARRAY_LAST_ITEM) |
| 1319 |
{ |
| 1320 |
itemIndex = maxIndex; |
| 1321 |
} |
| 1322 |
|
| 1323 |
if (1 <= itemIndex && itemIndex <= maxIndex) |
| 1324 |
{ |
| 1325 |
if (!insert) |
| 1326 |
{ |
| 1327 |
arrayNode.removeChild(itemIndex); |
| 1328 |
} |
| 1329 |
arrayNode.addChild(itemIndex, itemNode); |
| 1330 |
setNode(itemNode, itemValue, itemOptions, false); |
| 1331 |
} |
| 1332 |
else |
| 1333 |
{ |
| 1334 |
throw new XMPException("Array index out of bounds", XMPError.BADINDEX); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
void setNode(XMPNode node, Object value, PropertyOptions newOptions, boolean deleteExisting) |
| 1353 |
throws XMPException |
| 1354 |
{ |
| 1355 |
int compositeMask = (PropertyOptions.ARRAY | PropertyOptions.ARRAY_ALT_TEXT | PropertyOptions.ARRAY_ALTERNATE |
| 1356 |
| PropertyOptions.ARRAY_ORDERED | PropertyOptions.STRUCT); |
| 1357 |
if (deleteExisting) |
| 1358 |
{ |
| 1359 |
node.clear(); |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
node.getOptions().mergeWith(newOptions); |
| 1364 |
|
| 1365 |
if ((node.getOptions().getOptions() & compositeMask) == 0) |
| 1366 |
{ |
| 1367 |
|
| 1368 |
XMPNodeUtils.setNodeValue(node, value); |
| 1369 |
} |
| 1370 |
else |
| 1371 |
{ |
| 1372 |
if (value != null && value.toString().length() > 0) |
| 1373 |
{ |
| 1374 |
throw new XMPException("Composite nodes can't have values", XMPError.BADXPATH); |
| 1375 |
} |
| 1376 |
if ((node.getOptions().getOptions() & compositeMask) != 0) { |
| 1377 |
if ( (newOptions.getOptions() & compositeMask) != (node.getOptions().getOptions() & compositeMask) ) { |
| 1378 |
throw new XMPException( "Requested and existing composite form mismatch", XMPError.BADXPATH ); |
| 1379 |
} |
| 1380 |
} |
| 1381 |
|
| 1382 |
node.removeChildren(); |
| 1383 |
} |
| 1384 |
|
| 1385 |
} |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
private Object evaluateNodeValue(int valueType, final XMPNode propNode) throws XMPException |
| 1400 |
{ |
| 1401 |
final Object value; |
| 1402 |
String rawValue = propNode.getValue(); |
| 1403 |
switch (valueType) |
| 1404 |
{ |
| 1405 |
case VALUE_BOOLEAN: |
| 1406 |
value = new Boolean(XMPUtils.convertToBoolean(rawValue)); |
| 1407 |
break; |
| 1408 |
case VALUE_INTEGER: |
| 1409 |
value = new Integer(XMPUtils.convertToInteger(rawValue)); |
| 1410 |
break; |
| 1411 |
case VALUE_LONG: |
| 1412 |
value = new Long(XMPUtils.convertToLong(rawValue)); |
| 1413 |
break; |
| 1414 |
case VALUE_DOUBLE: |
| 1415 |
value = new Double(XMPUtils.convertToDouble(rawValue)); |
| 1416 |
break; |
| 1417 |
case VALUE_DATE: |
| 1418 |
value = XMPUtils.convertToDate(rawValue); |
| 1419 |
break; |
| 1420 |
case VALUE_CALENDAR: |
| 1421 |
XMPDateTime dt = XMPUtils.convertToDate(rawValue); |
| 1422 |
value = dt.getCalendar(); |
| 1423 |
break; |
| 1424 |
case VALUE_BASE64: |
| 1425 |
value = XMPUtils.decodeBase64(rawValue); |
| 1426 |
break; |
| 1427 |
case VALUE_STRING: |
| 1428 |
default: |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
value = rawValue != null || propNode.getOptions().isCompositeProperty() ? rawValue : ""; |
| 1434 |
break; |
| 1435 |
} |
| 1436 |
return value; |
| 1437 |
} |
| 1438 |
} |