List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix)
Case insensitive check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:com.willwinder.universalgcodesender.connection.ConnectionFactory.java
/** * Returns a new instance of a connection from an uri. The uri should be start with a protocol * {@link ConnectionDriver#getProtocol()} that defines which driver to use. The driver may then * have different styles for defining paths, ex: jserialcomm://{portname}:{baudrate} * * @param uri the uri for the hardware to connect to * @return a connection//from w w w. j a va 2s. c o m * @throws ConnectionException if something went wron while creating the connection */ static public Connection getConnection(String uri) throws ConnectionException { for (ConnectionDriver connectionDriver : ConnectionDriver.values()) { if (StringUtils.startsWithIgnoreCase(uri, connectionDriver.getProtocol())) { Connection connection = getConnection(connectionDriver).orElseThrow(() -> new ConnectionException( "Couldn't load connection driver " + connectionDriver + " for uri: " + uri)); connection.setUri(uri); return connection; } } throw new ConnectionException("Couldn't find connection driver for uri: " + uri); }
From source file:com.github.helenusdriver.driver.ObjectNotFoundException.java
/** * Handles special case where a keyspace is not defined by throwing a * {@link ObjectNotFoundException} if the specified exception matches that * specific condition.// w w w . ja va 2 s . c o m * * @author paouelle * * @param clazz the pojo class we queried * @param e the invalid query exception to handle * @throws ObjectNotFoundException if the keyspace is not found */ public static void handleKeyspaceNotFound(Class<?> clazz, InvalidQueryException e) throws ObjectNotFoundException { final String msg = e.getMessage(); if (StringUtils.startsWithIgnoreCase(msg, "keyspace ") && StringUtils.endsWith(msg, "does not exist")) { throw new ObjectNotFoundException(clazz, msg); } }
From source file:kenh.expl.functions.StartsWith.java
public boolean process(String str, String prefix, boolean ignoreCase) { if (ignoreCase) return StringUtils.startsWithIgnoreCase(str, prefix); else/*w w w . j a v a 2s .c o m*/ return StringUtils.startsWith(str, prefix); }
From source file:nc.noumea.mairie.annuairev2.saisie.viewmodel.StringSimpleListModel.java
@Override public boolean inSubModel(Object key, Object value) { String searchString = (String) key; if (StringUtils.isEmpty(searchString)) return true; return StringUtils.startsWithIgnoreCase((String) value, searchString); }
From source file:com.yqboots.initializer.core.builder.excel.AbstractSheetBuilder.java
@Override public boolean supports(final Sheet sheet) { final String name = StringUtils.trim(sheet.getSheetName()); return StringUtils.startsWithIgnoreCase(name, this.sheetName); }
From source file:com.monarchapis.driver.authentication.JwtClaimsProcessor.java
@Override public ObjectNode getClaims(HttpServletRequest request) { if (StringUtils.isBlank(jwtKey)) { return null; }/* ww w . ja v a2s . co m*/ String authorization = request.getHeader("Authorization"); if (authorization != null && StringUtils.startsWithIgnoreCase(authorization, "Bearer ")) { String jwt = authorization.substring(7).trim(); if (StringUtils.countMatches(jwt, ".") == 2) { try { return getClaims(jwt); } catch (Exception e) { logger.warn("Could not parse JWT token", e); } } } return null; }
From source file:com.nesscomputing.tinyhttp.ssl.HttpsTrustManagerFactory.java
@Nonnull private static KeyStore loadKeystore(@Nonnull String location, @Nonnull String keystoreType, @Nonnull String keystorePassword) throws GeneralSecurityException, IOException { final KeyStore keystore = KeyStore.getInstance(keystoreType); URL keystoreUrl;// w ww. j a v a2 s .c om if (StringUtils.startsWithIgnoreCase(location, "classpath:")) { keystoreUrl = Resources.getResource(HttpsTrustManagerFactory.class, location.substring(10)); } else { keystoreUrl = new URL(location); } keystore.load(keystoreUrl.openStream(), keystorePassword.toCharArray()); return keystore; }
From source file:com.nesscomputing.httpclient.internal.HttpClientTrustManagerFactory.java
@Nonnull private static KeyStore loadKeystore(@Nonnull String location, @Nonnull String keystoreType, @Nonnull String keystorePassword) throws GeneralSecurityException, IOException { final KeyStore keystore = KeyStore.getInstance(keystoreType); URL keystoreUrl;//from www. j av a2 s .com if (StringUtils.startsWithIgnoreCase(location, "classpath:")) { keystoreUrl = Resources.getResource(HttpClientTrustManagerFactory.class, location.substring(10)); } else { keystoreUrl = new URL(location); } keystore.load(keystoreUrl.openStream(), keystorePassword.toCharArray()); return keystore; }
From source file:com.opentable.logging.jetty.JsonRequestLog.java
@Override public void log(final Request request, final Response response) { final String requestUri = request.getRequestURI(); for (String blackListEntry : startsWithBlackList) { if (StringUtils.startsWithIgnoreCase(requestUri, blackListEntry)) { return; }/*from ww w. j av a 2 s . co m*/ } for (String blackListEntry : equalityBlackList) { if (StringUtils.equalsIgnoreCase(requestUri, blackListEntry)) { return; } } final RequestLogEvent event = eventFactory.createFor(clock, request, response); // TODO: this is a bit of a hack. The RequestId filter happens inside of the // servlet dispatcher which is a Jetty handler. Since the request log is generated // as a separate handler, the scope has already exited and thus the MDC lost its token. // But we want it there when we log, so let's put it back temporarily... MDC.put(CommonLogFields.REQUEST_ID_KEY, event.getRequestId()); try { event.prepareForDeferredProcessing(); LogbackLogging.log(LOG, event); } finally { MDC.remove(CommonLogFields.REQUEST_ID_KEY); } }
From source file:lti.oauth.OAuthFilter.java
@Override protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain fc) throws ServletException, IOException { LaunchRequest launchRequest = new LaunchRequest(req.getParameterMap()); SortedMap<String, String> alphaSortedMap = launchRequest.toSortedMap(); String signature = alphaSortedMap.remove(OAuthUtil.SIGNATURE_PARAM); String calculatedSignature = null; try {//from ww w. j a v a 2 s . co m calculatedSignature = new OAuthMessageSigner().sign(secret, OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST", req.getRequestURL().toString(), alphaSortedMap); } catch (Exception e) { log.error(e.getMessage(), e); res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value()); return; } if (!signature.equals(calculatedSignature)) { // try again with http String recalculatedSignature = null; if (StringUtils.startsWithIgnoreCase(req.getRequestURL().toString(), "https:")) { String url = StringUtils.replaceOnce(req.getRequestURL().toString(), "https:", "http:"); try { recalculatedSignature = new OAuthMessageSigner().sign(secret, OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST", url, alphaSortedMap); } catch (Exception e) { log.error(e.getMessage(), e); res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value()); return; } } if (!signature.equals(recalculatedSignature)) { res.sendError(HttpStatus.UNAUTHORIZED.value()); return; } } fc.doFilter(req, res); }