1 /*
2 * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3 * Copyright (C) 2010 Mickael Guessant
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 package davmail.exchange.ews;
20
21 import davmail.util.StringUtil;
22
23 /**
24 * Two operand expression.
25 */
26 public class TwoOperandExpression implements SearchExpression {
27 @SuppressWarnings({"UnusedDeclaration"})
28 protected enum Operator {
29 IsEqualTo, IsNotEqualTo, IsGreaterThan, IsGreaterThanOrEqualTo, IsLessThan, IsLessThanOrEqualTo
30 }
31
32 protected final Operator operator;
33 protected final FieldURI fieldURI;
34 protected final String value;
35
36 /**
37 * Create two operand expression.
38 *
39 * @param operator operator
40 * @param fieldURI field operand
41 * @param value value operand
42 */
43 public TwoOperandExpression(Operator operator, FieldURI fieldURI, String value) {
44 this.operator = operator;
45 this.fieldURI = fieldURI;
46 this.value = value;
47 }
48
49 public void appendTo(StringBuilder buffer) {
50 buffer.append("<t:").append(operator.toString()).append('>');
51 fieldURI.appendTo(buffer);
52
53 buffer.append("<t:FieldURIOrConstant><t:Constant Value=\"");
54 // encode urlcompname
55 if (fieldURI instanceof ExtendedFieldURI && "0x10f3".equals(((ExtendedFieldURI) fieldURI).propertyTag)) {
56 buffer.append(StringUtil.xmlEncodeAttribute(StringUtil.encodeUrlcompname(value)));
57 } else {
58 buffer.append(StringUtil.xmlEncodeAttribute(value));
59 }
60 buffer.append("\"/></t:FieldURIOrConstant>");
61
62 buffer.append("</t:").append(operator.toString()).append('>');
63 }
64
65 }