1
|
package eu.dnetlib.resolver.parser;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
import javax.xml.stream.XMLStreamReader;
|
6
|
|
7
|
import eu.dnetlib.resolver.model.ObjectType;
|
8
|
import eu.dnetlib.resolver.model.ResolvedObject;
|
9
|
import org.apache.commons.lang3.StringUtils;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
|
13
|
/**
|
14
|
* Created by sandro on 9/13/16.
|
15
|
*/
|
16
|
public abstract class AbstractResolverParser {
|
17
|
|
18
|
protected static final Log log = LogFactory.getLog(AbstractResolverParser.class);
|
19
|
|
20
|
public abstract ResolvedObject parseObject(final String record);
|
21
|
|
22
|
protected Map<String, String> getAttributes(final XMLStreamReader parser) {
|
23
|
final Map<String, String> attributesMap = new HashMap<>();
|
24
|
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
25
|
attributesMap.put(parser.getAttributeLocalName(i), parser.getAttributeValue(i));
|
26
|
}
|
27
|
return attributesMap;
|
28
|
}
|
29
|
|
30
|
protected void setType(final ResolvedObject object, final String type) {
|
31
|
if (!StringUtils.isBlank(type)) {
|
32
|
if (type.toLowerCase().contains("dataset")) {
|
33
|
object.setType(ObjectType.dataset);
|
34
|
return;
|
35
|
} else if (type.toLowerCase().contains("publication")) {
|
36
|
object.setType(ObjectType.publication);
|
37
|
return;
|
38
|
} else {
|
39
|
object.setType(ObjectType.unknown);
|
40
|
}
|
41
|
}
|
42
|
}
|
43
|
|
44
|
}
|