Revision 27f9f715
Added by Andreas Müller almost 2 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDImportConfigurator.java | ||
---|---|---|
1 |
/** |
|
2 |
* 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 |
|
|
10 |
package eu.etaxonomy.cdm.io.sdd.in; |
|
11 |
|
|
12 |
import java.io.InputStream; |
|
13 |
import java.net.MalformedURLException; |
|
14 |
import eu.etaxonomy.cdm.common.URI; |
|
15 |
import java.net.URL; |
|
16 |
|
|
17 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
18 |
import org.jdom.Element; |
|
19 |
import org.jdom.Namespace; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.common.XmlHelp; |
|
22 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
23 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator; |
|
24 |
import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator; |
|
25 |
import eu.etaxonomy.cdm.io.common.XmlImportConfiguratorBase; |
|
26 |
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer; |
|
27 |
import eu.etaxonomy.cdm.io.sdd.SDDTransformer; |
|
28 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
29 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author h.fradin |
|
33 |
* @since 24.10.2008 |
|
34 |
*/ |
|
35 |
public class SDDImportConfigurator extends XmlImportConfiguratorBase<SDDImportState> implements IImportConfigurator, IMatchingImportConfigurator { |
|
36 |
private static final long serialVersionUID = -960998183005112130L; |
|
37 |
|
|
38 |
private static final Logger logger = LogManager.getLogger(SDDImportConfigurator.class); |
|
39 |
|
|
40 |
//TODO |
|
41 |
private static IInputTransformer defaultTransformer = new SDDTransformer(); |
|
42 |
|
|
43 |
private boolean doMatchTaxa = true; |
|
44 |
|
|
45 |
//xml xmlNamespace |
|
46 |
Namespace sddNamespace; |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void makeIoClassList(){ |
|
50 |
ioClassList = new Class[]{ |
|
51 |
SDDImport.class |
|
52 |
}; |
|
53 |
}; |
|
54 |
|
|
55 |
public static SDDImportConfigurator NewInstance(URI uri, ICdmDataSource destination){ |
|
56 |
return new SDDImportConfigurator(uri, destination); |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
/** |
|
61 |
* @param berlinModelSource |
|
62 |
* @param sourceReference |
|
63 |
* @param destination |
|
64 |
*/ |
|
65 |
private SDDImportConfigurator(URI uri, ICdmDataSource destination) { |
|
66 |
super(defaultTransformer); |
|
67 |
setSource(uri); |
|
68 |
setDestination(destination); |
|
69 |
} |
|
70 |
|
|
71 |
|
|
72 |
@Override |
|
73 |
public SDDImportState getNewState() { |
|
74 |
return new SDDImportState(this); |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
/** |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
public Element getSourceRoot(){ |
|
82 |
try { |
|
83 |
URL url; |
|
84 |
url = getSource().toURL(); |
|
85 |
Object o = url.getContent(); |
|
86 |
InputStream is = (InputStream)o; |
|
87 |
Element root = XmlHelp.getRoot(is); |
|
88 |
makeNamespaces(root); |
|
89 |
return root; |
|
90 |
} catch (MalformedURLException e) { |
|
91 |
e.printStackTrace(); |
|
92 |
}catch (Exception e) { |
|
93 |
// TODO Auto-generated catch block |
|
94 |
e.printStackTrace(); |
|
95 |
} |
|
96 |
return null; |
|
97 |
} |
|
98 |
|
|
99 |
private boolean makeNamespaces(Element root){ |
|
100 |
sddNamespace = root.getNamespace(); |
|
101 |
return true; |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public Reference getSourceReference() { |
|
106 |
//TODO |
|
107 |
if (this.sourceReference == null){ |
|
108 |
logger.warn("getSource Reference not yet fully implemented"); |
|
109 |
sourceReference = ReferenceFactory.newDatabase(); |
|
110 |
sourceReference.setTitleCache("XXX", true); |
|
111 |
} |
|
112 |
return sourceReference; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public String getSourceNameString() { |
|
117 |
if (this.getSource() == null){ |
|
118 |
return null; |
|
119 |
}else{ |
|
120 |
return this.getSource().toString(); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
public Namespace getSddNamespace() { |
|
125 |
return sddNamespace; |
|
126 |
} |
|
127 |
|
|
128 |
public void setSddNamespace(Namespace xmlNamespace) { |
|
129 |
this.sddNamespace = xmlNamespace; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* @param doMatchTaxa the doMatchTaxa to set |
|
134 |
*/ |
|
135 |
@Override |
|
136 |
public void setReuseExistingTaxaWhenPossible(boolean doMatchTaxa) { |
|
137 |
this.doMatchTaxa = doMatchTaxa; |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* @return the doMatchTaxa |
|
142 |
*/ |
|
143 |
@Override |
|
144 |
public boolean isReuseExistingTaxaWhenPossible() { |
|
145 |
return doMatchTaxa; |
|
146 |
} |
|
147 |
} |
|
1 |
/** |
|
2 |
* 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 |
|
|
10 |
package eu.etaxonomy.cdm.io.sdd.in; |
|
11 |
|
|
12 |
import java.io.InputStream; |
|
13 |
import java.net.MalformedURLException; |
|
14 |
import java.net.URL; |
|
15 |
|
|
16 |
import org.apache.logging.log4j.LogManager; |
|
17 |
import org.apache.logging.log4j.Logger; |
|
18 |
import org.jdom.Element; |
|
19 |
import org.jdom.Namespace; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.common.URI; |
|
22 |
import eu.etaxonomy.cdm.common.XmlHelp; |
|
23 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
24 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator; |
|
25 |
import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator; |
|
26 |
import eu.etaxonomy.cdm.io.common.XmlImportConfiguratorBase; |
|
27 |
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer; |
|
28 |
import eu.etaxonomy.cdm.io.sdd.SDDTransformer; |
|
29 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
30 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author h.fradin |
|
34 |
* @since 24.10.2008 |
|
35 |
*/ |
|
36 |
public class SDDImportConfigurator extends XmlImportConfiguratorBase<SDDImportState> |
|
37 |
implements IImportConfigurator, IMatchingImportConfigurator { |
|
38 |
|
|
39 |
private static final long serialVersionUID = -960998183005112130L; |
|
40 |
private static final Logger logger = LogManager.getLogger(SDDImportConfigurator.class); |
|
41 |
|
|
42 |
//TODO |
|
43 |
private static IInputTransformer defaultTransformer = new SDDTransformer(); |
|
44 |
|
|
45 |
private boolean doMatchTaxa = true; |
|
46 |
|
|
47 |
//xml xmlNamespace |
|
48 |
Namespace sddNamespace; |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void makeIoClassList(){ |
|
52 |
ioClassList = new Class[]{ |
|
53 |
SDDImport.class |
|
54 |
}; |
|
55 |
}; |
|
56 |
|
|
57 |
public static SDDImportConfigurator NewInstance(URI uri, ICdmDataSource destination){ |
|
58 |
return new SDDImportConfigurator(uri, destination); |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
/** |
|
63 |
* @param berlinModelSource |
|
64 |
* @param sourceReference |
|
65 |
* @param destination |
|
66 |
*/ |
|
67 |
private SDDImportConfigurator(URI uri, ICdmDataSource destination) { |
|
68 |
super(defaultTransformer); |
|
69 |
setSource(uri); |
|
70 |
setDestination(destination); |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
@Override |
|
75 |
public SDDImportState getNewState() { |
|
76 |
return new SDDImportState(this); |
|
77 |
} |
|
78 |
|
|
79 |
|
|
80 |
/** |
|
81 |
* @return |
|
82 |
*/ |
|
83 |
public Element getSourceRoot(){ |
|
84 |
try { |
|
85 |
URL url; |
|
86 |
url = getSource().toURL(); |
|
87 |
Object o = url.getContent(); |
|
88 |
InputStream is = (InputStream)o; |
|
89 |
Element root = XmlHelp.getRoot(is); |
|
90 |
makeNamespaces(root); |
|
91 |
return root; |
|
92 |
} catch (MalformedURLException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
}catch (Exception e) { |
|
95 |
// TODO Auto-generated catch block |
|
96 |
e.printStackTrace(); |
|
97 |
} |
|
98 |
return null; |
|
99 |
} |
|
100 |
|
|
101 |
private boolean makeNamespaces(Element root){ |
|
102 |
sddNamespace = root.getNamespace(); |
|
103 |
return true; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public Reference getSourceReference() { |
|
108 |
//TODO |
|
109 |
if (this.sourceReference == null){ |
|
110 |
logger.warn("getSource Reference not yet fully implemented"); |
|
111 |
sourceReference = ReferenceFactory.newDatabase(); |
|
112 |
sourceReference.setTitleCache("XXX", true); |
|
113 |
} |
|
114 |
return sourceReference; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public String getSourceNameString() { |
|
119 |
if (this.getSource() == null){ |
|
120 |
return null; |
|
121 |
}else{ |
|
122 |
return this.getSource().toString(); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
public Namespace getSddNamespace() { |
|
127 |
return sddNamespace; |
|
128 |
} |
|
129 |
|
|
130 |
public void setSddNamespace(Namespace xmlNamespace) { |
|
131 |
this.sddNamespace = xmlNamespace; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* @param doMatchTaxa the doMatchTaxa to set |
|
136 |
*/ |
|
137 |
@Override |
|
138 |
public void setReuseExistingTaxaWhenPossible(boolean doMatchTaxa) { |
|
139 |
this.doMatchTaxa = doMatchTaxa; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* @return the doMatchTaxa |
|
144 |
*/ |
|
145 |
@Override |
|
146 |
public boolean isReuseExistingTaxaWhenPossible() { |
|
147 |
return doMatchTaxa; |
|
148 |
} |
|
149 |
} |
Also available in: Unified diff
cleanup and javadoc