Merge branch 'release/5.45.0'
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / editor / MetadataPrefixEditor.java
1 /**
2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.remote.editor;
10
11 import java.beans.PropertyEditorSupport;
12
13 import eu.etaxonomy.cdm.remote.dto.oaipmh.MetadataPrefix;
14 import eu.etaxonomy.cdm.remote.exception.CannotDisseminateFormatException;
15
16 public class MetadataPrefixEditor extends PropertyEditorSupport {
17
18 @Override
19 public void setAsText(String text) {
20 if(text == null) {
21 throw new IllegalArgumentException("null is not an acceptable metadata format");
22 } else {
23 MetadataPrefix metadatPrefix = MetadataPrefix.value(text);
24 if(metadatPrefix != null){
25 setValue(metadatPrefix);
26
27 // if(text.equals("rdf")) {
28 // setValue(MetadataPrefix.RDF);
29 // } else if(text.equals("oai_dc")) {
30 // setValue(MetadataPrefix.OAI_DC);
31 } else {
32 throw new CannotDisseminateFormatException(text + " is not an acceptable metadata format");
33 }
34 }
35 }
36
37 @Override
38 public String getAsText() {
39 if(getValue() == null) {
40 return null;
41 } else {
42 return ((MetadataPrefix)getValue()).name();
43 }
44 }
45 }