001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.repository.jcr; 017 018import java.util.Date; 019 020import org.ametys.plugins.repository.AmetysRepositoryException; 021import org.ametys.plugins.repository.metadata.CompositeMetadata; 022import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObject; 023import org.ametys.plugins.repository.metadata.ModifiableCompositeMetadata; 024import org.ametys.plugins.repository.metadata.ModifiableMetadataAwareAmetysObject; 025import org.ametys.plugins.repository.metadata.UnknownMetadataException; 026 027/** 028 * Helper class providing methods to get and set Dublin Core metadata on {@link MetadataAwareAmetysObject}s. 029 */ 030public final class DublinCoreHelper 031{ 032 033 /** Constant for Dublin Core metadata container name. */ 034 public static final String METADATA_DC_CONTAINER = "dc"; 035 036 /** Constant for Dublin Core title metadata. */ 037 public static final String METADATA_DC_TITLE = "dc_title"; 038 039 /** Constant for Dublin Core creator metadata. */ 040 public static final String METADATA_DC_CREATOR = "dc_creator"; 041 042 /** Constant for Dublin Core subject metadata. */ 043 public static final String METADATA_DC_SUBJECT = "dc_subject"; 044 045 /** Constant for Dublin Core description metadata. */ 046 public static final String METADATA_DC_DESCRIPTION = "dc_description"; 047 048 /** Constant for Dublin Core publisher metadata. */ 049 public static final String METADATA_DC_PUBLISHER = "dc_publisher"; 050 051 /** Constant for Dublin Core contributor metadata. */ 052 public static final String METADATA_DC_CONTRIBUTOR = "dc_contributor"; 053 054 /** Constant for Dublin Core date metadata. */ 055 public static final String METADATA_DC_DATE = "dc_date"; 056 057 /** Constant for Dublin Core type metadata. */ 058 public static final String METADATA_DC_TYPE = "dc_type"; 059 060 /** Constant for Dublin Core title Format. */ 061 public static final String METADATA_DC_FORMAT = "dc_format"; 062 063 /** Constant for Dublin Core identifier metadata. */ 064 public static final String METADATA_DC_IDENTIFIER = "dc_identifier"; 065 066 /** Constant for Dublin Core source metadata. */ 067 public static final String METADATA_DC_SOURCE = "dc_source"; 068 069 /** Constant for Dublin Core language metadata. */ 070 public static final String METADATA_DC_LANGUAGE = "dc_language"; 071 072 /** Constant for Dublin Core relation metadata. */ 073 public static final String METADATA_DC_RELATION = "dc_relation"; 074 075 /** Constant for Dublin Core coverage metadata. */ 076 public static final String METADATA_DC_COVERAGE = "dc_coverage"; 077 078 /** Constant for Dublin Core rights metadata. */ 079 public static final String METADATA_DC_RIGHTS = "dc_rights"; 080 081 private DublinCoreHelper() 082 { 083 // Hides default constructor. 084 } 085 086 /////// 087 // DublinCoreAwareAmetysObject methods. 088 /////// 089 090 /** 091 * Get the Dublin Core title. 092 * @param object the object. 093 * @return the Dublin Core title. Can be null. 094 * @throws AmetysRepositoryException if an error occurs. 095 */ 096 public static String getDCTitle(MetadataAwareAmetysObject object) throws AmetysRepositoryException 097 { 098 return getDCTitle(object, null); 099 } 100 101 /** 102 * Get the Dublin Core title. 103 * @param object the object. 104 * @param defaultValue the default title. 105 * @return the Dublin Core title. 106 * @throws AmetysRepositoryException if an error occurs. 107 */ 108 public static String getDCTitle(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 109 { 110 try 111 { 112 return getDCCompositeMetadata(object).getString(METADATA_DC_TITLE, defaultValue); 113 } 114 catch (UnknownMetadataException e) 115 { 116 return defaultValue; 117 } 118 } 119 120 /** 121 * Get the Dublin Core creator. 122 * @param object the object. 123 * @return the Dublin Core creator. Can be null. 124 * @throws AmetysRepositoryException if an error occurs. 125 */ 126 public static String getDCCreator(MetadataAwareAmetysObject object) throws AmetysRepositoryException 127 { 128 return getDCCreator(object, null); 129 } 130 131 /** 132 * Get the Dublin Core creator. 133 * @param object the object. 134 * @param defaultValue the default creator. 135 * @return the Dublin Core creator. 136 * @throws AmetysRepositoryException if an error occurs. 137 */ 138 public static String getDCCreator(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 139 { 140 try 141 { 142 return getDCCompositeMetadata(object).getString(METADATA_DC_CREATOR, defaultValue); 143 } 144 catch (UnknownMetadataException e) 145 { 146 return defaultValue; 147 } 148 } 149 150 /** 151 * Get the Dublin Core subject. 152 * @param object the object. 153 * @return the Dublin Core subject. Can be null. 154 * @throws AmetysRepositoryException if an error occurs. 155 */ 156 public static String[] getDCSubject(MetadataAwareAmetysObject object) throws AmetysRepositoryException 157 { 158 return getDCSubject(object, null); 159 } 160 161 /** 162 * Get the Dublin Core subject. 163 * @param object the object. 164 * @param defaultValue the default subject. 165 * @return the Dublin Core subject. 166 * @throws AmetysRepositoryException if an error occurs. 167 */ 168 public static String[] getDCSubject(MetadataAwareAmetysObject object, String[] defaultValue) throws AmetysRepositoryException 169 { 170 try 171 { 172 return getDCCompositeMetadata(object).getStringArray(METADATA_DC_SUBJECT, defaultValue); 173 } 174 catch (UnknownMetadataException e) 175 { 176 return defaultValue; 177 } 178 } 179 180 /** 181 * Get the Dublin Core description. 182 * @param object the object. 183 * @return the Dublin Core description. Can be null. 184 * @throws AmetysRepositoryException if an error occurs. 185 */ 186 public static String getDCDescription(MetadataAwareAmetysObject object) throws AmetysRepositoryException 187 { 188 return getDCDescription(object, null); 189 } 190 191 /** 192 * Get the Dublin Core description. 193 * @param object the object. 194 * @param defaultValue the default description. 195 * @return the Dublin Core description. 196 * @throws AmetysRepositoryException if an error occurs. 197 */ 198 public static String getDCDescription(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 199 { 200 try 201 { 202 return getDCCompositeMetadata(object).getString(METADATA_DC_DESCRIPTION, defaultValue); 203 } 204 catch (UnknownMetadataException e) 205 { 206 return defaultValue; 207 } 208 } 209 210 /** 211 * Get the Dublin Core publisher. 212 * @param object the object. 213 * @return the Dublin Core publisher. Can be null. 214 * @throws AmetysRepositoryException if an error occurs. 215 */ 216 public static String getDCPublisher(MetadataAwareAmetysObject object) throws AmetysRepositoryException 217 { 218 return getDCPublisher(object, null); 219 } 220 221 /** 222 * Get the Dublin Core publisher. 223 * @param object the object. 224 * @param defaultValue the default publisher. 225 * @return the Dublin Core publisher. 226 * @throws AmetysRepositoryException if an error occurs. 227 */ 228 public static String getDCPublisher(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 229 { 230 try 231 { 232 return getDCCompositeMetadata(object).getString(METADATA_DC_PUBLISHER, defaultValue); 233 } 234 catch (UnknownMetadataException e) 235 { 236 return defaultValue; 237 } 238 } 239 240 /** 241 * Get the Dublin Core contributor. 242 * @param object the object. 243 * @return the Dublin Core contributor. Can be null. 244 * @throws AmetysRepositoryException if an error occurs. 245 */ 246 public static String getDCContributor(MetadataAwareAmetysObject object) throws AmetysRepositoryException 247 { 248 return getDCContributor(object, null); 249 } 250 251 /** 252 * Get the Dublin Core contributor. 253 * @param object the object. 254 * @param defaultValue the default contributor. 255 * @return the Dublin Core contributor. 256 * @throws AmetysRepositoryException if an error occurs. 257 */ 258 public static String getDCContributor(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 259 { 260 try 261 { 262 return getDCCompositeMetadata(object).getString(METADATA_DC_CONTRIBUTOR, defaultValue); 263 } 264 catch (UnknownMetadataException e) 265 { 266 return defaultValue; 267 } 268 } 269 270 /** 271 * Get the Dublin Core date. 272 * @param object the object. 273 * @return the Dublin Core date. Can be null. 274 * @throws AmetysRepositoryException if an error occurs. 275 */ 276 public static Date getDCDate(MetadataAwareAmetysObject object) throws AmetysRepositoryException 277 { 278 return getDCDate(object, null); 279 } 280 281 /** 282 * Get the Dublin Core date. 283 * @param object the object. 284 * @param defaultValue the default date. 285 * @return the Dublin Core date. 286 * @throws AmetysRepositoryException if an error occurs. 287 */ 288 public static Date getDCDate(MetadataAwareAmetysObject object, Date defaultValue) throws AmetysRepositoryException 289 { 290 try 291 { 292 return getDCCompositeMetadata(object).getDate(METADATA_DC_DATE, defaultValue); 293 } 294 catch (UnknownMetadataException e) 295 { 296 return defaultValue; 297 } 298 } 299 300 /** 301 * Get the Dublin Core type. 302 * @param object the object. 303 * @return the Dublin Core type. Can be null. 304 * @throws AmetysRepositoryException if an error occurs. 305 */ 306 public static String getDCType(MetadataAwareAmetysObject object) throws AmetysRepositoryException 307 { 308 return getDCType(object, null); 309 } 310 311 /** 312 * Get the Dublin Core type. 313 * @param object the object. 314 * @param defaultValue the default type. 315 * @return the Dublin Core type. 316 * @throws AmetysRepositoryException if an error occurs. 317 */ 318 public static String getDCType(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 319 { 320 try 321 { 322 return getDCCompositeMetadata(object).getString(METADATA_DC_TYPE, defaultValue); 323 } 324 catch (UnknownMetadataException e) 325 { 326 return defaultValue; 327 } 328 } 329 330 /** 331 * Get the Dublin Core format. 332 * @param object the object. 333 * @return the Dublin Core format. Can be null. 334 * @throws AmetysRepositoryException if an error occurs. 335 */ 336 public static String getDCFormat(MetadataAwareAmetysObject object) throws AmetysRepositoryException 337 { 338 return getDCFormat(object, null); 339 } 340 341 /** 342 * Get the Dublin Core format. 343 * @param object the object. 344 * @param defaultValue the default format. 345 * @return the Dublin Core format. 346 * @throws AmetysRepositoryException if an error occurs. 347 */ 348 public static String getDCFormat(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 349 { 350 try 351 { 352 return getDCCompositeMetadata(object).getString(METADATA_DC_FORMAT, defaultValue); 353 } 354 catch (UnknownMetadataException e) 355 { 356 return defaultValue; 357 } 358 } 359 360 /** 361 * Get the Dublin Core identifier. 362 * @param object the object. 363 * @return the Dublin Core identifier. Can be null. 364 * @throws AmetysRepositoryException if an error occurs. 365 */ 366 public static String getDCIdentifier(MetadataAwareAmetysObject object) throws AmetysRepositoryException 367 { 368 return getDCIdentifier(object, null); 369 } 370 371 /** 372 * Get the Dublin Core identifier. 373 * @param object the object. 374 * @param defaultValue the default identifier. 375 * @return the Dublin Core identifier. 376 * @throws AmetysRepositoryException if an error occurs. 377 */ 378 public static String getDCIdentifier(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 379 { 380 try 381 { 382 return getDCCompositeMetadata(object).getString(METADATA_DC_IDENTIFIER, defaultValue); 383 } 384 catch (UnknownMetadataException e) 385 { 386 return defaultValue; 387 } 388 } 389 390 /** 391 * Get the Dublin Core source. 392 * @param object the object. 393 * @return the Dublin Core source. Can be null. 394 * @throws AmetysRepositoryException if an error occurs. 395 */ 396 public static String getDCSource(MetadataAwareAmetysObject object) throws AmetysRepositoryException 397 { 398 return getDCSource(object, null); 399 } 400 401 /** 402 * Get the Dublin Core source. 403 * @param object the object. 404 * @param defaultValue the default source. 405 * @return the Dublin Core source. 406 * @throws AmetysRepositoryException if an error occurs. 407 */ 408 public static String getDCSource(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 409 { 410 try 411 { 412 return getDCCompositeMetadata(object).getString(METADATA_DC_SOURCE, defaultValue); 413 } 414 catch (UnknownMetadataException e) 415 { 416 return defaultValue; 417 } 418 } 419 420 /** 421 * Get the Dublin Core language. 422 * @param object the object. 423 * @return the Dublin Core language. Can be null. 424 * @throws AmetysRepositoryException if an error occurs. 425 */ 426 public static String getDCLanguage(MetadataAwareAmetysObject object) throws AmetysRepositoryException 427 { 428 return getDCLanguage(object, null); 429 } 430 431 /** 432 * Get the Dublin Core language. 433 * @param object the object. 434 * @param defaultValue the default language. 435 * @return the Dublin Core language. 436 * @throws AmetysRepositoryException if an error occurs. 437 */ 438 public static String getDCLanguage(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 439 { 440 try 441 { 442 return getDCCompositeMetadata(object).getString(METADATA_DC_LANGUAGE, defaultValue); 443 } 444 catch (UnknownMetadataException e) 445 { 446 return defaultValue; 447 } 448 } 449 450 /** 451 * Get the Dublin Core relation. 452 * @param object the object. 453 * @return the Dublin Core relation. Can be null. 454 * @throws AmetysRepositoryException if an error occurs. 455 */ 456 public static String getDCRelation(MetadataAwareAmetysObject object) throws AmetysRepositoryException 457 { 458 return getDCRelation(object, null); 459 } 460 461 /** 462 * Get the Dublin Core relation. 463 * @param object the object. 464 * @param defaultValue the default relation. 465 * @return the Dublin Core relation. 466 * @throws AmetysRepositoryException if an error occurs. 467 */ 468 public static String getDCRelation(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 469 { 470 try 471 { 472 return getDCCompositeMetadata(object).getString(METADATA_DC_RELATION, defaultValue); 473 } 474 catch (UnknownMetadataException e) 475 { 476 return defaultValue; 477 } 478 } 479 480 /** 481 * Get the Dublin Core coverage. 482 * @param object the object. 483 * @return the Dublin Core coverage. Can be null. 484 * @throws AmetysRepositoryException if an error occurs. 485 */ 486 public static String getDCCoverage(MetadataAwareAmetysObject object) throws AmetysRepositoryException 487 { 488 return getDCCoverage(object, null); 489 } 490 491 /** 492 * Get the Dublin Core coverage. 493 * @param object the object. 494 * @param defaultValue the default coverage. 495 * @return the Dublin Core coverage. 496 * @throws AmetysRepositoryException if an error occurs. 497 */ 498 public static String getDCCoverage(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 499 { 500 try 501 { 502 return getDCCompositeMetadata(object).getString(METADATA_DC_COVERAGE, defaultValue); 503 } 504 catch (UnknownMetadataException e) 505 { 506 return defaultValue; 507 } 508 } 509 510 /** 511 * Get the Dublin Core rights. 512 * @param object the object. 513 * @return the Dublin Core rights. Can be null. 514 * @throws AmetysRepositoryException if an error occurs. 515 */ 516 public static String getDCRights(MetadataAwareAmetysObject object) throws AmetysRepositoryException 517 { 518 return getDCRights(object, null); 519 } 520 521 /** 522 * Get the Dublin Core rights. 523 * @param object the object. 524 * @param defaultValue the default rights. 525 * @return the Dublin Core rights. 526 * @throws AmetysRepositoryException if an error occurs. 527 */ 528 public static String getDCRights(MetadataAwareAmetysObject object, String defaultValue) throws AmetysRepositoryException 529 { 530 try 531 { 532 return getDCCompositeMetadata(object).getString(METADATA_DC_RIGHTS, defaultValue); 533 } 534 catch (UnknownMetadataException e) 535 { 536 return defaultValue; 537 } 538 } 539 540 /////// 541 // ModifiableDublinCoreAwareAmetysObject methods. 542 /////// 543 544 /** 545 * Set the Dublin Core title. 546 * @param object the ametys object. 547 * @param title the Dublin Core title to set. Can be null. 548 * @throws AmetysRepositoryException if an error occurs. 549 */ 550 public static void setDCTitle(ModifiableMetadataAwareAmetysObject object, String title) throws AmetysRepositoryException 551 { 552 if (title != null) 553 { 554 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_TITLE, title); 555 } 556 else 557 { 558 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_TITLE)) 559 { 560 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_TITLE); 561 } 562 } 563 } 564 565 /** 566 * Set the Dublin Core creator. 567 * @param object the ametys object. 568 * @param creator the Dublin Core creator to set. Can be null. 569 * @throws AmetysRepositoryException if an error occurs. 570 */ 571 public static void setDCCreator(ModifiableMetadataAwareAmetysObject object, String creator) throws AmetysRepositoryException 572 { 573 if (creator != null) 574 { 575 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_CREATOR, creator); 576 } 577 else 578 { 579 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_CREATOR)) 580 { 581 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_CREATOR); 582 } 583 } 584 } 585 586 /** 587 * Set the Dublin Core subject. 588 * @param object the ametys object. 589 * @param subject the Dublin Core subject to set. Can be null. 590 * @throws AmetysRepositoryException if an error occurs. 591 */ 592 public static void setDCSubject(ModifiableMetadataAwareAmetysObject object, String[] subject) throws AmetysRepositoryException 593 { 594 if (subject != null) 595 { 596 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_SUBJECT, subject); 597 } 598 else 599 { 600 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_SUBJECT)) 601 { 602 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_SUBJECT); 603 } 604 } 605 } 606 607 /** 608 * Set the Dublin Core description. 609 * @param object the ametys object. 610 * @param description the Dublin Core description to set. Can be null. 611 * @throws AmetysRepositoryException if an error occurs. 612 */ 613 public static void setDCDescription(ModifiableMetadataAwareAmetysObject object, String description) throws AmetysRepositoryException 614 { 615 if (description != null) 616 { 617 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_DESCRIPTION, description); 618 } 619 else 620 { 621 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_DESCRIPTION)) 622 { 623 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_DESCRIPTION); 624 } 625 } 626 } 627 628 /** 629 * Set the Dublin Core publisher. 630 * @param object the ametys object. 631 * @param publisher the Dublin Core publisher to set. Can be null. 632 * @throws AmetysRepositoryException if an error occurs. 633 */ 634 public static void setDCPublisher(ModifiableMetadataAwareAmetysObject object, String publisher) throws AmetysRepositoryException 635 { 636 if (publisher != null) 637 { 638 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_PUBLISHER, publisher); 639 } 640 else 641 { 642 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_PUBLISHER)) 643 { 644 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_PUBLISHER); 645 } 646 } 647 } 648 649 /** 650 * Set the Dublin Core contributor. 651 * @param object the ametys object. 652 * @param contributor the Dublin Core contributor to set. Can be null. 653 * @throws AmetysRepositoryException if an error occurs. 654 */ 655 public static void setDCContributor(ModifiableMetadataAwareAmetysObject object, String contributor) throws AmetysRepositoryException 656 { 657 if (contributor != null) 658 { 659 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_CONTRIBUTOR, contributor); 660 } 661 else 662 { 663 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_CONTRIBUTOR)) 664 { 665 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_CONTRIBUTOR); 666 } 667 } 668 } 669 670 /** 671 * Set the Dublin Core date. 672 * @param object the ametys object. 673 * @param date the Dublin Core date to set. Can be null. 674 * @throws AmetysRepositoryException if an error occurs. 675 */ 676 public static void setDCDate(ModifiableMetadataAwareAmetysObject object, Date date) throws AmetysRepositoryException 677 { 678 if (date != null) 679 { 680 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_DATE, date); 681 } 682 else 683 { 684 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_DATE)) 685 { 686 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_DATE); 687 } 688 } 689 } 690 691 /** 692 * Set the Dublin Core type. 693 * @param object the ametys object. 694 * @param type the Dublin Core type to set. Can be null. 695 * @throws AmetysRepositoryException if an error occurs. 696 */ 697 public static void setDCType(ModifiableMetadataAwareAmetysObject object, String type) throws AmetysRepositoryException 698 { 699 if (type != null) 700 { 701 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_TYPE, type); 702 } 703 else 704 { 705 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_TYPE)) 706 { 707 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_TYPE); 708 } 709 } 710 } 711 712 /** 713 * Set the Dublin Core format. 714 * @param object the ametys object. 715 * @param format the Dublin Core format to set. Can be null. 716 * @throws AmetysRepositoryException if an error occurs. 717 */ 718 public static void setDCFormat(ModifiableMetadataAwareAmetysObject object, String format) throws AmetysRepositoryException 719 { 720 if (format != null) 721 { 722 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_FORMAT, format); 723 } 724 else 725 { 726 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_FORMAT)) 727 { 728 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_FORMAT); 729 } 730 } 731 } 732 733 /** 734 * Set the Dublin Core identifier. 735 * @param object the ametys object. 736 * @param identifier the Dublin Core identifier to set. Can be null. 737 * @throws AmetysRepositoryException if an error occurs. 738 */ 739 public static void setDCIdentifier(ModifiableMetadataAwareAmetysObject object, String identifier) throws AmetysRepositoryException 740 { 741 if (identifier != null) 742 { 743 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_IDENTIFIER, identifier); 744 } 745 else 746 { 747 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_IDENTIFIER)) 748 { 749 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_IDENTIFIER); 750 } 751 } 752 } 753 754 /** 755 * Set the Dublin Core source. 756 * @param object the ametys object. 757 * @param source the Dublin Core source to set. Can be null. 758 * @throws AmetysRepositoryException if an error occurs. 759 */ 760 public static void setDCSource(ModifiableMetadataAwareAmetysObject object, String source) throws AmetysRepositoryException 761 { 762 if (source != null) 763 { 764 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_SOURCE, source); 765 } 766 else 767 { 768 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_SOURCE)) 769 { 770 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_SOURCE); 771 } 772 } 773 } 774 775 /** 776 * Set the Dublin Core language. 777 * @param object the ametys object. 778 * @param language the Dublin Core language to set. Can be null. 779 * @throws AmetysRepositoryException if an error occurs. 780 */ 781 public static void setDCLanguage(ModifiableMetadataAwareAmetysObject object, String language) throws AmetysRepositoryException 782 { 783 if (language != null) 784 { 785 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_LANGUAGE, language); 786 } 787 else 788 { 789 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_LANGUAGE)) 790 { 791 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_LANGUAGE); 792 } 793 } 794 } 795 796 /** 797 * Set the Dublin Core relation. 798 * @param object the ametys object. 799 * @param relation the Dublin Core relation to set. Can be null. 800 * @throws AmetysRepositoryException if an error occurs. 801 */ 802 public static void setDCRelation(ModifiableMetadataAwareAmetysObject object, String relation) throws AmetysRepositoryException 803 { 804 if (relation != null) 805 { 806 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_RELATION, relation); 807 } 808 else 809 { 810 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_RELATION)) 811 { 812 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_RELATION); 813 } 814 } 815 } 816 817 /** 818 * Set the Dublin Core coverage. 819 * @param object the ametys object. 820 * @param coverage the Dublin Core coverage to set. Can be null. 821 * @throws AmetysRepositoryException if an error occurs. 822 */ 823 public static void setDCCoverage(ModifiableMetadataAwareAmetysObject object, String coverage) throws AmetysRepositoryException 824 { 825 if (coverage != null) 826 { 827 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_COVERAGE, coverage); 828 } 829 else 830 { 831 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_COVERAGE)) 832 { 833 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_COVERAGE); 834 } 835 } 836 } 837 838 /** 839 * Set the Dublin Core rights. 840 * @param object the ametys object. 841 * @param rights the Dublin Core rights to set. Can be null. 842 * @throws AmetysRepositoryException if an error occurs. 843 */ 844 public static void setDCRights(ModifiableMetadataAwareAmetysObject object, String rights) throws AmetysRepositoryException 845 { 846 if (rights != null) 847 { 848 getModifiableDCCompositeMetadata(object).setMetadata(METADATA_DC_RIGHTS, rights); 849 } 850 else 851 { 852 if (getModifiableDCCompositeMetadata(object).hasMetadata(METADATA_DC_RIGHTS)) 853 { 854 getModifiableDCCompositeMetadata(object).removeMetadata(METADATA_DC_RIGHTS); 855 } 856 } 857 } 858 859 /** 860 * Get the Dublin Core composite metadata of the given ametys object. 861 * @param object the ametys object. 862 * @return Dublin Core composite metadata. 863 * @throws UnknownMetadataException if the CompositeMetadata does not exist. 864 */ 865 static CompositeMetadata getDCCompositeMetadata(MetadataAwareAmetysObject object) throws UnknownMetadataException 866 { 867 return object.getMetadataHolder().getCompositeMetadata(METADATA_DC_CONTAINER); 868 } 869 870 /** 871 * Get the Dublin Core modifiable composite metadata of the given ametys object, 872 * creating it if it doesn't exist. 873 * @param object the ametys object. 874 * @return Dublin Core composite metadata. 875 * @throws UnknownMetadataException if the CompositeMetadata does not exist (should never happen). 876 */ 877 static ModifiableCompositeMetadata getModifiableDCCompositeMetadata(ModifiableMetadataAwareAmetysObject object) throws UnknownMetadataException 878 { 879 return object.getMetadataHolder().getCompositeMetadata(METADATA_DC_CONTAINER, true); 880 } 881 882}