Example usage for org.apache.commons.lang StringUtils upperCase

List of usage examples for org.apache.commons.lang StringUtils upperCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils upperCase.

Prototype

public static String upperCase(String str) 

Source Link

Document

Converts a String to upper case as per String#toUpperCase() .

Usage

From source file:org.openhab.binding.astro.internal.bus.BindingConfigParser.java

/**
 * Parses the planet name.//w  w  w .j  a  v  a  2s. c om
 */
private PlanetName getPlanetName(AstroBindingConfigHelper helper) {
    try {
        return PlanetName.valueOf(StringUtils.upperCase(helper.planet));
    } catch (Exception ex) {
        return null;
    }
}

From source file:org.openhab.binding.homematic.internal.communicator.AbstractHomematicGateway.java

/**
 * Creates a virtual device for handling variables, scripts and other special gateway functions.
 *//*from www .  j  a v a 2s  . co  m*/
private HmDevice createGatewayDevice() {
    HmDevice device = new HmDevice();
    device.setAddress(HmDevice.ADDRESS_GATEWAY_EXTRAS);
    device.setHmInterface(getDefaultInterface());
    device.setGatewayId(config.getGatewayInfo().getId());
    device.setType(String.format("%s-%s", HmDevice.TYPE_GATEWAY_EXTRAS, StringUtils.upperCase(id)));
    device.setName(HmDevice.TYPE_GATEWAY_EXTRAS);

    HmChannel channel = new HmChannel();
    channel.setNumber(HmChannel.CHANNEL_NUMBER_EXTRAS);
    channel.setType(HmChannel.TYPE_GATEWAY_EXTRAS);
    device.addChannel(channel);

    channel = new HmChannel();
    channel.setNumber(HmChannel.CHANNEL_NUMBER_VARIABLE);
    channel.setType(HmChannel.TYPE_GATEWAY_VARIABLE);
    device.addChannel(channel);

    channel = new HmChannel();
    channel.setNumber(HmChannel.CHANNEL_NUMBER_SCRIPT);
    channel.setType(HmChannel.TYPE_GATEWAY_SCRIPT);
    device.addChannel(channel);

    return device;
}

From source file:org.openhab.binding.smartmeter.internal.helper.SerialParameter.java

