3 |
3 |
import java.io.StringReader;
|
4 |
4 |
import java.net.URI;
|
5 |
5 |
import java.net.URISyntaxException;
|
|
6 |
import java.util.LinkedHashMap;
|
|
7 |
import java.util.LinkedHashSet;
|
6 |
8 |
import java.util.List;
|
|
9 |
import java.util.Map;
|
|
10 |
import java.util.Map.Entry;
|
|
11 |
import java.util.Set;
|
7 |
12 |
|
|
13 |
import org.apache.commons.lang3.StringUtils;
|
8 |
14 |
import org.apache.commons.logging.Log;
|
9 |
15 |
import org.apache.commons.logging.LogFactory;
|
10 |
16 |
import org.dom4j.Document;
|
11 |
17 |
import org.dom4j.DocumentException;
|
|
18 |
import org.dom4j.Element;
|
12 |
19 |
import org.dom4j.Node;
|
|
20 |
import org.dom4j.QName;
|
13 |
21 |
import org.dom4j.io.SAXReader;
|
14 |
22 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
23 |
|
... | ... | |
35 |
43 |
|
36 |
44 |
if (results.size() == 1) {
|
37 |
45 |
final Node n = (Node) results.get(0);
|
38 |
|
System.out.println("------------");
|
39 |
|
System.out.println("TITLE 1: " + doc.valueOf("//*[local-name() = 'title']"));
|
40 |
|
System.out.println("TITLE 2: " + docRes.valueOf("//*[local-name() = 'title' and @classid='main title']"));
|
41 |
|
|
42 |
|
for (final Object oid : n.selectNodes(".//originalId")) {
|
43 |
|
System.out.println(" - " + ((Node) oid).getText());
|
44 |
|
}
|
|
46 |
updateRights(doc, n);
|
|
47 |
updateSubjects(doc, n);
|
|
48 |
updateCitations(doc, n);
|
|
49 |
updateUrls(doc, n);
|
45 |
50 |
return true;
|
46 |
51 |
} else if (results.size() == 1) {
|
47 |
52 |
log.warn("Too many responses");
|
... | ... | |
54 |
59 |
return false;
|
55 |
60 |
|
56 |
61 |
}
|
|
62 |
|
|
63 |
private void updateRights(final Document doc, final Node n) {
|
|
64 |
final Element rightsList = (Element) doc.selectSingleNode("//*[local-name() = 'rightsList']");
|
|
65 |
final Set<String> rights = new LinkedHashSet<>();
|
|
66 |
for (final Object o : rightsList.selectNodes("./*[local-name() = 'rights']")) {
|
|
67 |
rights.add(((Node) o).getText());
|
|
68 |
((Node) o).detach();
|
|
69 |
}
|
|
70 |
|
|
71 |
final String bestLicence = n.valueOf("./bestlicense/@classname");
|
|
72 |
if (StringUtils.isNotBlank(bestLicence)) {
|
|
73 |
rights.add(bestLicence);
|
|
74 |
}
|
|
75 |
|
|
76 |
for (final Object o : n.selectNodes(".//instance")) {
|
|
77 |
rights.add(((Node) o).valueOf("./licence/@classname").trim());
|
|
78 |
}
|
|
79 |
|
|
80 |
for (final String r : rights) {
|
|
81 |
rightsList.addElement(new QName("rights", rightsList.getNamespace())).setText(r);
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
private void updateSubjects(final Document doc, final Node n) {
|
|
86 |
final Element subjectsList = (Element) doc.selectSingleNode("//*[local-name() = 'subjects']");
|
|
87 |
final Set<String> subjects = new LinkedHashSet<>();
|
|
88 |
for (final Object o : subjectsList.selectNodes("./*[local-name() = 'subject']")) {
|
|
89 |
subjects.add(((Node) o).getText());
|
|
90 |
((Node) o).detach();
|
|
91 |
}
|
|
92 |
|
|
93 |
for (final Object o : n.selectNodes(".//subject[@classid='keyword']")) {
|
|
94 |
subjects.add(((Node) o).getText().trim());
|
|
95 |
}
|
|
96 |
|
|
97 |
for (final String r : subjects) {
|
|
98 |
subjectsList.addElement(new QName("subject", subjectsList.getNamespace())).setText(r);
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
private void updateCitations(final Document doc, final Node n) {
|
|
103 |
final Element citations = (Element) doc.selectSingleNode("//*[local-name() = 'citations']");
|
|
104 |
|
|
105 |
for (final Object o : n.selectNodes(".//citations/citation/rawText")) {
|
|
106 |
citations.addElement(new QName("citation", citations.getNamespace())).setText(((Node) o).getText());
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
private void updateUrls(final Document doc, final Node n) {
|
|
111 |
final Element urlList = (Element) doc.selectSingleNode("//*[local-name() = 'alternateIdentifiers']");
|
|
112 |
final Map<String, String> urls = new LinkedHashMap<>();
|
|
113 |
for (final Object o : urlList.selectNodes("./*[local-name() = 'alternateIdentifier' and @alternateIdentifierType='url']")) {
|
|
114 |
urls.put(((Node) o).getText().trim(), "unknown");
|
|
115 |
((Node) o).detach();
|
|
116 |
}
|
|
117 |
|
|
118 |
for (final Object oin : n.selectNodes(".//instance")) {
|
|
119 |
final String licence = ((Element) oin).valueOf("./licence/@classname").trim();
|
|
120 |
for (final Object ourl : ((Element) oin).selectNodes("./webresource/url")) {
|
|
121 |
urls.put(((Node) ourl).getText().trim(), licence);
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
for (final Entry<String, String> e : urls.entrySet()) {
|
|
126 |
final Element aid = urlList.addElement(new QName("alternateIdentifier", urlList.getNamespace()));
|
|
127 |
aid.addAttribute("alternateIdentifierType", "url");
|
|
128 |
aid.addAttribute("licence", e.getValue());
|
|
129 |
aid.setText(e.getKey());
|
|
130 |
}
|
|
131 |
}
|
57 |
132 |
}
|
Openaire plugin