1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.mods.classification;
20
21 import org.mycore.datamodel.classifications2.MCRCategoryDAOFactory;
22 import org.mycore.datamodel.classifications2.MCRCategoryID;
23 import org.w3c.dom.Element;
24
25
26
27
28
29
30
31 class MCRTypeOfResource extends MCRAuthorityInfo {
32
33
34
35
36
37 public static final String TYPE_OF_RESOURCE = "typeOfResource";
38
39
40
41
42 private String code;
43
44 MCRTypeOfResource(String code) {
45 this.code = code;
46 }
47
48
49
50
51 public static MCRTypeOfResource getAuthorityInfo(org.jdom2.Element modsElement) {
52 if (modsElement == null) {
53 return null;
54 }
55 String name = modsElement.getName();
56 String code = modsElement.getTextTrim();
57 return getTypeOfResource(name, code);
58 }
59
60
61
62
63 public static MCRTypeOfResource getAuthorityInfo(Element modsElement) {
64 if (modsElement == null) {
65 return null;
66 }
67 String name = modsElement.getLocalName();
68 String code = MCRMODSClassificationSupport.getText(modsElement).trim();
69 return getTypeOfResource(name, code);
70 }
71
72
73
74
75 private static MCRTypeOfResource getTypeOfResource(String name, String code) {
76 return (name.equals(TYPE_OF_RESOURCE) && isClassificationPresent()) ? new MCRTypeOfResource(code) : null;
77 }
78
79 @Override
80 public String toString() {
81 return TYPE_OF_RESOURCE + "#" + code;
82 }
83
84 @Override
85 protected MCRCategoryID lookupCategoryID() {
86 return new MCRCategoryID(TYPE_OF_RESOURCE, code.replace(" ", "_"));
87 }
88
89 @Override
90 public void setInElement(org.jdom2.Element element) {
91 element.setText(code);
92
93 }
94
95 @Override
96 public void setInElement(Element element) {
97 element.setTextContent(code);
98 }
99
100 public static boolean isClassificationPresent() {
101 return MCRCategoryDAOFactory.getInstance().exist(MCRCategoryID.rootID(TYPE_OF_RESOURCE));
102 }
103 }