View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.mods.enrichment;
20  
21  import org.jaxen.JaxenException;
22  import org.jdom2.Element;
23  import org.mycore.common.MCRException;
24  import org.mycore.common.xml.MCRNodeBuilder;
25  
26  /**
27   * Represents a publication's identifier like DOI or ISBN
28   *
29   * @author Frank L\u00FCtzenkirchen
30   */
31  public class MCRIdentifier {
32  
33      private MCRIdentifierType type;
34  
35      private String value;
36  
37      MCRIdentifier(MCRIdentifierType type, String value) {
38          this.type = type;
39          this.value = value;
40      }
41  
42      public MCRIdentifierType getType() {
43          return type;
44      }
45  
46      public String getValue() {
47          return value;
48      }
49  
50      @Override
51      public boolean equals(Object other) {
52          return (other instanceof MCRIdentifier && this.toString().equals(other.toString()));
53      }
54  
55      @Override
56      public int hashCode() {
57          return toString().hashCode();
58      }
59  
60      @Override
61      public String toString() {
62          return type.getTypeID() + " " + value;
63      }
64  
65      /**
66       * Builds the XML representation of this identifier within MODS.
67       */
68      void mergeInto(Element publication) {
69          Element container = new Element(publication.getName(), publication.getNamespace());
70          try {
71              new MCRNodeBuilder().buildElement(type.getXPath(), value, container);
72          } catch (JaxenException ex) {
73              throw new MCRException(ex);
74          }
75          MCREnricher.merge(publication, container);
76      }
77  }