1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package davmail.http.request;
21
22 import davmail.util.StringUtil;
23 import org.apache.log4j.Logger;
24
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.OutputStreamWriter;
28 import java.nio.charset.StandardCharsets;
29
30
31
32
33
34 public class ExchangeSearchRequest extends ExchangeDavRequest {
35 protected static final Logger LOGGER = Logger.getLogger(ExchangeSearchRequest.class);
36
37 protected final String searchRequest;
38
39
40
41
42
43
44
45 public ExchangeSearchRequest(String uri, String searchRequest) {
46 super(uri);
47 this.searchRequest = searchRequest;
48 }
49
50 protected byte[] generateRequestContent() {
51 try {
52
53 ByteArrayOutputStream baos = new ByteArrayOutputStream();
54 try (OutputStreamWriter writer = new OutputStreamWriter(baos, StandardCharsets.UTF_8)) {
55 writer.write("<?xml version=\"1.0\"?>\n");
56 writer.write("<d:searchrequest xmlns:d=\"DAV:\">\n");
57 writer.write(" <d:sql>");
58 writer.write(StringUtil.xmlEncode(searchRequest));
59 writer.write("</d:sql>\n");
60 writer.write("</d:searchrequest>");
61 }
62 return baos.toByteArray();
63 } catch (IOException e) {
64 throw new RuntimeException(e);
65 }
66
67 }
68
69 @Override
70 public String getMethod() {
71 return "SEARCH";
72 }
73
74 }