Revision c95e3daf
Added by Patrick Plitzner almost 9 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdParseUtility.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.io.specimen.abcd206.in; |
11 | 11 |
|
12 |
import java.io.InputStream; |
|
12 | 13 |
import java.net.URI; |
13 | 14 |
import java.util.Date; |
14 | 15 |
|
16 |
import javax.xml.parsers.DocumentBuilder; |
|
17 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
18 |
|
|
15 | 19 |
import org.apache.log4j.Logger; |
16 | 20 |
import org.joda.time.DateTime; |
21 |
import org.w3c.dom.Document; |
|
22 |
import org.w3c.dom.Element; |
|
17 | 23 |
import org.w3c.dom.Node; |
18 | 24 |
import org.w3c.dom.NodeList; |
19 | 25 |
|
... | ... | |
96 | 102 |
return date; |
97 | 103 |
} |
98 | 104 |
|
105 |
/** |
|
106 |
* Return the list of root nodes for an ABCD XML file |
|
107 |
* @param fileName: the file's location |
|
108 |
* @return the list of root nodes ("Unit") |
|
109 |
*/ |
|
110 |
public static NodeList getUnitsNodeList(Abcd206ImportState state) { |
|
111 |
InputStream inputStream = state.getConfig().getSource(); |
|
112 |
NodeList unitList = null; |
|
113 |
try { |
|
114 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
|
115 |
DocumentBuilder builder = factory.newDocumentBuilder(); |
|
116 |
|
|
117 |
Document document = builder.parse(inputStream); |
|
118 |
Element root = document.getDocumentElement(); |
|
119 |
unitList = root.getElementsByTagName("Unit"); |
|
120 |
if (unitList.getLength() == 0) { |
|
121 |
unitList = root.getElementsByTagName("abcd:Unit"); |
|
122 |
} |
|
123 |
if (unitList.getLength() == 0) { |
|
124 |
unitList = root.getElementsByTagName("abcd21:Unit"); |
|
125 |
} |
|
126 |
} catch (Exception e) { |
|
127 |
logger.warn(e); |
|
128 |
} |
|
129 |
return unitList; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Return the prefix an ABCD XML file |
|
134 |
* @param fileName: the file's location |
|
135 |
* @return the prefix |
|
136 |
*/ |
|
137 |
public static String getPrefix(Abcd206ImportState state) { |
|
138 |
InputStream inputStream = state.getConfig().getSource(); |
|
139 |
NodeList unitList = null; |
|
140 |
try { |
|
141 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
|
142 |
DocumentBuilder builder = factory.newDocumentBuilder(); |
|
143 |
|
|
144 |
Document document = builder.parse(inputStream); |
|
145 |
Element root = document.getDocumentElement(); |
|
146 |
unitList = root.getElementsByTagName("Unit"); |
|
147 |
if (unitList.getLength()>0) { |
|
148 |
return null; |
|
149 |
} |
|
150 |
unitList = root.getElementsByTagName("abcd:Unit"); |
|
151 |
if (unitList.getLength()>0) { |
|
152 |
return "abcd:"; |
|
153 |
} |
|
154 |
unitList = root.getElementsByTagName("abcd21:Unit"); |
|
155 |
if (unitList.getLength() == 0) { |
|
156 |
return "abcd21:"; |
|
157 |
} |
|
158 |
} catch (Exception e) { |
|
159 |
logger.warn(e); |
|
160 |
} |
|
161 |
return null; |
|
162 |
} |
|
163 |
|
|
99 | 164 |
} |
Also available in: Unified diff
Move unit parsing to utility class