/**
 * Returns the enum constant for the serial parameter string.
 * The parameters must be in format 'StartbitsParityStopbits'
 * e.g. '7N1', '8N1'/*from w  w  w.  j  a  v  a2s .co  m*/
 *
 * @param params
 * @return The found {@link SerialParameter} or {@link SerialParameter#_8N1} if not found
 */
public static SerialParameter fromString(String params) {
    try {
        return valueOf("_" + StringUtils.upperCase(params));
    } catch (IllegalArgumentException e) {
        return SerialParameter._8N1;
    }
}

From source file:org.openhab.binding.sonos.internal.SonosBinding.java

@SuppressWarnings("unchecked")
private Type createStateForType(Class<? extends State> ctype, String value) throws BindingConfigParseException {

    if (ctype != null && value != null) {

        List<Class<? extends State>> stateTypeList = new ArrayList<Class<? extends State>>();
        stateTypeList.add(ctype);//from w ww  .java 2s. c  om

        String finalValue = value;

        // Note to Kai or Thomas: sonos devices return some "true" "false"
        // values for specific variables. We convert those
        // into ON OFF if the commandTypes allow so. This is a little hack,
        // but IMHO OnOffType should
        // be enhanced, or a TrueFalseType should be developed
        if (ctype.equals(OnOffType.class)) {
            finalValue = StringUtils.upperCase(value);
            if (finalValue.equals("TRUE") || finalValue.equals("1")) {
                finalValue = "ON";
            } else if (finalValue.equals("FALSE") || finalValue.equals("0")) {
                finalValue = "OFF";
            }
        }

        State state = TypeParser.parseState(stateTypeList, finalValue);

        return state;
    } else {
        return null;
    }
}

From source file:org.openhab.binding.weather.internal.bus.BindingConfigParser.java

/**
 * Parses the bindingConfig of an item and returns a WeatherBindingConfig.
 *///from   w ww  .  ja  v a2s.  com
public WeatherBindingConfig parse(Item item, String bindingConfig) throws BindingConfigParseException {
    bindingConfig = StringUtils.trimToEmpty(bindingConfig);
    bindingConfig = StringUtils.removeStart(bindingConfig, "{");
    bindingConfig = StringUtils.removeEnd(bindingConfig, "}");
    String[] entries = bindingConfig.split("[,]");
    WeatherBindingConfigHelper helper = new WeatherBindingConfigHelper();

    for (String entry : entries) {
        String[] entryParts = StringUtils.trimToEmpty(entry).split("[=]");
        if (entryParts.length != 2) {
            throw new BindingConfigParseException("A bindingConfig must have a key and a value");
        }
        String key = StringUtils.trim(entryParts[0]);

        String value = StringUtils.trim(entryParts[1]);
        value = StringUtils.removeStart(value, "\"");
        value = StringUtils.removeEnd(value, "\"");

        try {
            helper.getClass().getDeclaredField(key).set(helper, value);
        } catch (Exception e) {
            throw new BindingConfigParseException("Could not set value " + value + " for attribute " + key);
        }
    }

    if (!helper.isValid()) {
        throw new BindingConfigParseException("Invalid binding: " + bindingConfig);
    }

    helper.type = StringUtils.replace(helper.type, "athmosphere", "atmosphere");

    WeatherBindingConfig weatherConfig = null;
    if (helper.isForecast()) {
        Integer forecast = parseInteger(helper.forecast, bindingConfig);
        if (forecast < 0) {
            throw new BindingConfigParseException("Invalid binding, forecast must be >= 0: " + bindingConfig);
        }
        weatherConfig = new ForecastBindingConfig(helper.locationId, forecast, helper.type, helper.property);
    } else {
        weatherConfig = new WeatherBindingConfig(helper.locationId, helper.type, helper.property);
    }

    Weather validationInstance = new Weather(null);
    String property = weatherConfig.getWeatherProperty();
    if (!Weather.isVirtualProperty(property) && !PropertyUtils.hasProperty(validationInstance, property)) {
        throw new BindingConfigParseException("Invalid binding, unknown type or property: " + bindingConfig);
    }

    boolean isDecimalTypeItem = item.getAcceptedDataTypes().contains(DecimalType.class);
    if (isDecimalTypeItem || Weather.isVirtualProperty(property)) {
        RoundingMode roundingMode = RoundingMode.HALF_UP;
        if (helper.roundingMode != null) {
            try {
                roundingMode = RoundingMode.valueOf(StringUtils.upperCase(helper.roundingMode));
            } catch (IllegalArgumentException ex) {
                throw new BindingConfigParseException(
                        "Invalid binding, unknown roundingMode: " + bindingConfig);
            }
        }

        Integer scale = 2;
        if (helper.scale != null) {
            scale = parseInteger(helper.scale, bindingConfig);
            if (scale < 0) {
                throw new BindingConfigParseException("Invalid binding, scale must be >= 0: " + bindingConfig);
            }
        }
        weatherConfig.setScale(roundingMode, scale);
    }

    weatherConfig.setUnit(Unit.parse(helper.unit));
    if (StringUtils.isNotBlank(helper.unit) && weatherConfig.getUnit() == null) {
        throw new BindingConfigParseException("Invalid binding, unknown unit: " + bindingConfig);
    }

    try {
        if (!Weather.isVirtualProperty(property) && weatherConfig.hasUnit()) {
            String doubleTypeName = Double.class.getName();
            String propertyTypeName = PropertyUtils.getPropertyTypeName(validationInstance, property);
            if (!StringUtils.equals(doubleTypeName, propertyTypeName)) {
                throw new BindingConfigParseException(
                        "Invalid binding, unit specified but property is not a double type: " + bindingConfig);
            }
        }
    } catch (IllegalAccessException ex) {
        logger.error(ex.getMessage(), ex);
        throw new BindingConfigParseException(ex.getMessage());
    }
    return weatherConfig;
}

From source file:org.openmrs.web.taglib.FormatTag.java

/**
 * Apply a case conversion to an input string
 * @param source//from  ww  w. jav a2  s  .  c  o  m
 * @return
 */
private String applyConversion(String source) {

    String result = source;

    // Find global property 
    if ("global".equalsIgnoreCase(caseConversion)) {
        AdministrationService adminService = Context.getAdministrationService();
        caseConversion = adminService.getGlobalProperty(OpenmrsConstants.GP_DASHBOARD_METADATA_CASE_CONVERSION);
    }

    // Apply conversion
    if ("lowercase".equalsIgnoreCase(caseConversion)) {
        result = StringUtils.lowerCase(result);
    } else if ("uppercase".equalsIgnoreCase(caseConversion)) {
        result = StringUtils.upperCase(result);
    } else if ("capitalize".equalsIgnoreCase(caseConversion)) {
        result = WordUtils.capitalize(StringUtils.lowerCase(result));
    }
    return result;
}

From source file:org.orcid.frontend.web.controllers.WorksUpdateController.java

@ModelAttribute("citationTypes")
public Map<String, String> retrieveTypesAsMap() {
    Map<String, String> citationTypes = new TreeMap<String, String>();
    citationTypes.put("", "Pick a citation type");
    for (CitationType citationType : CitationType.values()) {
        String value = citationType.value().replace("formatted-", "");
        citationTypes.put(citationType.value(), StringUtils.upperCase(value));
    }// w w w  .jav  a 2  s .  com
    return citationTypes;
}

From source file:org.orcid.persistence.dao.impl.OtherNameDaoImpl.java

@Override
@Transactional/*w  w w .j  a v a 2s  . co m*/
public boolean updateOtherNamesVisibility(String orcid, Visibility visibility) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified=now(), other_names_visibility=:other_names_visibility, indexing_status='PENDING' where orcid=:orcid");
    query.setParameter("other_names_visibility", StringUtils.upperCase(visibility.value()));
    query.setParameter("orcid", orcid);
    boolean result = query.executeUpdate() > 0 ? true : false;
    return result;

}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
@Transactional/*w  w  w . ja  v a 2 s . c  o m*/
public boolean updateProfile(ProfileEntity profile) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified=now(), credit_name=:credit_name, family_name=:family_name, given_names=:given_names, biography=:biography, iso2_country=:iso2_country, biography_visibility=:biography_visibility, keywords_visibility=:keywords_visibility, researcher_urls_visibility=:researcher_urls_visibility, other_names_visibility=:other_names_visibility, names_visibility=:credit_name_visibility, profile_address_visibility=:profile_address_visibility, indexing_status='PENDING' where orcid=:orcid");
    query.setParameter("credit_name", profile.getCreditName());
    query.setParameter("family_name", profile.getFamilyName());
    query.setParameter("given_names", profile.getGivenNames());
    query.setParameter("biography", profile.getBiography());
    Iso3166Country iso2Country = profile.getIso2Country();
    query.setParameter("iso2_country", iso2Country != null ? iso2Country.value() : null);
    query.setParameter("biography_visibility", StringUtils.upperCase(profile.getBiographyVisibility().value()));
    query.setParameter("keywords_visibility", StringUtils.upperCase(profile.getKeywordsVisibility().value()));
    query.setParameter("researcher_urls_visibility",
            StringUtils.upperCase(profile.getResearcherUrlsVisibility().value()));
    query.setParameter("other_names_visibility",
            StringUtils.upperCase(profile.getOtherNamesVisibility().value()));
    query.setParameter("credit_name_visibility",
            StringUtils.upperCase(profile.getCreditNameVisibility().value()));
    query.setParameter("profile_address_visibility",
            StringUtils.upperCase(profile.getProfileAddressVisibility().value()));
    query.setParameter("orcid", profile.getId());

    boolean result = query.executeUpdate() > 0 ? true : false;

    return result;
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
@Transactional//from w ww. j a  v  a  2  s. c o  m
public void updateCountry(String orcid, Iso3166Country iso2Country, Visibility profileAddressVisibility) {
    Query updateQuery = entityManager.createQuery(
            "update ProfileEntity set lastModified = now(), iso2_country = :iso2Country,  profile_address_visibility = :profileAddressVisibility where orcid = :orcid");
    updateQuery.setParameter("orcid", orcid);
    updateQuery.setParameter("iso2Country", iso2Country != null ? iso2Country.value() : null);
    updateQuery.setParameter("profileAddressVisibility",
            StringUtils.upperCase(profileAddressVisibility.value()));
    updateQuery.executeUpdate();
}