Example usage for com.liferay.portal.kernel.util GetterUtil getFloat

List of usage examples for com.liferay.portal.kernel.util GetterUtil getFloat

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util GetterUtil getFloat.

Prototype

public static float getFloat(String value) 

Source Link

Document

Returns the String value as a float.

Usage

From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java

License:Open Source License

public long createThumbnail(long imageId) {

    Image image = null;//  ww  w . j  ava2 s .com
    try {
        image = imageLocalService.fetchImage(imageId);
    } catch (SystemException e) {
        e.printStackTrace();
    }

    if (Validator.isNull(image))
        return 0l;

    // optimize the original image
    float maximumWidth = GetterUtil.getFloat(PortletProps.get("profile.photo.maximum.width"));
    if (image.getWidth() > (int) maximumWidth) {
        minifyPhoto(image, imageId, maximumWidth);
    }

    long thumbnailId = imageId;

    // check the original width of the image. 
    float thumbnailWidth = GetterUtil.getFloat(PortletProps.get("profile.photo.thumbnail.width"));
    if (image.getWidth() > (int) thumbnailWidth) {
        try {
            thumbnailId = counterLocalService.increment(Image.class.getName());
        } catch (SystemException e) {
            e.printStackTrace();
        }

        minifyPhoto(image, thumbnailId, thumbnailWidth);
    }

    Photo photo = null;
    try {
        photo = fetchPhoto(imageId);
    } catch (SystemException e) {
        e.printStackTrace();
    }

    photo.setThumbnailId(thumbnailId);
    try {
        updatePhoto(photo);
    } catch (SystemException e) {
        e.printStackTrace();
    }

    transferToS3(imageId);

    return thumbnailId;
}

From source file:com.liferay.alloy.util.DefaultValueUtil.java

License:Open Source License

public static String getDefaultValue(String className, String value) {
    String defaultValue = StringPool.BLANK;

    if (className.equals(ArrayList.class.getName()) || className.equals(HashMap.class.getName())
            || className.equals(Object.class.getName()) || className.equals(String.class.getName())) {

        if (!isValidStringValue(value)) {
            return defaultValue;
        }//from  ww  w. jav a 2  s. c  o m

        if (_EMPTY_STRINGS.contains(value)) {
            value = StringPool.BLANK;
        } else if (className.equals(ArrayList.class.getName())
                && !StringUtil.startsWith(value.trim(), StringPool.OPEN_BRACKET)) {

            value = "[]";
        } else if (className.equals(HashMap.class.getName())
                && !StringUtil.startsWith(value.trim(), StringPool.OPEN_CURLY_BRACE)) {

            value = "{}";
        }

        defaultValue = StringUtil.unquote(value);
    } else if (className.equals(boolean.class.getName()) || className.equals(Boolean.class.getName())) {

        defaultValue = String.valueOf(GetterUtil.getBoolean(value));
    } else if (className.equals(int.class.getName()) || className.equals(Integer.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Integer.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getInteger(value));
    } else if (className.equals(double.class.getName()) || className.equals(Double.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Double.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getDouble(value));
    } else if (className.equals(float.class.getName()) || className.equals(Float.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Float.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getFloat(value));
    } else if (className.equals(long.class.getName()) || className.equals(Long.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Long.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getLong(value));
    } else if (className.equals(short.class.getName()) || className.equals(Short.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Short.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getShort(value));
    } else if (className.equals(Number.class.getName())) {
        if (_INFINITY.contains(value)) {
            value = String.valueOf(Integer.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getNumber(value));
    }

    return defaultValue;
}

From source file:com.liferay.client.json.ipgeocoder.util.IPGeocoderUtil.java

License:Open Source License

public static IPInfo getIPInfo(String ipAddress) throws PortalException {
    Object response = MessageBusUtil.sendSynchronousMessage(DestinationNames.IP_GEOCODER, ipAddress);

    if (!(response instanceof JSONObject)) {
        return null;
    }/*from   www.  jav  a 2s .com*/

    JSONObject ipInfoJSON = (JSONObject) response;

    if (ipInfoJSON == null) {
        return null;
    }

    float latitude = GetterUtil.getFloat(ipInfoJSON.getString("latitude"));
    float longitude = GetterUtil.getFloat(ipInfoJSON.getString("longitude"));

    return new IPInfo(ipAddress, latitude, longitude);
}

From source file:com.liferay.dynamic.data.mapping.storage.FieldConstants.java

License:Open Source License

public static final Serializable getSerializable(String type, String value) {

    if (Validator.isNull(type)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Invalid type " + type);
        }/*from ww w.j  av  a  2s.c om*/

        return value;
    }

    if (isNumericType(type) && Validator.isNull(value)) {
        return StringPool.BLANK;
    }

    if (type.equals(BOOLEAN)) {
        return GetterUtil.getBoolean(value);
    } else if (type.equals(DATE) && Validator.isNotNull(value)) {
        return value;
    } else if (type.equals(DOUBLE)) {
        return GetterUtil.getDouble(value);
    } else if (type.equals(FLOAT)) {
        return GetterUtil.getFloat(value);
    } else if (type.equals(INTEGER)) {
        return GetterUtil.getInteger(value);
    } else if (type.equals(LONG)) {
        return GetterUtil.getLong(value);
    } else if (type.equals(NUMBER)) {
        return GetterUtil.getNumber(value);
    } else if (type.equals(SHORT)) {
        return GetterUtil.getShort(value);
    } else {
        return value;
    }
}

