1
2
3
4
5
6
7
8
9 package eu.etaxonomy.cdm.io.tcsrdf;
10
11 import org.apache.log4j.Logger;
12 import org.jdom.Content;
13 import org.jdom.Element;
14 import org.jdom.Namespace;
15
16 import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
17 import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
18
19
20
21
22
23
24
25
26 public abstract class CdmSingleAttributeXmlMapperBase extends CdmSingleAttributeMapperBase implements IXmlMapper{
27 @SuppressWarnings("unused")
28 private static final Logger logger = Logger.getLogger(CdmSingleAttributeXmlMapperBase.class);
29
30 protected Namespace sourceNamespace;
31
32
33
34
35
36
37
38 protected CdmSingleAttributeXmlMapperBase(String sourceElementString,Namespace sourceNamespace, String cdmAttributeString){
39 super(sourceElementString, cdmAttributeString);
40
41 }
42
43
44
45
46
47
48
49 protected CdmSingleAttributeXmlMapperBase(String sourceElementString, String cdmAttributeString){
50 super(sourceElementString, cdmAttributeString);
51
52 }
53
54 public String getSourceElement(){
55 return super.getSourceAttribute();
56 }
57
58 public String getDestinationAttribute(){
59 return super.getDestinationAttribute();
60 }
61
62
63 public Namespace getSourceNamespace(){
64 return sourceNamespace;
65 }
66
67
68
69
70
71
72 public Namespace getSourceNamespace(Element parentElement){
73 if (this.sourceNamespace != null){
74 return sourceNamespace;
75 }else if (parentElement != null){
76 return parentElement.getNamespace();
77 }else{
78 return null;
79 }
80 }
81
82 public boolean mapsSource(Content content, Element parentElement){
83 if (! (content instanceof Element)){
84 return false;
85 }
86 Element element = (Element)content;
87 if (content == null){
88 return false;
89 }else if (! element.getName().equals(getSourceElement())){
90 return false;
91 }
92 Namespace thisNamespace = getSourceNamespace(parentElement);
93 if (thisNamespace == null){
94 if (element.getNamespace() == null){
95 return true;
96 }else{
97 return false;
98 }
99 }
100 if (! thisNamespace.equals(element.getNamespace())){
101 return false;
102 }
103 return true;
104 }
105
106 public String toString(){
107
108 return this.getSourceElement();
109 }
110 }