01: package org.theospi.portfolio.reports.model;
02:
03: import org.jdom.Document;
04: import org.jdom.input.SAXBuilder;
05: import org.sakaiproject.content.api.ContentResource;
06:
07: import java.io.ByteArrayInputStream;
08: import java.io.ByteArrayOutputStream;
09: import java.io.IOException;
10: import java.io.InputStream;
11: import java.util.Set;
12:
13: public class ReportDefinitionXmlFile {
14: private String reportDefId = null;
15: private byte[] xmlFile;
16: private Set reportXslFiles;
17: Document xml;
18:
19: public ReportDefinitionXmlFile() {
20: }
21:
22: public ReportDefinitionXmlFile(ContentResource resource) {
23: SAXBuilder builder = new SAXBuilder();
24:
25: try {
26: InputStream in = resource.streamContent();
27: setXmlFile(readStreamToBytes(resource.streamContent()));
28: setXml(builder.build(in));
29: } catch (Exception e) {
30: e.printStackTrace();
31: }
32: }
33:
34: public String getReportDefId() {
35: return reportDefId;
36: }
37:
38: public void setReportDefId(String reportDefId) {
39: this .reportDefId = reportDefId;
40: }
41:
42: public Document getXml() {
43: if (xml == null) {
44: ByteArrayInputStream in = new ByteArrayInputStream(
45: getXmlFile());
46: SAXBuilder builder = new SAXBuilder();
47: try {
48: Document doc = builder.build(in);
49: setXml(doc);
50: } catch (Exception e) {
51:
52: }
53:
54: }
55: return xml;
56: }
57:
58: public void setXml(Document xml) {
59: this .xml = xml;
60: }
61:
62: public byte[] getXmlFile() {
63: return xmlFile;
64: }
65:
66: public void setXmlFile(byte[] xmlFile) {
67: this .xmlFile = xmlFile;
68: }
69:
70: private byte[] readStreamToBytes(InputStream inStream)
71: throws IOException {
72: ByteArrayOutputStream bytes = new ByteArrayOutputStream();
73: byte data[] = new byte[10 * 1024];
74:
75: int count;
76: while ((count = inStream.read(data, 0, 10 * 1024)) != -1) {
77: bytes.write(data, 0, count);
78: }
79: byte[] tmp = bytes.toByteArray();
80: bytes.close();
81: return tmp;
82: }
83:
84: public Set getReportXslFiles() {
85: return reportXslFiles;
86: }
87:
88: public void setReportXslFiles(Set reportXslFiles) {
89: this.reportXslFiles = reportXslFiles;
90: }
91: }
|