protected String key(String prefix, String key) { if(Strings.isEmpty(key) || key.equals(".")) { return Strings.removeEnd(prefix, "."); }else{ return prefix + key; } }
protected String removePrefixAndSuffix(String expr) { if (expr.startsWith("#{")) { return Strings.removeEnd(Strings.removeStart(expr, "#{"), "}"); } else { return expr; } } }
@Override protected String parseDelimiter(BufferedReader reader, String delimiter, String line) { if(Strings.startsWithIgnoreCase(line, "delimiter ")) { String newDelimiter = Strings.removeStartIgnoreCase(line, "delimiter").trim(); while(newDelimiter.length() > 0 && newDelimiter.endsWith(delimiter)) { newDelimiter = Strings.removeEnd(newDelimiter, delimiter); } if(newDelimiter.length() > 0) { return newDelimiter; } } return null; }
@Override public <T> Map<String, T> getNamedBeans(Class<? super T> type) { if(Global.context == null) { return null; } Map<String, T> namedBeans = (Map<String,T>)Global.context.getBeansOfType(type); if(namedBeans == null || namedBeans.isEmpty()) { return namedBeans; } final String suffix = type.getSimpleName(); final Map<String, T> beans = new LinkedHashMap<>(); namedBeans.forEach((name, bean) -> { if(shouldReturn(bean) != null) { name = Strings.removeEnd(name, suffix); beans.put(name, bean); } }); return beans; }
public static String[] getLocalePaths(Locale locale, String path,String suffix){ List<String> paths = new ArrayList<String>(); if(null == suffix){ suffix = ""; }else if(path.endsWith(suffix)){ path = Strings.removeEnd(path,suffix); } String lang = null == locale ? null : locale.getLanguage(); String country = null == locale ? null : locale.getCountry(); //{path}_{lang}_{COUNTRY}{suffix} if(!Strings.isEmpty(country)){ paths.add(path + "_" + lang + "_" + country + suffix); } //{path}_{lang}{suffix} if(!Strings.isEmpty(lang)){ paths.add(path + "_" + lang + suffix); } //{path}{suffix} paths.add(path + suffix); return paths.toArray(new String[paths.size()]); }
private static Map<String, String> scanAllIdentifiers(String rootPath, String suffix) { Map<String, String> map = new LinkedHashMap<>(); for(Resource resource : Resources.scan("classpath*:" + rootPath + "/**/*." + suffix)) { String name = Strings.removeStart(resource.getClasspath(), rootPath + "/"); name = Strings.removeEnd(name, "." + suffix); map.put(name, "classpath:" + resource.getClasspath()); } return map; } }
public static String path(String root, Resource file) { String childPath = Urls.decode(Paths.normalize(file.getFilepath())); root = Paths.prefixAndSuffixWithSlash(root); int index = childPath.indexOf(root); if(index <= 0) { throw new IllegalStateException("Invalid root '" + root + "' at '" + file.getURLString() + "'"); } String relativePath = Paths.prefixWithAndSuffixWithoutSlash(childPath.substring(index + root.length())); return Strings.removeEnd(relativePath, "/" + file.getFilename()); }
protected Resource[] findMetaInfClasspathSql(String filename) { final String prefix = "classpath*:META-INF/conf/db/" + name + "/" + filename; Set<Resource> found = new LinkedHashSet<>(); ResourceSet rs = Resources.scan(prefix + "_" + getType().toLowerCase() + ".sql"); rs.forEach(found::add); rs = Resources.scan(prefix + ".sql"); for(Resource untyped : rs) { boolean exists = false; for(Resource typed : found) { //exists -> META-INF/conf/db/{name}/filename_{type}.sql //r -> META-INF/conf/db/{name}/filename.sql String cp = Strings.removeEnd(untyped.getClasspath(),".sql"); if((cp + "_" + getType().toLowerCase() + ".sql").equals(typed.getClasspath())) { exists = true; break; } } if(!exists) { found.add(untyped); } } return found.toArray(new Resource[0]); }
sql.append(Strings.removeEnd(line, "}}")); sqls.add(sql.toString().trim()); sql.delete(0, sql.length());
String location = Strings.removeEnd(req.getRequestURI(), "/login.jsp"); resp.getWriter().write("<script type=\"text/javascript\">top.location='" + location + "';</script>"); return;
name = plugin.getClass().getSimpleName(); if(name.endsWith("Plugin")) { name = Strings.removeEnd(name, "Plugin");
private void configureNested(Object bean, String keyPrefix, ReflectValued member, Configurable.Nested nested) { String nestedPrefix = nested.prefix(); if(Strings.isEmpty(nestedPrefix)) { nestedPrefix = Strings.lowerUnderscore(member.getName()); if(nestedPrefix.endsWith("_config")) { nestedPrefix = Strings.removeEnd(nestedPrefix, "_config"); } } String fullKeyPrefix = keyPrefix(keyPrefix + nestedPrefix); Object nestedBean = member.getValue(bean); BeanType nestedType; if(null == nestedBean) { nestedType = BeanType.of(member.getType()); nestedBean = nestedType.newInstance(); member.setValue(bean, nestedBean); }else{ nestedType = BeanType.of(nestedBean.getClass()); } configure(nestedBean, nestedType, fullKeyPrefix); }