1
|
package eu.etaxonomy.cdm.io.tcsrdf;
|
2
|
|
3
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
4
|
import org.jdom.Element;
|
5
|
|
6
|
import com.hp.hpl.jena.rdf.model.Resource;
|
7
|
import com.hp.hpl.jena.rdf.model.Statement;
|
8
|
|
9
|
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
|
10
|
import eu.etaxonomy.cdm.io.common.mapping.IRdfMapper;
|
11
|
import eu.etaxonomy.cdm.io.tcsxml.CdmSingleAttributeXmlMapperBase;
|
12
|
|
13
|
|
14
|
/**
|
15
|
* @author a.mueller
|
16
|
*/
|
17
|
public abstract class CdmSingleAttributeRDFMapperBase extends
|
18
|
CdmSingleAttributeMapperBase implements IRdfMapper {
|
19
|
|
20
|
|
21
|
@SuppressWarnings("unused")
|
22
|
private static final Logger logger = LogManager.getLogger(CdmSingleAttributeXmlMapperBase.class);
|
23
|
|
24
|
protected String sourceNameSpace;
|
25
|
|
26
|
|
27
|
/**
|
28
|
* @param sourceElementString
|
29
|
* @param sourceNamespace
|
30
|
* @param cdmAttributeString
|
31
|
*/
|
32
|
protected CdmSingleAttributeRDFMapperBase(String sourceElementString, String subject, String cdmAttributeString){
|
33
|
super(sourceElementString, cdmAttributeString);
|
34
|
this.sourceNameSpace = subject;
|
35
|
}
|
36
|
|
37
|
|
38
|
/**
|
39
|
* Uses the Namespace of the parent Element
|
40
|
* @param sourceElementString
|
41
|
* @param cdmAttributeString
|
42
|
*/
|
43
|
protected CdmSingleAttributeRDFMapperBase(String sourceElementString, String cdmAttributeString){
|
44
|
super(sourceElementString, cdmAttributeString);
|
45
|
|
46
|
}
|
47
|
|
48
|
public String getSourceElement(){
|
49
|
return super.getSourceAttribute();
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public String getDestinationAttribute(){
|
54
|
return super.getDestinationAttribute();
|
55
|
}
|
56
|
|
57
|
|
58
|
public String getSourceNamespace(){
|
59
|
return sourceNameSpace;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Returns the namespace. If namespace is null, return parentElement namespace
|
64
|
* @param parentElement
|
65
|
* @return
|
66
|
*/
|
67
|
public String getSourceNameSpace(Statement resource){
|
68
|
if (this.sourceNameSpace != null){
|
69
|
return sourceNameSpace;
|
70
|
}else if (resource != null){
|
71
|
return resource.getPredicate().toString();
|
72
|
}else{
|
73
|
return null;
|
74
|
}
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public boolean mapsSource(Resource content, Statement statement){
|
79
|
if (! (content instanceof Element)){
|
80
|
return false;
|
81
|
}
|
82
|
//Element element = (Element)content;
|
83
|
if (content == null){
|
84
|
return false;
|
85
|
}else if (! content.getNameSpace().equals(getSourceElement())){
|
86
|
return false;
|
87
|
}
|
88
|
String thisSourceNameSpace= getSourceNameSpace(statement);
|
89
|
if (thisSourceNameSpace == null){
|
90
|
if (content.getNameSpace() == null){
|
91
|
return true;
|
92
|
}else{
|
93
|
return false;
|
94
|
}
|
95
|
}
|
96
|
if (! thisSourceNameSpace.equals(content.getNameSpace())){
|
97
|
return false;
|
98
|
}
|
99
|
return true;
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public String toString(){
|
104
|
//TODO
|
105
|
return this.getSourceElement();
|
106
|
}
|
107
|
}
|