Minor bugs fixed
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / sdd / 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;
11
12 import java.io.InputStream;
13 import java.net.MalformedURLException;
14 import java.net.URL;
15
16 import org.apache.log4j.Logger;
17 import org.jdom.Element;
18 import org.jdom.Namespace;
19
20 import eu.etaxonomy.cdm.common.XmlHelp;
21 import eu.etaxonomy.cdm.database.ICdmDataSource;
22 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
23 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
24 import eu.etaxonomy.cdm.io.common.ImportStateBase;
25 import eu.etaxonomy.cdm.model.reference.IDatabase;
26 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28
29 /**
30 * @author h.fradin
31 * @created 24.10.2008
32 * @version 1.0
33 */
34 public class SDDImportConfigurator extends ImportConfiguratorBase implements IImportConfigurator {
35 private static final Logger logger = Logger.getLogger(SDDImportConfigurator.class);
36
37 //xml xmlNamespace
38 Namespace sddNamespace;
39
40 protected void makeIoClassList(){
41 ioClassList = new Class[]{
42 SDDDescriptionIO.class
43 };
44 };
45
46 public static SDDImportConfigurator NewInstance(String url,
47 ICdmDataSource destination){
48 return new SDDImportConfigurator(url, destination);
49 }
50
51
52 /**
53 * @param berlinModelSource
54 * @param sourceReference
55 * @param destination
56 */
57 private SDDImportConfigurator(String url, ICdmDataSource destination) {
58 super();
59 setSource(url);
60 setDestination(destination);
61 }
62
63
64
65
66 /* (non-Javadoc)
67 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
68 */
69 public SDDImportState getNewState() {
70 return new SDDImportState(this);
71 }
72
73 /* (non-Javadoc)
74 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
75 */
76 public String getSource() {
77 return (String)super.getSource();
78 }
79
80 /**
81 * @param file
82 */
83 public void setSource(String file) {
84 super.setSource(file);
85 }
86
87 /**
88 * @return
89 */
90 public Element getSourceRoot(){
91 String source = getSource();
92 try {
93 URL url;
94 url = new URL(source);
95 Object o = url.getContent();
96 InputStream is = (InputStream)o;
97 Element root = XmlHelp.getRoot(is);
98 makeNamespaces(root);
99 return root;
100 } catch (MalformedURLException e) {
101 e.printStackTrace();
102 }catch (Exception e) {
103 // TODO Auto-generated catch block
104 e.printStackTrace();
105 }
106 return null;
107 }
108
109 private boolean makeNamespaces(Element root){
110 sddNamespace = root.getNamespace();
111 return true;
112 }
113
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
117 */
118 @Override
119 public ReferenceBase getSourceReference() {
120 //TODO
121 if (this.sourceReference == null){
122 logger.warn("getSource Reference not yet fully implemented");
123 ReferenceFactory refFactory = ReferenceFactory.newInstance();
124 sourceReference = refFactory.newDatabase();
125 sourceReference.setTitleCache("XXX");
126 }
127 return sourceReference;
128 }
129
130
131 /* (non-Javadoc)
132 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
133 */
134 public String getSourceNameString() {
135 if (this.getSource() == null){
136 return null;
137 }else{
138 return this.getSource();
139 }
140 }
141
142 public Namespace getSddNamespace() {
143 return sddNamespace;
144 }
145
146 public void setSddNamespace(Namespace xmlNamespace) {
147 this.sddNamespace = xmlNamespace;
148 }
149 }