001    /**
002     * Copyright (c) 2000-present 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.mobile.device;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import java.util.HashSet;
023    import java.util.Set;
024    
025    /**
026     * @author Michael C. Han
027     */
028    @ProviderType
029    public class DefaultDeviceCapabilityFilter implements DeviceCapabilityFilter {
030    
031            @Override
032            public boolean accept(String capabilityName) {
033                    if (_acceptableCapabilityNames.isEmpty() ||
034                            _acceptableCapabilityNames.contains(capabilityName)) {
035    
036                            return true;
037                    }
038    
039                    return false;
040            }
041    
042            @Override
043            public boolean accept(String capabilityName, String capabilityValue) {
044                    if (Validator.isNull(capabilityValue)) {
045                            return false;
046                    }
047    
048                    capabilityValue = StringUtil.toLowerCase(capabilityValue);
049    
050                    if (capabilityValue.equals("false")) {
051                            return false;
052                    }
053    
054                    if (!accept(capabilityName)) {
055                            return false;
056                    }
057    
058                    return true;
059            }
060    
061            public void setAcceptableCapabilityNames(
062                    Set<String> acceptableCapabilityNames) {
063    
064                    _acceptableCapabilityNames.addAll(acceptableCapabilityNames);
065            }
066    
067            private final Set<String> _acceptableCapabilityNames = new HashSet<>();
068    
069    }