1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.scheduler;
17
18 import java.io.BufferedWriter;
19 import java.io.FileNotFoundException;
20 import java.io.FileOutputStream;
21 import java.io.FileWriter;
22 import java.util.Collection;
23 import java.util.Iterator;
24
25 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
26 import org.kuali.rice.krad.service.KRADServiceLocator;
27
28 import com.thoughtworks.xstream.XStream;
29 import com.thoughtworks.xstream.io.xml.DomDriver;
30
31
32
33
34
35 public class TimeBlockSerializerService {
36
37
38
39
40
41
42 public void serializeToXML() throws FileNotFoundException {
43
44 Collection timeBlocks = KRADServiceLocator.getBusinessObjectService()
45 .findAll(TimeBlock.class);
46 Iterator<TimeBlock> itr = timeBlocks.iterator();
47 while (itr.hasNext()) {
48 TimeBlock timeBlockObj = itr.next();
49 XStream xs = new XStream(new DomDriver());
50 FileOutputStream fos;
51
52
53 fos = new FileOutputStream(System.getProperty("user.home")
54 + "\\TimeBlockData.xml", true);
55 xs.toXML(timeBlockObj, fos);
56 }
57
58 }
59
60 public void serializeToCSV() throws FileNotFoundException {
61
62 Collection timeBlocks = KRADServiceLocator.getBusinessObjectService()
63 .findAll(TimeBlock.class);
64 Iterator<TimeBlock> itr = timeBlocks.iterator();
65 while (itr.hasNext()) {
66
67 TimeBlock timeBlockObj = itr.next();
68 try {
69
70 FileWriter fstream = new FileWriter(System.getProperty("user.home")
71 + "\\TimeBlockData.csv", true);
72 BufferedWriter out = new BufferedWriter(fstream);
73 out.write(timeBlockObj.toCSVString());
74
75 out.close();
76 } catch (Exception e) {
77 e.printStackTrace();
78 }
79 }
80
81 }
82
83 }