Created
September 5, 2012 15:05
-
-
Save nshaw/3637992 to your computer and use it in GitHub Desktop.
Customized WURFLDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. | |
* | |
* This library is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU Affero General Public License as published by the Free | |
* Software Foundation; version 3.0 of the License. | |
* | |
* This library is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
* details. | |
*/ | |
package com.liferay.portal.mobile.device.wurfl; | |
import com.liferay.portal.kernel.mobile.device.AbstractDevice; | |
import com.liferay.portal.kernel.mobile.device.Capability; | |
import com.liferay.portal.kernel.mobile.device.Dimensions; | |
import com.liferay.portal.kernel.util.GetterUtil; | |
import com.liferay.portal.kernel.util.Validator; | |
import com.liferay.util.portlet.PortletProps; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map.Entry; | |
import java.util.Map; | |
/** | |
* @author Milen Dyankov | |
* @author Michael C. Han | |
*/ | |
public class WURFLDevice extends AbstractDevice { | |
public WURFLDevice(Map<String, String> capabilities) { | |
for (Entry<String, String> entry : capabilities.entrySet()) { | |
// CUSTOM BEGIN | |
String name = entry.getKey(); | |
String value = entry.getValue(); | |
if(!_acceptableCapabilities.isEmpty() | |
&& !_acceptableCapabilities.contains(name)) { | |
continue; | |
} | |
if (Validator.isNull(value) || value.toLowerCase().equals("false")) { | |
continue; | |
} | |
Capability capability = new Capability(name, value); | |
// CUSTOM END | |
_capabilities.put(entry.getKey(), capability); | |
} | |
} | |
public String getBrand() { | |
return _getValue(WURFLConstants.BRAND_NAME); | |
} | |
public String getBrowser() { | |
return _getValue(WURFLConstants.MOBILE_BROWSER); | |
} | |
public String getBrowserVersion() { | |
return _getValue(WURFLConstants.MOBILE_BROWSER_VERSION); | |
} | |
public Map<String, Capability> getCapabilities() { | |
return _capabilities; | |
} | |
public String getCapability(String name) { | |
return _getValue(name); | |
} | |
public String getModel() { | |
return _getValue(WURFLConstants.MODEL_NAME); | |
} | |
public String getOS() { | |
return _getValue(WURFLConstants.DEVICE_OS); | |
} | |
public String getOSVersion() { | |
return _getValue(WURFLConstants.DEVICE_OS_VERSION); | |
} | |
public String getPointingMethod() { | |
return _getValue(WURFLConstants.POINTING_METHOD); | |
} | |
public Dimensions getScreenSize() { | |
String heightValue = _getValue(WURFLConstants.RESOLUTION_HEIGHT); | |
float height = GetterUtil.getFloat(heightValue); | |
String widthValue = _getValue(WURFLConstants.RESOLUTION_WIDTH); | |
float width = GetterUtil.getFloat(widthValue); | |
return new Dimensions(height, width); | |
} | |
public boolean hasQwertyKeyboard() { | |
String value = _getValue(WURFLConstants.HAS_QWERTY_KEYBOARD); | |
return GetterUtil.getBoolean(value, false); | |
} | |
public boolean isTablet() { | |
String value = _getValue(WURFLConstants.IS_TABLET); | |
return GetterUtil.getBoolean(value, false); | |
} | |
private String _getValue(String capabilityName) { | |
Capability capability = _capabilities.get(capabilityName); | |
return (capability != null) ? capability.getValue() : ""; | |
} | |
private static final List<String> _acceptableCapabilities = | |
Arrays.asList( | |
PortletProps.getArray("acceptable.capabilities.names")); | |
private Map<String, Capability> _capabilities = | |
new HashMap<String, Capability>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment