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.TimeBlockBo;
26 import org.kuali.rice.krad.service.KRADServiceLocator;
27
28 import com.thoughtworks.xstream.XStream;
29 import com.thoughtworks.xstream.io.xml.DomDriver;
30 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
31
32
33
34
35
36 public class TimeBlockSerializerService {
37
38
39
40
41
42
43 public void serializeToXML() throws FileNotFoundException {
44
45 Collection timeBlocks = KRADServiceLocatorWeb.getLegacyDataAdapter()
46 .findAll(TimeBlockBo.class);
47 Iterator<TimeBlockBo> itr = timeBlocks.iterator();
48 while (itr.hasNext()) {
49 TimeBlockBo timeBlockObj = itr.next();
50 XStream xs = new XStream(new DomDriver());
51 FileOutputStream fos;
52
53
54 fos = new FileOutputStream(System.getProperty("user.home")
55 + "\\TimeBlockData.xml", true);
56 xs.toXML(timeBlockObj, fos);
57 }
58
59 }
60
61 public void serializeToCSV() throws FileNotFoundException {
62
63 Collection timeBlocks = KRADServiceLocatorWeb.getLegacyDataAdapter()
64 .findAll(TimeBlockBo.class);
65 Iterator<TimeBlockBo> itr = timeBlocks.iterator();
66 while (itr.hasNext()) {
67
68 TimeBlockBo timeBlockObj = itr.next();
69 try {
70
71 FileWriter fstream = new FileWriter(System.getProperty("user.home")
72 + "\\TimeBlockData.csv", true);
73 BufferedWriter out = new BufferedWriter(fstream);
74 out.write(timeBlockObj.toCSVString());
75
76 out.close();
77 } catch (Exception e) {
78 e.printStackTrace();
79 }
80 }
81
82 }
83
84 }