001    /**
002     * Copyright (c) 2000-2013 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            @Override
036            public String toQueryFragment() {
037                    StringBundler sb = new StringBundler(7);
038    
039                    sb.append(_field);
040    
041                    if (_includesLower) {
042                            sb.append(" >= ");
043                    }
044                    else {
045                            sb.append(" > ");
046                    }
047    
048                    sb.append(_lowerTerm);
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(_upperTerm);
060    
061                    return sb.toString();
062            }
063    
064            private String _field;
065            private boolean _includesLower;
066            private boolean _includesUpper;
067            private String _lowerTerm;
068            private String _upperTerm;
069    
070    }