EWS: implement basic SearchExpression restriction

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1064 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-05-26 21:40:08 +00:00
parent 4e90f26772
commit 81e47e93b2
3 changed files with 126 additions and 2 deletions

View File

@ -58,6 +58,9 @@ public abstract class EWSMethod extends PostMethod {
protected String errorDetail;
protected Item item;
protected SearchExpression searchExpression;
/**
* Build EWS method
*/
@ -118,6 +121,10 @@ public abstract class EWSMethod extends PostMethod {
additionalProperties.add(additionalProperty);
}
protected void setSearchExpression(SearchExpression searchExpression) {
this.searchExpression = searchExpression;
}
protected void writeShape(Writer writer) throws IOException {
if (baseShape != null) {
writer.write("<m:");
@ -158,9 +165,17 @@ public abstract class EWSMethod extends PostMethod {
protected void writeParentFolderId(Writer writer) throws IOException {
if (parentFolderId != null) {
writer.write("<m:ParentFolderId");if (item == null) {writer.write("s");}writer.write(">");
writer.write("<m:ParentFolderId");
if (item == null) {
writer.write("s");
}
writer.write(">");
parentFolderId.write(writer);
writer.write("</m:ParentFolderId");if (item == null) {writer.write("s");}writer.write(">");
writer.write("</m:ParentFolderId");
if (item == null) {
writer.write("s");
}
writer.write(">");
}
}
@ -176,6 +191,14 @@ public abstract class EWSMethod extends PostMethod {
}
}
protected void writeRestriction(Writer writer) throws IOException {
if (searchExpression != null) {
writer.write("<m:Restriction>");
searchExpression.write(writer);
writer.write("</m:Restriction>");
}
}
protected byte[] generateSoapEnvelope() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
@ -208,6 +231,7 @@ public abstract class EWSMethod extends PostMethod {
protected void writeSoapBody(Writer writer) throws IOException {
writeShape(writer);
writeRestriction(writer);
writeItemId(writer);
writeParentFolderId(writer);
writeFolderId(writer);

View File

@ -0,0 +1,35 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.exchange.ews;
import java.io.IOException;
import java.io.Writer;
/**
* EWS Search Expression.
*/
public abstract class SearchExpression {
/**
* Write XML content to writer.
*
* @param writer writer
* @throws IOException on error
*/
public abstract void write(Writer writer) throws IOException;
}

View File

@ -0,0 +1,65 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.exchange.ews;
import java.io.IOException;
import java.io.Writer;
/**
* Two operand expression.
*/
public class TwoOperandExpression extends SearchExpression {
protected enum Operator {
IsEqualTo, IsNotEqualTo, IsGreaterThan, IsGreaterThanOrEqualTo, IsLessThan, IsLessThanOrEqualTo
}
protected Operator operator;
protected FieldURI fieldURI;
protected String value;
/**
* Create two operand expression.
*
* @param operator operator
* @param fieldURI field operand
* @param value value operand
*/
public TwoOperandExpression(Operator operator, FieldURI fieldURI, String value) {
this.operator = operator;
this.fieldURI = fieldURI;
this.value = value;
}
@Override
public void write(Writer writer) throws IOException {
writer.write("<t:");
writer.write(operator.toString());
writer.write(">");
fieldURI.write(writer);
writer.write("<t:FieldURIOrConstant><t:Constant Value=\"");
writer.write(value);
writer.write("\"/></t:FieldURIOrConstant>");
writer.write("</t:");
writer.write(operator.toString());
writer.write(">");
}
}