001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.repository.cmis.search;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    
019    /**
020     * @author Mika Koivisto
021     */
022    public class CMISBetweenExpression implements CMISCriterion {
023    
024            public CMISBetweenExpression(
025                    String field, String lower, String upper, boolean includesLower,
026                    boolean includesUpper) {
027    
028                    _field = field;
029                    _lower = lower;
030                    _upper = upper;
031                    _includesLower = includesLower;
032                    _includesUpper = includesUpper;
033            }
034    
035            public String toQueryFragment() {
036                    StringBundler sb = new StringBundler(9);
037    
038                    sb.append("(");
039                    sb.append(_field);
040    
041                    if (_includesLower) {
042                            sb.append(" >= ");
043                    }
044                    else {
045                            sb.append(" > ");
046                    }
047    
048                    sb.append(CMISParameterValueUtil.formatParameterValue(_field, _lower));
049                    sb.append(" AND ");
050                    sb.append(_field);
051    
052                    if (_includesUpper) {
053                            sb.append(" <= ");
054                    }
055                    else {
056                            sb.append(" < ");
057                    }
058    
059                    sb.append(CMISParameterValueUtil.formatParameterValue(_field, _upper));
060                    sb.append(")");
061    
062                    return sb.toString();
063            }
064    
065            private String _field;
066            private boolean _includesLower;
067            private boolean _includesUpper;
068            private String _lower;
069            private String _upper;
070    
071    }