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.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            @Override
028            public boolean accept(String capabilityName) {
029                    if (_acceptableCapabilityNames.isEmpty() ||
030                            _acceptableCapabilityNames.contains(capabilityName)) {
031    
032                            return true;
033                    }
034    
035                    return false;
036            }
037    
038            @Override
039            public boolean accept(String capabilityName, String capabilityValue) {
040                    if (Validator.isNull(capabilityValue)) {
041                            return false;
042                    }
043    
044                    capabilityValue = capabilityValue.toLowerCase();
045    
046                    if (capabilityValue.equals("false")) {
047                            return false;
048                    }
049    
050                    if (!accept(capabilityName)) {
051                            return false;
052                    }
053    
054                    return true;
055            }
056    
057            public void setAcceptableCapabilityNames(
058                    Set<String> acceptableCapabilityNames) {
059    
060                    _acceptableCapabilityNames.addAll(acceptableCapabilityNames);
061            }
062    
063            private Set<String> _acceptableCapabilityNames = new HashSet<String>();
064    
065    }