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

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

Introduction

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

Prototype

public static String substringBetween(String str, String tag) 

Source Link

Document

Gets the String that is nested in between two instances of the same String.

Usage

From source file:org.kuali.rice.krad.lookup.LookupUtils.java

/**
 * Retrieves the value for the given parameter name to send as a lookup parameter.
 *
 * @param form form instance to retrieve values from
 * @param request request object to retrieve parameters from
 * @param lookupObjectClass data object class associated with the lookup, used to check whether the
 * value needs to be encyrpted//from   ww w  .j av a 2 s. co  m
 * @param propertyName name of the property associated with the parameter, used to check whether the
 * value needs to be encrypted
 * @param parameterName name of the parameter to retrieve the value for
 * @return String parameter value or empty string if no value was found
 */
public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request,
        Class<?> lookupObjectClass, String propertyName, String parameterName) {
    String parameterValue = "";

    // get literal parameter values first
    if (StringUtils.startsWith(parameterName, "'") && StringUtils.endsWith(parameterName, "'")) {
        parameterValue = StringUtils.substringBetween(parameterName, "'");
    } else if (parameterValue.startsWith(
            KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
        parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
                + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER);
    }
    // check if parameter is in request
    else if (request.getParameterMap().containsKey(parameterName)) {
        parameterValue = request.getParameter(parameterName);
    }
    // get parameter value from form object
    else {
        parameterValue = ObjectPropertyUtils.getPropertyValueAsText(form, parameterName);
    }

    if (parameterValue != null && lookupObjectClass != null
            && KRADServiceLocatorWeb.getDataObjectAuthorizationService()
                    .attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) {
        try {
            if (CoreApiServiceLocator.getEncryptionService().isEnabled()) {
                parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue)
                        + EncryptionService.ENCRYPTION_POST_PREFIX;
            }
        } catch (GeneralSecurityException e) {
            LOG.error("Unable to encrypt value for property name: " + propertyName);
            throw new RuntimeException(e);
        }
    }

    return parameterValue;
}

From source file:org.openhab.action.openwebif.internal.OpenWebIfActionService.java

/**
 * Parses the properties for a OpenWebIfConfig.
 *///from  w  ww. j a v a 2  s .c o  m
private void parseConfig(String key, String value) throws ConfigurationException {
    if (value == null) {
        throw new ConfigurationException("openwebif",
                "Empty property '" + key + "', please check your openhab.cfg!");
    }

    String receiverName = StringUtils.substringBetween(key, ".");
    if (receiverName == null) {
        throw new ConfigurationException("openwebif",
                "Malformed receiver property '" + key + "', please check your openhab.cfg!");
    }

    OpenWebIfConfig rc = OpenWebIf.getConfigs().get(receiverName);
    if (rc == null) {
        rc = new OpenWebIfConfig();
        rc.setName(receiverName);
        OpenWebIf.getConfigs().put(receiverName, rc);
    }

    String keyId = StringUtils.substringAfterLast(key, ".");
    if (StringUtils.equalsIgnoreCase(keyId, "host")) {
        rc.setHost(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "port")) {
        rc.setPort(parseNumber(key, value).intValue());
    } else if (StringUtils.equalsIgnoreCase(keyId, "user")) {
        rc.setUser(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "password")) {
        rc.setPassword(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "https")) {
        rc.setHttps(Boolean.parseBoolean(value));
    } else {
        throw new ConfigurationException("openwebif",
                "Unknown configuration key '" + key + "', please check your openhab.cfg!");
    }
}

From source file:org.openhab.binding.weather.internal.common.WeatherConfig.java

/**
 * Parses the properties for a location config.
 *//*from w w w. j a  v  a 2s .c  om*/
private void parseLocation(String key, String value) throws ConfigurationException {
    if (value == null) {
        throw new ConfigurationException("weather",
                "Empty property '" + key + "', please check your openhab.cfg!");
    }

    String locationId = StringUtils.substringBetween(key, ".");
    if (locationId == null) {
        throw new ConfigurationException("weather",
                "Malformed location property '" + key + "', please check your openhab.cfg!");
    }

    LocationConfig lc = locationConfigs.get(locationId);
    if (lc == null) {
        lc = new LocationConfig();
        lc.setLocationId(locationId);
        locationConfigs.put(locationId, lc);
    }

    String keyId = PropertyResolver.last(key);
    if (StringUtils.equalsIgnoreCase(keyId, "provider")) {
        lc.setProviderName(getProviderName(value));
    } else if (StringUtils.equalsIgnoreCase(keyId, "updateInterval")) {
        lc.setUpdateInterval(parseNumber(key, value).intValue());
    } else if (StringUtils.equalsIgnoreCase(keyId, "latitude")) {
        lc.setLatitude(parseNumber(key, value));
    } else if (StringUtils.equalsIgnoreCase(keyId, "longitude")) {
        lc.setLongitude(parseNumber(key, value));
    } else if (StringUtils.equalsIgnoreCase(keyId, "language")) {
        lc.setLanguage(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "name")) {
        lc.setName(value);
    } else {
        throw new ConfigurationException("weather",
                "Unknown configuration key '" + key + "', please check your openhab.cfg!");
    }
}

From source file:org.openhab.ui.chart.internal.ChartProviderDelegate.java

@Override
public BufferedImage createChart(String service, String theme, Date startTime, Date endTime, int height,
        int width, String items, String groups) throws ItemNotFoundException {
    try {//from ww w .j ava 2  s  . com
        return provider.createChart(service, theme, startTime, endTime, height, width, items, groups);
    } catch (org.openhab.core.items.ItemNotFoundException e) {
        throw new ItemNotFoundException(StringUtils.substringBetween(e.getMessage(), "'"));
    }
}

From source file:org.sipfoundry.sipxconfig.login.LoginEvent.java

Date extractDate(String line) {
    Date date = null;/*w w w.jav a  2  s.c  om*/
    try {
        String token = StringUtils.substringBetween(line, "\"");
        date = LOG_DATE_FORMAT.parse(token);
    } catch (ParseException ex) {
        return null;
    }
    return date;
}