1 package org.kuali.ole.ingest;
2
3 import com.thoughtworks.xstream.XStream;
4 import org.kuali.ole.ingest.pojo.OleLocationGroup;
5 import org.kuali.ole.ingest.pojo.OleLocationIngest;
6
7 import java.io.IOException;
8 import java.net.URISyntaxException;
9 import java.util.List;
10
11
12
13
14
15 public class OleLocationObjectGeneratorFromXML {
16
17
18
19
20
21
22
23
24 public OleLocationGroup buildLocationFromFileContent(String fileContent) throws URISyntaxException, IOException {
25
26 XStream xStream = new XStream();
27 xStream.alias("locationGroup", OleLocationGroup.class);
28 xStream.alias("location", OleLocationIngest.class);
29 xStream.addImplicitCollection(OleLocationGroup.class,"locationGroup");
30 Object object = xStream.fromXML(fileContent);
31 return (OleLocationGroup)object;
32 }
33
34
35
36
37
38
39
40
41
42 public String toXML(List<OleLocationIngest> oleLocationIngestList) throws URISyntaxException, IOException {
43
44 StringBuffer stringBuffer = new StringBuffer();
45 stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<locationGroup xmlns=\"http://ole.kuali.org/standards/ole-location\">");
46 stringBuffer.append("\n");
47 for(OleLocationIngest oleLocationIngest : oleLocationIngestList){
48 XStream xStream = new XStream();
49 xStream.alias("location", OleLocationIngest.class);
50 xStream.addImplicitCollection(OleLocationGroup.class,"locationGroup");
51 String xml = xStream.toXML(oleLocationIngest);
52 stringBuffer.append(xml);
53 stringBuffer.append("\n");
54 }
55 stringBuffer.append("</locationGroup>");
56 return stringBuffer.toString();
57 }
58 }