From source file:com.liferay.mobile.device.rules.rule.group.rule.SimpleRuleHandler.java

License:Open Source License

protected boolean isValidRangeValue(MDRRule mdrRule, String maxProperty, String minProperty, float value) {

    UnicodeProperties typeSettingsProperties = mdrRule.getTypeSettingsProperties();

    String max = typeSettingsProperties.get(maxProperty);
    String min = typeSettingsProperties.get(minProperty);

    if (Validator.isNull(max) && Validator.isNull(min)) {
        logRangeValue(mdrRule, maxProperty, minProperty, value, max, min, true);

        return true;
    }// ww  w  . ja  v  a  2 s  .c o  m

    if (Validator.isNotNull(max)) {
        float maxFloat = GetterUtil.getFloat(max);

        if (value > maxFloat) {
            logRangeValue(mdrRule, maxProperty, minProperty, value, max, min, false);

            return false;
        }

        logRangeValue(mdrRule, maxProperty, minProperty, value, max, min, true);
    }

    if (Validator.isNotNull(min)) {
        float minFloat = GetterUtil.getFloat(min);

        if (value < minFloat) {
            logRangeValue(mdrRule, maxProperty, minProperty, value, max, min, false);

            return false;
        }

        logRangeValue(mdrRule, maxProperty, minProperty, value, max, min, true);
    }

    return true;
}

From source file:com.liferay.portlet.dynamicdatamapping.storage.FieldConstants.java

License:Open Source License

public static final Serializable getSerializable(String type, String value) {

    if (type.equals(BOOLEAN)) {
        return GetterUtil.getBoolean(value);
    } else if (type.equals(DATE) && Validator.isNotNull(value)) {
        return new Date(GetterUtil.getLong(value));
    } else if (type.equals(DOUBLE)) {
        return GetterUtil.getDouble(value);
    } else if (type.equals(FLOAT)) {
        return GetterUtil.getFloat(value);
    } else if (type.equals(INTEGER)) {
        return GetterUtil.getInteger(value);
    } else if (type.equals(LONG)) {
        return GetterUtil.getLong(value);
    } else if (type.equals(NUMBER)) {
        return GetterUtil.getNumber(value);
    } else if (type.equals(SHORT)) {
        return GetterUtil.getShort(value);
    } else {/*from   w w  w . j a  v  a 2s .  c  o m*/
        return value;
    }
}

From source file:com.liferay.portlet.expando.model.ExpandoColumnConstants.java

License:Open Source License

