Project

General

Profile

1 41789 sandro.lab
package eu.dnetlib.data.mdstore.modular;
2
3
import java.io.StringReader;
4
import java.util.HashMap;
5
import java.util.Map;
6
import javax.xml.xpath.XPath;
7
import javax.xml.xpath.XPathFactory;
8
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.xml.sax.InputSource;
12
13
/**
14
 * Terrible implementation of a record parser.
15
 *
16
 * @author marko
17
 */
18
public class SimpleRecordParser implements RecordParser {
19
20
	static final Log log = LogFactory.getLog(SimpleRecordParser.class); // NOPMD by marko on 11/24/08 5:02 PM
21
22
	@Override
23
	public Map<String, String> parseRecord(String record) {
24
		Map<String, String> props = new HashMap<String, String>();
25
26
		try {
27
			//			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
28
			XPath xpath = XPathFactory.newInstance().newXPath();
29
30
			//			Document doc = builder.parse(new InputSource(new StringReader(record)));
31
			InputSource doc = new InputSource(new StringReader(record));
32
33
			props.put("id", xpath.evaluate("//*[local-name()='objIdentifier']", doc));
34
			props.put("originalId", xpath.evaluate("//*[local-name()='efgEntity']/*/*[local-name()='identifier']", doc));
35
36
			//			String date = xpath.evaluate("//*[local-name()='dateOfCollection'][1]", doc);
37
			//			props.put("date", new Date(date).getTime());
38
39
		} catch (Exception e) {
40
			log.warn("got exception while parsing document", e);
41
			log.warn("record is:");
42
			log.warn(record);
43
			log.warn("------------");
44
		}
45
		return props;
46
47
	}
48
49
}