Revision 47517
Added by Alessia Bardi almost 7 years ago
IndexFieldRecordParser.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.mdstore.modular.mongodb.utils; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
|
|
3 | 8 |
import com.ximpleware.AutoPilot; |
4 | 9 |
import com.ximpleware.VTDGen; |
5 | 10 |
import com.ximpleware.VTDNav; |
... | ... | |
7 | 12 |
import org.apache.commons.logging.Log; |
8 | 13 |
import org.apache.commons.logging.LogFactory; |
9 | 14 |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 | 15 |
/** |
16 | 16 |
* Created by sandro on 11/29/16. |
17 | 17 |
*/ |
... | ... | |
19 | 19 |
|
20 | 20 |
private static final Log log = LogFactory.getLog(IndexFieldRecordParser.class); |
21 | 21 |
|
22 |
public static List<String> getTextValue(final AutoPilot ap, final VTDNav vn, final String xpath) throws Exception {
|
|
22 |
private static List<String> getTextValue(final AutoPilot ap, final VTDNav vn, final String xpath) throws Exception {
|
|
23 | 23 |
List<String> results = new ArrayList<>(); |
24 | 24 |
ap.selectXPath(xpath); |
25 | 25 |
while (ap.evalXPath() != -1) { |
... | ... | |
29 | 29 |
return results; |
30 | 30 |
} |
31 | 31 |
|
32 |
public Map<String, List<String>> parseRecord(final String record, final List<MDFormatDescription> mdformats) { |
|
32 |
public Map<String, List<String>> parseRecord(final String record, final List<MDFormatDescription> mdformats) throws IndexFieldRecordParserException {
|
|
33 | 33 |
if (mdformats == null || mdformats.size() == 0) |
34 | 34 |
return null; |
35 | 35 |
final Map<String, List<String>> result = new HashMap<>(); |
... | ... | |
46 | 46 |
result.put(description.getName(), xpathResult); |
47 | 47 |
} |
48 | 48 |
return result; |
49 |
|
|
50 | 49 |
} catch (Throwable e) { |
51 |
log.error("Error on parsing record " + record, e);
|
|
50 |
throw new IndexFieldRecordParserException("Cannot index record", e);
|
|
52 | 51 |
} |
53 |
return result; |
|
54 | 52 |
} |
55 | 53 |
|
56 | 54 |
|
Also available in: Unified diff
Stroing in mdstore fails if the VTD Parser cannot properly apply the xpaths on records to index