public static final Serializable getSerializable(int type, String value) {
    if (type == BOOLEAN) {
        return GetterUtil.getBoolean(value);
    } else if (type == BOOLEAN_ARRAY) {
        return new Boolean[] { GetterUtil.getBoolean(value) };
    } else if (type == DATE) {
        try {//from w w  w.j  a v a  2s  . c  o  m
            DateFormat dateFormat = DateFormatFactoryUtil.getDateTime(LocaleUtil.getDefault());

            return dateFormat.parse(value);
        } catch (Exception e) {
            _log.warn("Unable to parse date " + value, e);
        }
    } else if (type == DATE_ARRAY) {
        Serializable dateSerializable = getSerializable(DATE, value);

        if (dateSerializable instanceof Date) {
            return new Date[] { (Date) dateSerializable };
        }
    } else if (type == DOUBLE) {
        return GetterUtil.getDouble(value);
    } else if (type == DOUBLE_ARRAY) {
        return new double[] { GetterUtil.getDouble(value) };
    } else if (type == FLOAT) {
        return GetterUtil.getFloat(value);
    } else if (type == FLOAT_ARRAY) {
        return new float[] { GetterUtil.getFloat(value) };
    } else if (type == INTEGER) {
        return GetterUtil.getInteger(value);
    } else if (type == INTEGER_ARRAY) {
        return new int[] { GetterUtil.getInteger(value) };
    } else if (type == LONG) {
        return GetterUtil.getLong(value);
    } else if (type == LONG_ARRAY) {
        return new long[] { GetterUtil.getLong(value) };
    } else if (type == NUMBER) {
        return GetterUtil.getNumber(value);
    } else if (type == NUMBER_ARRAY) {
        return new Number[] { GetterUtil.getNumber(value) };
    } else if (type == SHORT) {
        return GetterUtil.getShort(value);
    } else if (type == SHORT_ARRAY) {
        return new short[] { GetterUtil.getShort(value) };
    } else if (type == STRING_ARRAY) {
        return new String[] { value };
    }

    return value;
}

From source file:com.liferay.portlet.expando.model.impl.ExpandoValueImpl.java

License:Open Source License

public float getFloat() throws PortalException, SystemException {
    validate(ExpandoColumnConstants.FLOAT);

    return GetterUtil.getFloat(getData());
}

From source file:com.liferay.portlet.expando.util.ExpandoConverterUtil.java

License:Open Source License

public static Serializable getAttributeFromString(int type, String attribute) {

    if (attribute == null) {
        return null;
    }//w w  w.j  av  a 2 s. c o m

    if (type == ExpandoColumnConstants.BOOLEAN) {
        return GetterUtil.getBoolean(attribute);
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
        return GetterUtil.getBooleanValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.DATE) {
        return GetterUtil.getDate(attribute, _getDateFormat());
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
        return GetterUtil.getDateValues(StringUtil.split(attribute), _getDateFormat());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
        return GetterUtil.getDouble(attribute);
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
        return GetterUtil.getDoubleValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.FLOAT) {
        return GetterUtil.getFloat(attribute);
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
        return GetterUtil.getFloatValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.INTEGER) {
        return GetterUtil.getInteger(attribute);
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
        return GetterUtil.getIntegerValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.LONG) {
        return GetterUtil.getLong(attribute);
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
        return GetterUtil.getLongValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.SHORT) {
        return GetterUtil.getShort(attribute);
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
        return GetterUtil.getShortValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
        return StringUtil.split(attribute);
    } else {
        return attribute;
    }
}

From source file:com.liferay.weather.util.WeatherWebCacheItem.java

License:Open Source License

protected Weather doConvert() throws Exception {
    String xml = HttpUtil.URLtoString("http://api.openweathermap.org/data/2.5/weather?q="
            + HttpUtil.encodeURL(_zip) + "&units=imperial&mode=xml");

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    Element cityElement = rootElement.element("city");

    Attribute cityIdAttribute = cityElement.attribute("id");

    String cityId = cityIdAttribute.getText();

    Element temperatureElement = rootElement.element("temperature");

    Attribute temperatureAttribute = temperatureElement.attribute("value");

    float temperature = GetterUtil.getFloat(temperatureAttribute.getData());

    Element weatherElement = rootElement.element("weather");

    Attribute iconAttribute = weatherElement.attribute("icon");

    String iconURL = "http://openweathermap.org/img/w/" + iconAttribute.getText() + ".png";

    return new Weather(_zip, cityId, iconURL, temperature);
}