Project

General

Profile

« Previous | Next » 

Revision c95e3daf

Added by Patrick Plitzner almost 9 years ago

Move unit parsing to utility class

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
9 9

  
10 10
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
11 11

  
12
import java.io.InputStream;
13 12
import java.net.MalformedURLException;
14 13
import java.util.ArrayList;
15 14
import java.util.HashMap;
......
19 18
import java.util.Set;
20 19
import java.util.UUID;
21 20

  
22
import javax.xml.parsers.DocumentBuilder;
23
import javax.xml.parsers.DocumentBuilderFactory;
24

  
25 21
import org.apache.commons.lang.StringUtils;
26 22
import org.apache.log4j.Logger;
27 23
import org.springframework.stereotype.Component;
28
import org.w3c.dom.Document;
29 24
import org.w3c.dom.Element;
30 25
import org.w3c.dom.NodeList;
31 26

  
......
214 209
            }
215 210
        }
216 211

  
217
        InputStream source = state.getConfig().getSource();
218
        NodeList unitsList = getUnitsNodeList(source);
212
        NodeList unitsList = AbcdParseUtility.getUnitsNodeList(state);
213
        prefix = AbcdParseUtility.getPrefix(state);
219 214

  
220 215
        if (unitsList != null) {
221 216
            String message = "nb units to insert: " + unitsList.getLength();
......
299 294
        return;
300 295
    }
301 296

  
302
    /**
303
     * Return the list of root nodes for an ABCD 2.06 XML file
304
     * @param fileName: the file's location
305
     * @return the list of root nodes ("Unit")
306
     */
307
    protected NodeList getUnitsNodeList(InputStream inputStream) {
308
        NodeList unitList = null;
309
        try {
310
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
311
            DocumentBuilder builder = factory.newDocumentBuilder();
312

  
313
            Document document = builder.parse(inputStream);
314
            Element root = document.getDocumentElement();
315
            unitList = root.getElementsByTagName("Unit");
316
            if (unitList.getLength() == 0) {
317
                unitList = root.getElementsByTagName("abcd:Unit");
318
                prefix = "abcd:";
319
            }
320
            if (unitList.getLength() == 0) {
321
                unitList = root.getElementsByTagName("abcd21:Unit");
322
                prefix = "abcd21:";
323
            }
324
        } catch (Exception e) {
325
            logger.warn(e);
326
        }
327
        return unitList;
328
    }
329

  
330 297
    /**
331 298
     * Handle a single unit
332 299
     * @param state

Also available in: Unified diff