Project

General

Profile

1
package edu.ucsb.nceas.metacat.index;
2

    
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileReader;
6
import java.io.IOException;
7
import java.util.ArrayList;
8
import java.util.List;
9

    
10
/**
11
 * Read field definitions from a file. Replacement for Spring-based config used in DataONE.
12
 * Presently uses csv-style text which is primitive and fragile; should probably be some
13
 * sort of xml to be properly javaee-esque. It's possible to use Spring configuration info
14
 * directly, but the parsing and evaluation involved is non-trivial, even though the data
15
 * involved is really quite simple. Thus at present our config info has been manually
16
 * generated in this format, based on the DataONE indexer's definitions.
17
 *
18
 * Oh Java, when will you get a decent object syntax?
19
 */
20
public class FieldDefReader {
21
	public static List<FieldSpec> read(File f) {
22
		ArrayList<FieldSpec> specs = new ArrayList<FieldSpec>(20);
23
		try {
24
			BufferedReader r = new BufferedReader(new FileReader(f));
25
			String s;
26
			while ((s = r.readLine()) != null) {
27
				String[] def = s.split(" ");
28
				D1IndexField.DataFormat df = D1IndexField.DataFormat.SINGLE;
29
				if (def[2].equals("set")) df = D1IndexField.DataFormat.SET;
30
				else if (def[2].equals("multi")) df = D1IndexField.DataFormat.MULTISET;
31
				D1IndexField.Conversion dc = D1IndexField.Conversion.NONE;
32
				if (def[3].equals("date")) dc = D1IndexField.Conversion.DATE;
33
				else if (def[3].equals("fgdc")) dc = D1IndexField.Conversion.FGDCDATE;
34
				else if (def[3].equals("lat")) dc = D1IndexField.Conversion.LATITUDE;
35
				else if (def[3].equals("lon")) dc = D1IndexField.Conversion.LONGITUDE;
36
				specs.add(new D1IndexField(def[0], def[1], df, dc));
37
			}
38
			r.close();
39
		} catch (IOException e) {
40
			// TODO: logs
41
			e.printStackTrace();
42
		}
43
		return specs;
44
	}
45
}
(5-5/14)