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.repository.cmis;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    
021    import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
022    
023    /**
024     * @author Ivan Zaera
025     */
026    public class CMISRepositoryDetector {
027    
028            public CMISRepositoryDetector(RepositoryInfo repositoryInfo) {
029                    detectVendor(repositoryInfo);
030            }
031    
032            public boolean isNuxeo() {
033                    return _nuxeo;
034            }
035    
036            public boolean isNuxeo5_4() {
037                    return _nuxeo5_4;
038            }
039    
040            public boolean isNuxeo5_5OrHigher() {
041                    return _nuxeo5_5OrHigher;
042            }
043    
044            public boolean isNuxeo5_8OrHigher() {
045                    return _nuxeo5_8OrHigher;
046            }
047    
048            protected void detectNuxeo(RepositoryInfo repositoryInfo) {
049                    String productVersion = repositoryInfo.getProductVersion();
050    
051                    String[] versionParts = StringUtil.split(
052                            productVersion, StringPool.PERIOD);
053    
054                    int major = GetterUtil.getInteger(versionParts[0]);
055                    int minor = GetterUtil.getInteger(versionParts[1]);
056    
057                    if (major > 5) {
058                            _nuxeo5_8OrHigher = true;
059                            _nuxeo5_5OrHigher = true;
060                    }
061                    else if (major == 5) {
062                            if (minor >= 8) {
063                                    _nuxeo5_8OrHigher = true;
064                            }
065    
066                            if (minor >= 5) {
067                                    _nuxeo5_5OrHigher = true;
068                            }
069    
070                            if (minor == 4) {
071                                    _nuxeo5_4 = true;
072                            }
073                    }
074            }
075    
076            private void detectVendor(RepositoryInfo repositoryInfo) {
077                    String productName = repositoryInfo.getProductName();
078    
079                    if (productName.contains(_NUXEO_ID)) {
080                            _nuxeo = true;
081    
082                            detectNuxeo(repositoryInfo);
083                    }
084            }
085    
086            private static final String _NUXEO_ID = "Nuxeo";
087    
088            private boolean _nuxeo;
089            private boolean _nuxeo5_4;
090            private boolean _nuxeo5_5OrHigher;
091            private boolean _nuxeo5_8OrHigher;
092    
093    }