1 package org.kuali.ole.docstore.common.search;
2
3
4 import org.apache.log4j.Logger;
5
6 import javax.xml.bind.JAXBContext;
7 import javax.xml.bind.JAXBElement;
8 import javax.xml.bind.Marshaller;
9 import javax.xml.bind.Unmarshaller;
10 import javax.xml.bind.annotation.XmlAccessType;
11 import javax.xml.bind.annotation.XmlAccessorType;
12 import javax.xml.bind.annotation.XmlRootElement;
13 import javax.xml.bind.annotation.XmlType;
14 import javax.xml.transform.stream.StreamSource;
15 import java.io.ByteArrayInputStream;
16 import java.io.StringWriter;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @XmlAccessorType(XmlAccessType.FIELD)
39 @XmlType(name = "browseParams", propOrder = {
40 "totalCount"
41 })
42 @XmlRootElement
43 public class BrowseParams
44 extends SearchParams
45 {
46 private static final Logger LOG = Logger.getLogger(BrowseParams.class);
47 protected long totalCount;
48
49
50
51
52
53 public long getTotalCount() {
54 return totalCount;
55 }
56
57
58
59
60
61 public void setTotalCount(long value) {
62 this.totalCount = value;
63 }
64
65 @Override
66 public String serialize(Object object) {
67 String result = null;
68 StringWriter sw = new StringWriter();
69 BrowseParams browseParams = (BrowseParams) object;
70 try {
71 JAXBContext jaxbContext = JAXBContext.newInstance(BrowseParams.class);
72 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
73 jaxbMarshaller.marshal(browseParams, sw);
74 result = sw.toString();
75 } catch (Exception e) {
76 LOG.error("Exception ", e);
77 }
78 return result;
79 }
80
81 @Override
82 public Object deserialize(String content) {
83
84 JAXBElement<BrowseParams> browseParamsElement = null;
85 try {
86 JAXBContext jaxbContext = JAXBContext.newInstance(BrowseParams.class);
87 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
88 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
89 browseParamsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input),BrowseParams.class);
90 } catch (Exception e) {
91 LOG.error("Exception ", e);
92 }
93 return browseParamsElement.getValue();
94 }
95
96 }