001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }