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

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

Introduction

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

Prototype

public static boolean startsWithIgnoreCase(String str, String prefix) 

Source Link

Document

Case insensitive check if a String starts with a specified prefix.

Usage

From source file:org.openhab.binding.pioneeravr.internal.discovery.PioneerAvrDiscoveryParticipant.java

/**
 * Return true only if the given device model is supported.
 * //from   w  w  w  .  ja v a 2  s . c om
 * @param deviceModel
 * @return
 */
private boolean isSupportedDeviceModel(final String deviceModel) {
    return StringUtils.isNotBlank(deviceModel)
            && !Collections2.filter(PioneerAvrBindingConstants.SUPPORTED_DEVICE_MODELS,
                    new com.google.common.base.Predicate<String>() {
                        public boolean apply(String input) {
                            return StringUtils.startsWithIgnoreCase(deviceModel, input);
                        }
                    }).isEmpty();
}

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

/**
 * Parses and validates the properties in openhab.cfg.
 *//*from  w w  w. ja v  a2  s .com*/
public void parse(Dictionary<String, ?> properties) throws ConfigurationException {
    valid = false;
    if (properties != null) {
        Enumeration<String> keys = properties.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();

            String value = StringUtils.trimToNull((String) properties.get(key));
            if (StringUtils.startsWithIgnoreCase(key, "apikey")) {
                parseApiKey(key, value);
            } else if (StringUtils.startsWithIgnoreCase(key, "location")) {
                parseLocation(key, value);
            }
        }

        // check all LocationConfigs
        for (LocationConfig lc : locationConfigs.values()) {
            if (!lc.isValid()) {
                throw new ConfigurationException("weather", "Incomplete location config for locationId '"
                        + lc.getLocationId() + "', please check your openhab.cfg!");
            }
            if (lc.getProviderName() != ProviderName.YAHOO
                    && !providerConfigs.containsKey(lc.getProviderName())) {
                throw new ConfigurationException("weather", "No apikey found for provider '"
                        + lc.getProviderName() + "', please check your openhab.cfg!");
            }
        }

        // check all ProviderConfigs
        for (ProviderConfig pc : providerConfigs.values()) {
            if (!pc.isValid()) {
                throw new ConfigurationException("weather", "Invalid apikey config for provider '"
                        + pc.getProviderName() + "', please check your openhab.cfg!");
            }
        }

        valid = locationConfigs.size() > 0;
    }
}

From source file:org.openhab.io.neeo.internal.OpenHabToDeviceConverter.java

/**
 * Convert the {@link Thing} to a {@link NeeoDevice}
 *
 * @param thing the non-null thing//  w  w w  . ja  va2s  .  com
 * @return a potentially null neeo device
 */
