List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:cn.hxh.springside.orm.PropertyFilter.java
/** * @param filterName ,???. // www . j ava 2s .c o m * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ObjectMapper.convertToObject(value, propertyClass); }
From source file:com.bstek.dorado.view.resolver.VelocityInterceptorDirective.java
@SuppressWarnings("rawtypes") protected void intercept(InternalContextAdapter contextAdapter, Writer writer, Node node) throws Exception { int paramNum = node.jjtGetNumChildren(); if (paramNum == 0) { throw new IllegalArgumentException("No interceptor name defined in #interceptor."); }/*from w w w . jav a2 s . c o m*/ String interceptorName = (String) node.jjtGetChild(0).value(contextAdapter); if (StringUtils.isEmpty(interceptorName)) { throw new IllegalArgumentException("The interceptor name defined in #interceptor can not be empty."); } if (interceptorName.indexOf('#') <= 0) { throw new IllegalArgumentException("Invalid interceptor name [" + interceptorName + "]."); } String beanName = StringUtils.substringBefore(interceptorName, "#"); String methodName = StringUtils.substringAfter(interceptorName, "#"); if (StringUtils.isEmpty(methodName)) { throw new IllegalArgumentException("Invalid interceptor name [" + interceptorName + "]."); } if (paramNum > 2) { throw new IllegalArgumentException("Too more arguments defined in #interceptor."); } Map parameterMap = null; if (paramNum == 2) { parameterMap = (Map) node.jjtGetChild(1).value(contextAdapter); } Object bean = BeanFactoryUtils.getBean(beanName); Method[] methods = MethodAutoMatchingUtils.getMethodsByName(bean.getClass(), methodName); if (methods.length == 0) { throw new IllegalArgumentException("No method found for [" + interceptorName + "]."); } else if (methods.length > 1) { throw new IllegalArgumentException("More than one method found for [" + interceptorName + "]."); } Method method = methods[0]; View view = (View) contextAdapter.get("view"); Class<?>[] parameterTypes = method.getParameterTypes(); String[] parameterNames = MethodAutoMatchingUtils.getParameterNames(method); Object[] parameters = new Object[parameterTypes.length]; int i = 0; for (Class<?> parameterType : parameterTypes) { if (Writer.class.isAssignableFrom(parameterType)) { /* Writer */ parameters[i] = writer; } else if (Context.class.isAssignableFrom(parameterType)) { /* Velocity Context */ parameters[i] = contextAdapter; } else if (ViewElement.class.isAssignableFrom(parameterType)) { /* Component or View */ String parameterName = parameterNames[i]; if ("view".equals(parameterName)) { parameters[i] = view; } else { parameters[i] = view.getViewElement(parameterName); } } else if (parameterMap != null) { /* from ParameterMap */ String parameterName = parameterNames[i]; parameters[i] = parameterMap.get(parameterName); } i++; } method.invoke(bean, parameters); }
From source file:net.osxx.controller.admin.StatisticsController.java
/** * /*from www . j a v a 2s .c o m*/ */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/osxx.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:net.shopxx.controller.admin.StatisticsController.java
/** * //from www .j a v a2s . c o m */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/shopxx.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:cn.newtouch.util.orm.PropertyFilter.java
/** * @param filterName/* w ww .j a v a 2 s . c om*/ * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { this.matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { this.propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); this.propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, this.propertyClass); }
From source file:net.groupbuy.controller.admin.StatisticsController.java
/** * /*from w ww. j a va 2 s . c om*/ */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/groupbuy.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:com.dp2345.controller.admin.StatisticsController.java
/** * //from w w w .ja va2s .c o m */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/dp2345.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:gov.nih.nci.caarray.application.GenericDataServiceBean.java
/** * {@inheritDoc}/*ww w . ja v a2s .co m*/ */ @Override public String getIncrementingCopyName(Class<?> entityClass, String fieldName, String name) { final String alphaPrefix = StringUtils.stripEnd(name, "0123456789"); final String numericSuffix = StringUtils.substringAfter(name, alphaPrefix); int maxSuffix = StringUtils.isEmpty(numericSuffix) ? 1 : Integer.parseInt(numericSuffix); final List<String> currentNames = this.searchDao.findValuesWithSamePrefix(entityClass, fieldName, alphaPrefix); for (final String currentName : currentNames) { final String suffix = StringUtils.substringAfter(currentName, alphaPrefix); if (!StringUtils.isNumeric(suffix) || StringUtils.isEmpty(suffix)) { continue; } maxSuffix = Math.max(maxSuffix, Integer.parseInt(suffix)); } return alphaPrefix + (maxSuffix + 1); }
From source file:com.safetys.framework.jmesa.core.preference.PropertiesPreferences.java
private InputStream getInputStream(String preferencesLocation, WebContext webContext) throws IOException { if (preferencesLocation.startsWith("WEB-INF")) { String path = webContext.getRealPath("WEB-INF"); String name = StringUtils.substringAfter(preferencesLocation, "WEB-INF/"); return new FileInputStream(path + "/" + name); }/* w w w . j av a 2 s. co m*/ return this.getClass().getResourceAsStream(preferencesLocation); }
From source file:cn.com.p2p.framework.util.Struts2Utils.java
/** * .//from www. j a va 2s . c o m * * eg. <br/> * render("text/plain", "hello", "encoding:GBK"); <br/> * render("text/plain", "hello", "no-cache:false"); <br/> * render("text/plain", "hello", "encoding:GBK", "no-cache:false"); * * @param headers * ??header??"encoding:""no-cache:",UTF-8true. */ public static void render(final String contentType, final String content, final String... headers) { try { // ?headers? String encoding = ENCODING_DEFAULT; boolean noCache = NOCACHE_DEFAULT; for (String header : headers) { String headerName = StringUtils.substringBefore(header, ":"); String headerValue = StringUtils.substringAfter(header, ":"); if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) { encoding = headerValue; } else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) { noCache = Boolean.parseBoolean(headerValue); } else { throw new IllegalArgumentException(headerName + "??header"); } } HttpServletResponse response = ServletActionContext.getResponse(); // headers? String fullContentType = contentType + ";charset=" + encoding; response.setContentType(fullContentType); if (noCache) { response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); } response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { logger.error(e.getMessage(), e); } }