blob: 3d04a038f931e7cc0766a4d69b09ffd3e20f628a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package design.persistence;
import java.io.File;
import java.io.IOException;
import design.model.DataHandler;
import com.fasterxml.jackson.databind.ObjectMapper;
import design.model.Golfer;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class XMLParser implements DataHandler
{
private final ObjectMapper jsonMapper = new ObjectMapper();
private final XmlMapper xmlMapper = new XmlMapper();
public void exportPersonalData(File fileName) throws IOException {
File jsonData = JSONPersonalDatabase.instance().exportData();
Golfer[] golfers = jsonMapper.readValue(jsonData, Golfer[].class);
File xmlFile = new File(fileName + ".xml");
xmlMapper.writerWithDefaultPrettyPrinter().writeValue(xmlFile, golfers);
}
public void importPersonalData(File fileName) throws IOException {
Golfer[] golfers = xmlMapper.readValue(fileName, Golfer[].class);
File tempJson = File.createTempFile("imported", ".json");
jsonMapper.writerWithDefaultPrettyPrinter().writeValue(tempJson, golfers);
JSONPersonalDatabase.instance().importData(tempJson);
tempJson.delete();
}
public void exportLeagueData(File fileName)
{
// TO DO: exporting league data
}
public void importLeagueData(File fileName)
{
// TO DO: importing league data
}
}
|