@Nullable
NeeoDevice convert(Thing thing) {
    Objects.requireNonNull(thing, "thing cannot be null");

    final List<NeeoDeviceChannel> channels = new ArrayList<>();

    final ThingUID thingUID = thing.getUID();
    final Set<String> existingLabels = new HashSet<>();

    for (Channel channel : thing.getChannels()) {
        final ChannelUID uid = channel.getUID();

        if (channel.getKind() == ChannelKind.TRIGGER) {
            channels.addAll(NeeoDeviceChannel.from(channel, NeeoCapabilityType.BUTTON, ItemSubType.NONE,
                    existingLabels));
        } else {
            final ChannelType channelType = context.getChannelTypeRegistry()
                    .getChannelType(channel.getChannelTypeUID());

            NeeoCapabilityType type = NeeoCapabilityType.EXCLUDE;
            if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOBINDING_BINDING_ID, thingUID.getBindingId())) {
                if (StringUtils.startsWithIgnoreCase(thingUID.getAsString(),
                        NeeoConstants.NEEOBINDING_DEVICE_ID)) {
                    // all device channels are currently macros - so buttons are appropriate
                    type = NeeoCapabilityType.BUTTON;
                } else {
                    type = NeeoCapabilityType.guessType(channelType);
                }
            } else if (exposeAll) {
                type = NeeoCapabilityType.guessType(channelType);
            }

            final Set<Item> linkedItems = context.getItemChannelLinkRegistry().getLinkedItems(uid);
            if (linkedItems != null) {
                for (Item item : linkedItems) {
                    channels.addAll(NeeoDeviceChannel.from(item, channel, channelType, type, existingLabels));
                }
            }
        }

    }

    if (channels.size() == 0) {
        logger.debug("No linked channels found for thing {} - ignoring", thing.getLabel());
        return null;
    }

    if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOBINDING_BINDING_ID, thing.getUID().getBindingId())) {
        final Map<String, String> properties = thing.getProperties();
        /** The following properties have matches in org.openhab.binding.neeo.NeeoDeviceHandler.java */
        final String neeoType = StringUtils.isEmpty(properties.get("Type"))
                ? NeeoDeviceType.ACCESSOIRE.toString()
                : properties.get("Type");
        final String manufacturer = StringUtils.isEmpty(properties.get("Manufacturer")) ? "openHAB"
                : properties.get("Manufacturer");

        final Integer standbyDelay = parseInteger(properties.get("Standby Command Delay"));
        final Integer switchDelay = parseInteger(properties.get("Source Switch Delay"));
        final Integer shutDownDelay = parseInteger(properties.get("Shutdown Delay"));

        final NeeoDeviceTiming timing = new NeeoDeviceTiming(standbyDelay, switchDelay, shutDownDelay);

        final String dc = properties.get("Device Capabilities");
        final String[] deviceCapabilities = StringUtils.isEmpty(dc) ? new String[0]
                : StringUtils.split(dc, ',');

        try {
            return new NeeoDevice(new NeeoThingUID(thing.getUID()), 0,
                    exposeNeeoBinding ? NeeoDeviceType.parse(neeoType) : NeeoDeviceType.EXCLUDE, manufacturer,
                    thing.getLabel(), channels, timing, Arrays.asList(deviceCapabilities), null, null);
        } catch (IllegalArgumentException e) {
            logger.debug("NeeoDevice constructor threw an IAE - ignoring device: {} - {}", thing.getUID(),
                    e.getMessage(), e);
            return null;
        }
    } else {
        try {
            return new NeeoDevice(thing, channels,
                    exposeAll ? NeeoUtil.guessType(thing) : NeeoDeviceType.EXCLUDE, null);
        } catch (IllegalArgumentException e) {
            logger.debug("NeeoDevice constructor threw an IAE - ignoring device: {} - {}", thing.getUID(),
                    e.getMessage(), e);
            return null;
        }
    }
}

From source file:org.openmrs.module.fhir.api.impl.LocationServiceImpl.java

/**
 * @see org.openmrs.module.fhir.api.LocationService#searchLocationsById(String)
 *///  w w w. j a v a  2  s  . c om
public List<Location> searchLocationsByName(String name) {
    List<org.openmrs.Location> omrsLocations = Context.getLocationService().getLocations(name);
    List<Location> locationList = new ArrayList<Location>();
    for (org.openmrs.Location location : omrsLocations) {
        if (StringUtils.startsWithIgnoreCase(location.getName(), name)) {
            locationList.add(FHIRLocationUtil.generateLocation(location));
        }
    }
    return locationList;
}

From source file:org.parosproxy.paros.network.HttpMessage.java

public TreeSet<HtmlParameter> getFormParams() {
    final String contentType = mReqHeader.getHeader(HttpRequestHeader.CONTENT_TYPE);
    if (contentType == null
            || !StringUtils.startsWithIgnoreCase(contentType.trim(), HttpHeader.FORM_URLENCODED_CONTENT_TYPE)) {
        return new TreeSet<>();
    }/*  ww  w .  j ava  2 s.c  o m*/
    return this.getParamsSet(HtmlParameter.Type.form);
}

From source file:org.pepstock.jem.jbpm.tasks.ValueParser.java

/**
 * Parses the value of variables in JBPM and loads datasets into data descriptions
 * @param dd data description to load//w  ww . j  a v  a 2 s  . c om
 * @param valueParm value of assignment in BPMN2 language
 * @throws JBpmException if any error occurs
 */
