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