View Javadoc

1   /**
2   * Copyright (C) 2009 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.eflora;
11  
12  import java.io.InputStream;
13  import java.net.MalformedURLException;
14  import java.net.URL;
15  import java.util.UUID;
16  
17  import org.apache.log4j.Logger;
18  import org.jdom.Element;
19  import org.springframework.stereotype.Component;
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.ImportConfiguratorBase;
25  import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
26  import eu.etaxonomy.cdm.io.eflora.EfloraImportState;
27  import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28  import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29  
30  @Component
31  public class EfloraImportConfigurator extends ImportConfiguratorBase<EfloraImportState> implements IImportConfigurator {
32  	private static final Logger logger = Logger.getLogger(EfloraImportConfigurator.class);
33  	
34  	public static EfloraImportConfigurator NewInstance(String url, ICdmDataSource destination){
35  		return new EfloraImportConfigurator(url, destination);
36  	}
37  	
38  	//TODO
39  	private static IInputTransformer defaultTransformer = null;
40  	private String classificationTitle = "E-Flora Import";
41  	private String sourceReferenceTitle = "E-Flora";
42  	private UUID defaultLanguageUuid;
43  	
44  	//TODO move to state, but a state gets lost after each import.invoke, so I can't move this information
45  	//from the one import to another import in case I run 2 imports in line
46  	private UUID lastTaxonUuid;
47  	
48  	//if true, the keys will be printed after they have been created	
49  	private boolean doPrintKeys = false;
50  
51  	
52  	/* (non-Javadoc)
53  	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#makeIoClassList()
54  	 */
55  	protected void makeIoClassList(){
56  		ioClassList = new Class[]{
57  			EfloraTaxonImport.class
58  		};
59  	};
60  	
61  	protected EfloraImportConfigurator() {
62  		super(defaultTransformer);
63  	}
64  	
65  	
66  	/**
67  	 * 
68  	 */
69  	protected EfloraImportConfigurator(IInputTransformer transformer) {
70  		super(transformer);
71  	}
72  	
73  
74  	/**
75  	 * @param url
76  	 * @param destination
77  	 */
78  	protected EfloraImportConfigurator(String url, ICdmDataSource destination) {
79  		super(defaultTransformer);
80  		setSource(url);
81  		setDestination(destination);
82  	}
83  	
84  	/**
85  	 * @param url
86  	 * @param destination
87  	 */
88  	protected EfloraImportConfigurator(String url, ICdmDataSource destination, IInputTransformer transformer) {
89  		super(transformer);
90  		setSource(url);
91  		setDestination(destination);
92  	}
93  
94  
95  	/* (non-Javadoc)
96  	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
97  	 */
98  	public EfloraImportState getNewState() {
99  		return new EfloraImportState(this);
100 	}
101 
102 	/* (non-Javadoc)
103 	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
104 	 */
105 	public String getSource() {
106 		return (String)super.getSource();
107 	}
108 	
109 	/**
110 	 * @param file
111 	 */
112 	public void setSource(String file) {
113 		super.setSource(file);
114 	}
115 	
116 	/**
117 	 * @return
118 	 */
119 	public Element getSourceRoot(){
120 		String source = getSource();
121 		try {
122 			URL url;
123 			url = new URL(source);
124 			Object o = url.getContent();
125 			InputStream is = (InputStream)o;
126 			Element root = XmlHelp.getRoot(is);
127 //			makeNamespaces(root);
128 			return root;
129 		} catch (MalformedURLException e) {
130 			e.printStackTrace();
131 		}catch (Exception e) {
132 			// TODO Auto-generated catch block
133 			e.printStackTrace();
134 		}
135 		return null;
136 	}
137 	
138 
139 	/* (non-Javadoc)
140 	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
141 	 */
142 	@Override
143 	public ReferenceBase getSourceReference() {
144 		//TODO
145 		if (this.sourceReference == null){
146 			logger.warn("getSource Reference not yet fully implemented");
147 			sourceReference = ReferenceFactory.newGeneric();
148 			sourceReference.setTitleCache(sourceReferenceTitle, true);
149 		}
150 		return sourceReference;
151 	}
152 
153 
154 	/* (non-Javadoc)
155 	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
156 	 */
157 	public String getSourceNameString() {
158 		if (this.getSource() == null){
159 			return null;
160 		}else{
161 			return this.getSource();
162 		}
163 	}
164 
165 	public void setClassificationTitle(String classificationTitle) {
166 		this.classificationTitle = classificationTitle;
167 	}
168 
169 	public String getClassificationTitle() {
170 		return classificationTitle;
171 	}
172 	
173 	
174 
175 	public UUID getLastTaxonUuid() {
176 		return lastTaxonUuid;
177 	}
178 	
179 	public void setLastTaxonUuid(UUID lastTaxonUuid) {
180 		this.lastTaxonUuid = lastTaxonUuid;
181 	}
182 
183 	public void setDoPrintKeys(boolean doPrintKeys) {
184 		this.doPrintKeys = doPrintKeys;
185 	}
186 
187 	public boolean isDoPrintKeys() {
188 		return doPrintKeys;
189 	}
190 
191 	public UUID getDefaultLanguageUuid() {
192 		return this.defaultLanguageUuid;
193 	}
194 
195 	public void setDefaultLanguageUuid(UUID defaultLanguageUuid) {
196 		this.defaultLanguageUuid = defaultLanguageUuid;
197 	}
198 	
199 
200 
201 
202 	
203 }