public static final void loadDataDescription(DataDescription dd, String valueParm) throws JBpmException {
    // trim value
    String value = valueParm.trim();

    // init of variables to load dd
    String[] dsn = null;
    String disposition = null;
    String dataSource = null;
    boolean isSysout = false;
    // this boolean is set to true 
    // because if it's not able to parse the content,
    // the wjole string will be the content of dataset
    boolean isText = true;

    // parses using comma
    String[] stmtTokens = StringUtils.split(value, COMMAND_SEPARATOR);
    if (stmtTokens != null && stmtTokens.length > 0) {
        // scans all tokes
        for (int i = 0; i < stmtTokens.length; i++) {
            String token = stmtTokens[i].trim();
            // is datasetname?
            if (StringUtils.startsWithIgnoreCase(token, DSN_PREFIX)) {
                // gets all string after DSN and =
                String subToken = getValue(token, DSN_PREFIX);
                if (subToken != null) {
                    // sets that is not a text
                    isText = false;

                    String subValue = null;
                    // checks if the content is inside of brackets
                    if (subToken.startsWith("(") && subToken.endsWith(")")) {
                        // gets content inside brackets
                        subValue = StringUtils.removeEnd(StringUtils.removeStart(subToken, "("), ")");
                    } else {
                        // only 1 datasets
                        subValue = subToken;
                    }
                    // parses values
                    dsn = StringUtils.split(subValue, VALUE_SEPARATOR);
                }
            } else if (StringUtils.startsWithIgnoreCase(token, DISP_PREFIX)) {
                // sets that is not a text
                isText = false;
                // saves disposition
                disposition = getValue(token, DISP_PREFIX);
            } else if (StringUtils.startsWithIgnoreCase(token, DATASOURCE_PREFIX)) {
                // sets that is not a text
                isText = false;
                // saves data sourceinfo
                dataSource = getValue(token, DATASOURCE_PREFIX);
            } else if (StringUtils.startsWithIgnoreCase(token, SYSOUT)) {
                // sets that is not a text
                isText = false;
                // sets is a sysout
                isSysout = true;
            }
        }
    }
    // content of file
    if (isText) {
        dd.setDisposition(Disposition.SHR);
        DataSet ds = createDataSet(dd, null, valueParm);
        dd.addDataSet(ds);
    } else {
        // disposition DISP= is mandatory, always
        if (disposition == null) {
            throw new JBpmException(JBpmMessage.JEMM050E, dd.getName());
        }
        dd.setDisposition(disposition);

        // if sets SYSOUT but also DSN=, this is not allowed
        if (isSysout && dsn != null) {
            throw new JBpmException(JBpmMessage.JEMM051E, dd.getName());
        }
        // sets sysout
        dd.setSysout(isSysout);
        // if not sysout, loads datasets
        // datasource can be set ONLY with 1 dataset
        if (!isSysout && dsn != null) {
            if (dsn.length > 1 && dataSource != null) {
                throw new JBpmException(JBpmMessage.JEMM052E, dd.getName());
            }
            // loads all datasets and set datasource
            for (int k = 0; k < dsn.length; k++) {
                DataSet ds = createDataSet(dd, dsn[k], null);
                dd.addDataSet(ds);
                // doesn't check anything because
                // already done before
                if (dataSource != null) {
                    ds.setDatasource(dataSource);
                }
            }
        }
    }
}

From source file:org.pepstock.jem.jbpm.tasks.ValueParser.java

/**
 * Parses the value of variable in JBPM and load all data source properties if there are
 * @param ds data source to be loaded/* w  w  w . java  2  s.  c  o  m*/
 * @param valueParm value specified on JBPM xml assignment
 * @throws JBpmException if any error occurs
 */
