List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.beanfuse.struts2.route.Action.java
public void addParams(String paramStr) { if (null == params) { params = new HashMap(); }//from w ww . j av a 2s . c o m if (StringUtils.isNotEmpty(paramStr)) { String[] paramPairs = StringUtils.split(paramStr, "&"); for (int i = 0; i < paramPairs.length; i++) { String key = StringUtils.substringBefore(paramPairs[i], "="); String value = StringUtils.substringAfter(paramPairs[i], "="); if (StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value)) { params.put(key, value); } } } }
From source file:org.beangle.commons.text.replacer.BatchReplaceMain.java
public static void main(String[] args) throws Exception { if (args.length < 2) { logger.info("using BatchReplaceMain dir patternfile encoding"); return;//from w ww . j a va2 s . co m } String dir = args[0]; if (!new File(dir).exists()) { logger.error("{} not a valid file or directory", dir); return; } String properties = args[1]; if (!new File(properties).exists()) { logger.info("{} not valid file or directory", properties); } String encoding = null; if (args.length >= 3) { encoding = args[2]; } List<String> lines = FileUtils.readLines(new File(properties)); Map<String, List<Replacer>> profiles = CollectUtils.newHashMap(); List<Replacer> replacers = null; for (String line : lines) { if (StringUtils.isEmpty(line)) { continue; } if (-1 == line.indexOf('=')) { replacers = CollectUtils.newArrayList(); profiles.put(line, replacers); } else { line = StringUtils.replace(line, "\\=", "~~~~"); String older = StringUtils.replace(StringUtils.substringBefore(line, "="), "~~~~", "="); String newer = StringUtils.replace(StringUtils.substringAfter(line, "="), "~~~~", "="); older = StringUtils.replace(older, "\\n", "\n"); older = StringUtils.replace(older, "\\t", "\t"); newer = StringUtils.replace(newer, "\\n", "\n"); newer = StringUtils.replace(newer, "\\t", "\t"); Replacer pair = new Replacer(older, newer); replacers.add(pair); } } replaceFile(dir, profiles, encoding); }
From source file:org.beangle.ems.avatar.service.AbstractAvatarBase.java
private int updateFile(File path) { int count = 0; if (path.isDirectory()) { String[] fileNames = path.list(); for (String fileName : fileNames) { File file = new File(path.getAbsolutePath() + "/" + fileName); if (file.isDirectory()) { count += updateFile(file); file.delete();// ww w.ja v a 2 s . c om } else { String type = StringUtils.substringAfter(fileName, "."); boolean passed = containType(type); if (passed) { logger.debug("updating avatar by {}", file.getName()); updateAvatar(StringUtils.substringBefore(fileName, "."), file, type); count++; } file.delete(); } } } return count; }
From source file:org.beangle.ems.avatar.service.FileSystemAvatarBase.java
public Page<String> getAvatarNames(PageLimit limit) { if (null == avatarDir) { logger.error("avatar dir property not config properly"); return Pages.emptyPage(); }/* w w w.j av a 2 s .co m*/ File file = new File(avatarDir); if (!file.exists()) { return Pages.emptyPage(); } String[] names = file.list(); List<String> fileNames = CollectUtils.newArrayList(); for (int i = 0; i < names.length; i++) { String name = StringUtils.substringBefore(names[i], "."); String ext = StringUtils.substringAfter(names[i], "."); if (StringUtils.isNotBlank(name) && containType(ext)) { fileNames.add(name); } } Collections.sort(fileNames); return new PagedList<String>(fileNames, limit); }
From source file:org.beangle.ems.security.restrict.service.RestrictionServiceImpl.java
private List<?> getFieldValues(RestrictField field) { if (null == field.getSource()) return Collections.emptyList(); String source = field.getSource(); String prefix = StringUtils.substringBefore(source, ":"); source = StringUtils.substringAfter(source, ":"); DataProvider provider = providers.get(prefix); if (null != provider) { return provider.getData(field, source); } else {// w w w . ja v a 2 s .c om throw new RuntimeException("not support data provider:" + prefix); } }
From source file:org.beangle.model.persist.hibernate.support.DefaultTableNameConfig.java
private void loadProperties(URL url) { try {/*from w w w. j a va 2 s . co m*/ logger.debug("loading {}", url); InputStream is = url.openStream(); Properties props = new Properties(); if (null != is) { props.load(is); } for (Iterator<Object> iter = props.keySet().iterator(); iter.hasNext();) { String packageName = (String) iter.next(); String schemaPrefix = props.getProperty(packageName).trim(); String schema = null; String prefix = null; String abbreviationStr = null; int commaIndex = schemaPrefix.indexOf(','); if (commaIndex < 0 || (commaIndex + 1 == schemaPrefix.length())) { schema = schemaPrefix; } else if (commaIndex == 0) { prefix = schemaPrefix.substring(1); } else { schema = StringUtils.substringBefore(schemaPrefix, ","); prefix = StringUtils.substringAfter(schemaPrefix, ","); } if (StringUtils.contains(prefix, ",")) { abbreviationStr = StringUtils.substringAfter(prefix, ",").toLowerCase(); prefix = StringUtils.substringBefore(prefix, ","); } TableNamePattern pattern = (TableNamePattern) packagePatterns.get(packageName); if (null == pattern) { pattern = new TableNamePattern(packageName, schema, prefix); packagePatterns.put(packageName, pattern); patterns.add(pattern); } else { pattern.setSchema(schema); pattern.setPrefix(prefix); } if (null != abbreviationStr) { String[] pairs = StringUtils.split(abbreviationStr, ";"); for (String pair : pairs) { String longName = StringUtils.substringBefore(pair, "="); String shortName = StringUtils.substringAfter(pair, "="); pattern.abbreviations.put(longName, shortName); } } } is.close(); } catch (IOException e) { logger.error("property load error", e); } }
From source file:org.beangle.model.transfer.importer.MultiEntityImporter.java
protected EntityType getEntityType(String attr) { String alias = StringUtils.substringBefore(attr, "."); EntityType entityType = (EntityType) entityTypes.get(alias); if (null == entityType) { entityType = (EntityType) entityTypes.get(attr); }/* ww w .j a v a 2 s . c o m*/ return entityType; }
From source file:org.beangle.model.transfer.importer.MultiEntityImporter.java
public Object getCurrent(String attr) { String alias = StringUtils.substringBefore(attr, "."); Object entity = current.get(alias); if (null == entity) { EntityType entityType = (EntityType) entityTypes.get(alias); if (null == entityType) { logger.error("Not register entity type for {}", alias); throw new RuntimeException("Not register entity type for " + alias); } else {/* w w w . ja v a 2 s.co m*/ entity = entityType.newInstance(); current.put(alias, entity); return entity; } } return entity; }
From source file:org.beangle.security.core.AuthenticationException.java
@Override public String getMessage() { String msg = super.getMessage(); if (null == msg) { return StrUtils .concat("security." + StringUtils.substringBefore(getClass().getSimpleName(), "Exception")); } else {//from ww w. ja v a 2s . com return msg; } }
From source file:org.beangle.struts2.action.EntityDrivenAction.java
public String exportDataSelect() { String format = get("format"); String fileName = get("fileName"); String template = get("template"); put("format", format); put("fileName", fileName); put("template", template); String properties = get("properties"); if (StringUtils.isNotEmpty(properties)) { String[] props = StringUtils.split(properties, ","); List<String> keys = CollectUtils.newArrayList(); Map<String, String> titles = CollectUtils.newHashMap(); for (String prop : props) { String key = StringUtils.substringBefore(prop, ":"); System.out.println(key); String value = getTextInternal(StringUtils.substringAfter(prop, ":")); keys.add(key);/*ww w .jav a 2 s . com*/ titles.put(key, value); } put("keys", keys); put("titles", titles); } return forward("/template/exportDataSelect"); }