001    /**
002     * Copyright (c) 2000-2012 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.kernel.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 lowerTerm, String upperTerm, boolean includesLower,
026                    boolean includesUpper) {
027    
028                    _field = field;
029                    _lowerTerm = lowerTerm;
030                    _upperTerm = upperTerm;
031                    _includesLower = includesLower;
032                    _includesUpper = includesUpper;
033            }
034    
035            public String toQueryFragment() {
036                    StringBundler sb = new StringBundler(7);
037    
038                    sb.append(_field);
039    
040                    if (_includesLower) {
041                            sb.append(" >= ");
042                    }
043                    else {
044                            sb.append(" > ");
045                    }
046    
047                    sb.append(_lowerTerm);
048                    sb.append(" AND ");
049                    sb.append(_field);
050    
051                    if (_includesUpper) {
052                            sb.append(" <= ");
053                    }
054                    else {
055                            sb.append(" < ");
056                    }
057    
058                    sb.append(_upperTerm);
059    
060                    return sb.toString();
061            }
062    
063            private String _field;
064            private boolean _includesLower;
065            private boolean _includesUpper;
066            private String _lowerTerm;
067            private String _upperTerm;
068    
069    }