public static final void loadDataSource(DataSource ds, String valueParm) throws JBpmException {
    // trim value
    String value = valueParm.trim();

    // parses using comma
    String[] stmtTokens = StringUtils.split(value, COMMAND_SEPARATOR);
    if (stmtTokens != null && stmtTokens.length > 0) {
        // scans all tokes
        for (int i = 0; i < stmtTokens.length; i++) {
            String token = stmtTokens[i].trim();
            // is datasetname?
            if (StringUtils.startsWithIgnoreCase(token, PROPERTIES_PREFIX)) {
                // gets all string after DSN=
                String subToken = getValue(token, PROPERTIES_PREFIX);
                if (subToken.startsWith("(") && subToken.endsWith(")")) {
                    // gets content inside brackets
                    String subValue = StringUtils.removeEnd(StringUtils.removeStart(subToken, "("), ")");
                    // if subvalue is null, exception
                    if (subValue != null) {
                        // changes all ; in line separator because by areader it can load a properties object
                        subValue = subValue.replace(VALUE_SEPARATOR, System.getProperty("line.separator"))
                                .concat(System.getProperty("line.separator"));
                        // loads all properties from a reader
                        StringReader reader = new StringReader(subValue);
                        Properties properties = new Properties();
                        try {
                            // loads it
                            properties.load(reader);
                            // scans all properties to creates property object
                            for (Entry<Object, Object> entry : properties.entrySet()) {
                                // creates properties
                                Property prop = new Property();
                                prop.setName(entry.getKey().toString());
                                prop.addText(entry.getValue().toString());
                                ds.addProperty(prop);
                            }
                        } catch (IOException e) {
                            LogAppl.getInstance().ignore(e.getMessage(), e);
                        }
                    } else {
                        throw new JBpmException(JBpmMessage.JEMM054E, ds.getName());
                    }
                } else {
                    throw new JBpmException(JBpmMessage.JEMM054E, ds.getName());
                }
            } else if (StringUtils.startsWithIgnoreCase(token, RESOURCE_PREFIX)) {
                String subToken = getValue(token, RESOURCE_PREFIX);
                // sets that is not a text
                ds.setResource(subToken);
            }
        }
    }
}

From source file:org.sakaiproject.profile2.logic.ProfileConnectionsLogicImpl.java

/**
  * {@inheritDoc}//  w ww  . j a v  a 2 s  . c  o  m
  */
public List<Person> getConnectionsSubsetForSearch(List<Person> connections, String search,
        boolean forMessaging) {

    List<Person> subList = new ArrayList<Person>();

    //check auth and get currentUserUuid
    String currentUserUuid = sakaiProxy.getCurrentUserId();
    if (currentUserUuid == null) {
        throw new SecurityException("You must be logged in to get a connection list subset.");
    }

    for (Person p : connections) {
        //check for match by name
        if (StringUtils.startsWithIgnoreCase(p.getDisplayName(), search)) {

            //if reached max size
            if (subList.size() == ProfileConstants.MAX_CONNECTIONS_PER_SEARCH) {
                break;
            }

            //if we need to check messaging privacy setting
            if (forMessaging) {
                //if not allowed to be messaged by this user
                if (!privacyLogic.isActionAllowed(p.getUuid(), currentUserUuid,
                        PrivacyType.PRIVACY_OPTION_MESSAGES)) {
                    continue;
                }
            }

            //all ok, add them to the list
            subList.add(p);
        }
    }
    return subList;
}

From source file:org.sonar.api.batch.fs.internal.PathPattern.java

public static PathPattern create(String s) {
    String trimmed = StringUtils.trim(s);
    if (StringUtils.startsWithIgnoreCase(trimmed, "file:")) {
        return new AbsolutePathPattern(StringUtils.substring(trimmed, "file:".length()));
    }/*from  w ww.  j av a 2s.  co m*/
    return new RelativePathPattern(trimmed);
}

From source file:org.sonar.batch.scan.filesystem.PathPattern.java

static PathPattern create(String s) {
    String trimmed = StringUtils.trim(s);
    if (StringUtils.startsWithIgnoreCase(trimmed, "file:")) {
        return new AbsolutePathPattern(StringUtils.substring(trimmed, "file:".length()));
    }//from w ww .j  a  v a  2s  .  c o  m
    return new RelativePathPattern(trimmed);
}