1 |
1e21a025
|
Andreas Müller
|
/**
|
2 |
01be5674
|
Andreas Müller
|
* Copyright (C) 2007 EDIT
|
3 |
|
|
* European Distributed Institute of Taxonomy
|
4 |
|
|
* http://www.e-taxonomy.eu
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
|
|
*/
|
9 |
|
|
package eu.etaxonomy.cdm.io.tcsrdf;
|
10 |
1e21a025
|
Andreas Müller
|
|
11 |
|
|
import org.apache.log4j.Logger;
|
12 |
|
|
import org.jdom.Content;
|
13 |
|
|
import org.jdom.Element;
|
14 |
|
|
import org.jdom.Namespace;
|
15 |
|
|
|
16 |
892efc69
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
|
17 |
9cc4226b
|
Katja Luther
|
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
|
18 |
1e21a025
|
Andreas Müller
|
|
19 |
01be5674
|
Andreas Müller
|
|
20 |
1e21a025
|
Andreas Müller
|
/**
|
21 |
|
|
* @author a.mueller
|
22 |
01be5674
|
Andreas Müller
|
* @created 29.07.2008
|
23 |
|
|
* @version 1.0
|
24 |
1e21a025
|
Andreas Müller
|
*/
|
25 |
01be5674
|
Andreas Müller
|
|
26 |
8e7ddb43
|
Andreas Müller
|
public abstract class CdmSingleAttributeXmlMapperBase extends CdmSingleAttributeMapperBase implements IXmlMapper{
|
27 |
|
|
@SuppressWarnings("unused")
|
28 |
|
|
private static final Logger logger = Logger.getLogger(CdmSingleAttributeXmlMapperBase.class);
|
29 |
1e21a025
|
Andreas Müller
|
|
30 |
1bfab135
|
Andreas Müller
|
protected Namespace sourceNamespace;
|
31 |
1e21a025
|
Andreas Müller
|
|
32 |
|
|
|
33 |
|
|
/**
|
34 |
|
|
* @param sourceElementString
|
35 |
|
|
* @param sourceNamespace
|
36 |
|
|
* @param cdmAttributeString
|
37 |
|
|
*/
|
38 |
8e7ddb43
|
Andreas Müller
|
protected CdmSingleAttributeXmlMapperBase(String sourceElementString,Namespace sourceNamespace, String cdmAttributeString){
|
39 |
1e21a025
|
Andreas Müller
|
super(sourceElementString, cdmAttributeString);
|
40 |
|
|
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* Uses the Namespace of the parent Element
|
46 |
|
|
* @param sourceElementString
|
47 |
|
|
* @param cdmAttributeString
|
48 |
|
|
*/
|
49 |
8e7ddb43
|
Andreas Müller
|
protected CdmSingleAttributeXmlMapperBase(String sourceElementString, String cdmAttributeString){
|
50 |
1e21a025
|
Andreas Müller
|
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 |
|
|
* Returns the namespace. If namespace is null, return parentElement namespace
|
69 |
|
|
* @param parentElement
|
70 |
|
|
* @return
|
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 |
1bfab135
|
Andreas Müller
|
public String toString(){
|
107 |
|
|
//TODO
|
108 |
|
|
return this.getSourceElement();
|
109 |
|
|
}
|
110 |
1e21a025
|
Andreas Müller
|
}
|