public static String getAcceptEncoding(HttpServletRequest req) { String encode = StringUtils.defaultIfEmpty(req.getHeader("Accept-Charset"), "UTF-8"); encode = encode.contains(",") ? encode.substring(0, encode.indexOf(",")) : encode; return encode.contains(";") ? encode.substring(0, encode.indexOf(";")) : encode; } }
public static String getAcceptEncoding(HttpServletRequest req) { String encode = StringUtils.defaultIfEmpty(req.getHeader("Accept-Charset"), "UTF-8"); encode = encode.contains(",") ? encode.substring(0, encode.indexOf(",")) : encode; return encode.contains(";") ? encode.substring(0, encode.indexOf(";")) : encode; } }
/** * Makes sure the string ends with "/" * * @param prefix any string, or null. * @return the prefix with a "/" at the end, never null. */ protected String endWithSlash( String prefix ) { prefix = StringUtils.defaultIfEmpty( prefix, "/" ); if ( ! prefix.endsWith( "/" ) ) { prefix = prefix + "/"; } return prefix; }
/** * Makes sure the string ends with "/" * * @param prefix any string, or null. * @return the prefix with a "/" at the end, never null. */ protected String endWithSlash( String prefix ) { prefix = StringUtils.defaultIfEmpty( prefix, "/" ); if ( ! prefix.endsWith( "/" ) ) { prefix = prefix + "/"; } return prefix; }
/** * Makes sure the string ends with "/" * * @param prefix * any string, or null. * @return the prefix with a "/" at the end, never null. */ protected String endWithSlash( String prefix ) { prefix = StringUtils.defaultIfEmpty( prefix, "/" ); if ( !prefix.endsWith( "/" ) ) { prefix = prefix + "/"; } return prefix; }
/** * Makes sure the string ends with "/" * * @param prefix * any string, or null. * @return the prefix with a "/" at the end, never null. */ protected String endWithSlash( String prefix ) { prefix = StringUtils.defaultIfEmpty( prefix, "/" ); if ( !prefix.endsWith( "/" ) ) { prefix = prefix + "/"; } return prefix; }
private String decodeHttpHeader(String encoded, String encoding) { try { return URLDecoder.decode(encoded, defaultIfEmpty(encoding, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } }
@Override public String getFallbackName(Class<?> enclosingType, Method commandMethod) { String commandDefaultFallback = commandMethod.getAnnotation(HystrixCommand.class).defaultFallback(); String classDefaultFallback = Optional.fromNullable(enclosingType.getAnnotation(DefaultProperties.class)) .transform(new Function<DefaultProperties, String>() { @Override public String apply(DefaultProperties input) { return input.defaultFallback(); } }).or(StringUtils.EMPTY); return StringUtils.defaultIfEmpty(commandDefaultFallback, classDefaultFallback); }
public Optional<String> getFileNameFromContentDisposition(String headerName, String headerValue) { if (!"Content-Disposition".equalsIgnoreCase(headerName) || headerValue == null) { return Optional.empty(); } Matcher regex = pattern.matcher(headerValue); if (!regex.matches()) { return Optional.empty(); } String fileName = regex.replaceFirst("$3"); String encoding = defaultIfEmpty(regex.replaceFirst("$2"), regex.replaceFirst("$5")); return Optional.of(decodeHttpHeader(fileName, encoding)); }
@Test public void testDefaultIfEmpty_StringBuffers() { assertEquals("NULL", StringUtils.defaultIfEmpty(new StringBuffer(""), new StringBuffer("NULL")).toString()); assertEquals("abc", StringUtils.defaultIfEmpty(new StringBuffer("abc"), new StringBuffer("NULL")).toString()); assertNull(StringUtils.defaultIfEmpty(new StringBuffer(""), null)); // Tests compatibility for the API return type final StringBuffer s = StringUtils.defaultIfEmpty(new StringBuffer("abc"), new StringBuffer("NULL")); assertEquals("abc", s.toString()); }
@Test public void testDefaultIfEmpty_CharBuffers() { assertEquals("NULL", StringUtils.defaultIfEmpty(CharBuffer.wrap(""), CharBuffer.wrap("NULL")).toString()); assertEquals("abc", StringUtils.defaultIfEmpty(CharBuffer.wrap("abc"), CharBuffer.wrap("NULL")).toString()); assertNull(StringUtils.defaultIfEmpty(CharBuffer.wrap(""), null)); // Tests compatibility for the API return type final CharBuffer s = StringUtils.defaultIfEmpty(CharBuffer.wrap("abc"), CharBuffer.wrap("NULL")); assertEquals("abc", s.toString()); }
@Test public void testDefaultIfEmpty_StringBuilders() { assertEquals("NULL", StringUtils.defaultIfEmpty(new StringBuilder(""), new StringBuilder("NULL")).toString()); assertEquals("abc", StringUtils.defaultIfEmpty(new StringBuilder("abc"), new StringBuilder("NULL")).toString()); assertNull(StringUtils.defaultIfEmpty(new StringBuilder(""), null)); // Tests compatibility for the API return type final StringBuilder s = StringUtils.defaultIfEmpty(new StringBuilder("abc"), new StringBuilder("NULL")); assertEquals("abc", s.toString()); }
@Test public void testDefaultIfEmpty_StringString() { assertEquals("NULL", StringUtils.defaultIfEmpty(null, "NULL")); assertEquals("NULL", StringUtils.defaultIfEmpty("", "NULL")); assertEquals("abc", StringUtils.defaultIfEmpty("abc", "NULL")); assertNull(StringUtils.defaultIfEmpty("", null)); // Tests compatibility for the API return type final String s = StringUtils.defaultIfEmpty("abc", "NULL"); assertEquals("abc", s); }
public String getMessage() { String messageString = null; if (message instanceof String) { messageString = (String) message; } else if (message instanceof Message) { Message messageObject = (Message) message; MessageLevel level = MessageLevel.BRIEF_MESSAGE; if (isReleased()) { level = messageObject.getMessageLevel(this); } if (level == MessageLevel.DETAILED_MESSAGE) { messageString = messageObject.getDetailedMessage(); } else { messageString = messageObject.getBriefMessage(); } } return StringUtils.defaultIfEmpty(messageString, null); }
public void clear(HttpRequest request) { HttpRequest requestMatcher = null; if (!Strings.isNullOrEmpty(request.getBodyAsString())) { requestMatcher = httpRequestSerializer.deserialize(request.getBodyAsString()); } try { ClearType retrieveType = ClearType.valueOf(StringUtils.defaultIfEmpty(request.getFirstQueryStringParameter("type").toUpperCase(), "ALL")); switch (retrieveType) { case LOG: mockServerLog.clear(requestMatcher); mockServerLogger.info(CLEARED, requestMatcher, "clearing recorded requests and logs that match:{}", (requestMatcher == null ? "{}" : requestMatcher)); break; case EXPECTATIONS: mockServerMatcher.clear(requestMatcher); mockServerLogger.info(CLEARED, requestMatcher, "clearing expectations that match:{}", (requestMatcher == null ? "{}" : requestMatcher)); break; case ALL: mockServerLog.clear(requestMatcher); mockServerMatcher.clear(requestMatcher); mockServerLogger.info(CLEARED, requestMatcher, "clearing expectations and request logs that match:{}", (requestMatcher == null ? "{}" : requestMatcher)); break; } } catch (IllegalArgumentException iae) { throw new IllegalArgumentException("\"" + request.getFirstQueryStringParameter("type") + "\" is not a valid value for \"type\" parameter, only the following values are supported " + Lists.transform(Arrays.asList(ClearType.values()), new Function<ClearType, String>() { public String apply(ClearType input) { return input.name().toLowerCase(); } })); } }
Format format = Format.valueOf(StringUtils.defaultIfEmpty(request.getFirstQueryStringParameter("format").toUpperCase(), "JSON")); RetrieveType retrieveType = RetrieveType.valueOf(StringUtils.defaultIfEmpty(request.getFirstQueryStringParameter("type").toUpperCase(), "REQUESTS")); switch (retrieveType) { case LOGS: {
private void addCompletion(final String moduleName, final List<Completion> completions) { final String nonEmptyModuleName = StringUtils.defaultIfEmpty(moduleName, ROOT_MODULE_SYMBOL); completions.add(new Completion(nonEmptyModuleName)); }
protected void activate(final ComponentContext cContext) { context = cContext.getBundleContext(); final File projectDirectory = new File(StringUtils.defaultIfEmpty(OSGiUtils.getRooWorkingDirectory(cContext), FileUtils.CURRENT_DIRECTORY)); projectRootDirectory = FileUtils.getCanonicalPath(projectDirectory); }
protected void activate(final ComponentContext context) { final File projectDirectory = new File(StringUtils.defaultIfEmpty(OSGiUtils.getRooWorkingDirectory(context), CURRENT_DIRECTORY)); rootPath = FileUtils.getCanonicalPath(projectDirectory); }
private PathParameter extractPathVariable(Type type, PathVariable pathVariable) { String paramName = StringUtils.defaultIfEmpty(pathVariable.value(), pathVariable.name()); PathParameter pathParameter = new PathParameter().name(paramName); Property schema = readAsPropertyIfPrimitive(type); if (schema != null) { pathParameter.setProperty(schema); } return pathParameter; }