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