Project

General

Profile

« Previous | Next » 

Revision 64c9b080

Added by Andreas Müller almost 11 years ago

fix ABCD import

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
12 12
import java.io.InputStream;
13 13
import java.net.MalformedURLException;
14 14
import java.net.URI;
15
import java.net.URL;
16 15
import java.util.ArrayList;
17 16
import java.util.HashMap;
18 17
import java.util.HashSet;
......
33 32

  
34 33
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
35 34
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
35
import eu.etaxonomy.cdm.common.UriUtils;
36 36
import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;
37 37
import eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction;
38 38
import eu.etaxonomy.cdm.io.specimen.UnitsGatheringArea;
......
206 206
            }
207 207
        }
208 208

  
209
        URI sourceName = state.getConfig().getSource();
210
        NodeList unitsList = getUnitsNodeList(sourceName);
209
        InputStream source = state.getConfig().getSource();
210
        NodeList unitsList = getUnitsNodeList(source);
211 211

  
212 212
        if (unitsList != null) {
213 213
            String message = "nb units to insert: " + unitsList.getLength();
......
240 240
    }
241 241

  
242 242

  
243
    protected NodeList getUnitsNodeList(URI source) {
244
        try {
245
        	InputStream is = UriUtils.getInputStream(source);
246
            return getUnitsNodeList(is);
247
        } catch (Exception e) {
248
            logger.warn(e);
249
            throw new RuntimeException(e);
250
        }
251
    }
252
    
243 253
    /**
244 254
     * Return the list of root nodes for an ABCD 2.06 XML file
245 255
     * @param fileName: the file's location
246 256
     * @return the list of root nodes ("Unit")
247 257
     */
248
    protected NodeList getUnitsNodeList(URI urlFileName) {
258
    protected NodeList getUnitsNodeList(InputStream inputStream) {
249 259
        NodeList unitList = null;
250 260
        try {
251 261
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
252 262
            DocumentBuilder builder = factory.newDocumentBuilder();
253
            URL url = urlFileName.toURL();
254
            Object o = url.getContent();
255
            InputStream is = (InputStream) o;
256
            Document document = builder.parse(is);
263
 
264
            Document document = builder.parse(inputStream);
257 265
            Element root = document.getDocumentElement();
258 266
            unitList = root.getElementsByTagName("Unit");
259 267
            if (unitList.getLength() == 0) {
......
378 386
     */
379 387
    private void save(CdmBase cdmBase, Abcd206ImportState state) {
380 388
		ICdmApplicationConfiguration cdmRepository = state.getConfig().getCdmAppController();
389
		if (cdmRepository == null){
390
			cdmRepository = this;
391
		}
381 392
		
382 393
		if (cdmBase.isInstanceOf(LanguageString.class)){
383 394
			cdmRepository.getTermService().saveLanguageData(CdmBase.deproxy(cdmBase, LanguageString.class));

Also available in: Unified diff