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:org.b3log.symphony.processor.LoginProcessor.java
/** * Shows registration page.//from ww w . jav a 2 s .co m * * @param context the specified context * @param request the specified request * @param response the specified response * @throws Exception exception */ @RequestProcessing(value = "/register", method = HTTPRequestMethod.GET) @Before(adviceClass = StopwatchStartAdvice.class) @After(adviceClass = StopwatchEndAdvice.class) public void showRegister(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final AbstractFreeMarkerRenderer renderer = new SkinRenderer(); context.setRenderer(renderer); final Map<String, Object> dataModel = renderer.getDataModel(); dataModel.put(Common.REFERRAL, ""); String referral = request.getParameter("r"); if (!Strings.isEmptyOrNull(referral)) { dataModel.put(Common.REFERRAL, referral); } final String code = request.getParameter("code"); if (Strings.isEmptyOrNull(code)) { // Register Step 1 renderer.setTemplateName("register.ftl"); } else { // Register Step 2 final JSONObject verifycode = verifycodeQueryService.getVerifycode(code); if (null == verifycode) { dataModel.put(Keys.MSG, langPropsService.get("verifycodeExpiredLabel")); renderer.setTemplateName("/error/custom.ftl"); } else { renderer.setTemplateName("register2.ftl"); final String userId = verifycode.optString(Verifycode.USER_ID); final JSONObject user = userQueryService.getUser(userId); dataModel.put(User.USER, user); referral = StringUtils.substringAfter(code, "r="); if (!Strings.isEmptyOrNull(referral)) { dataModel.put(Common.REFERRAL, referral); } } } filler.fillHeaderAndFooter(request, response, dataModel); dataModel.put(Common.TEAMS, Symphonys.get(Common.TEAMS).split(",")); dataModel.put(Common.EMAIL_DOMAIN, Symphonys.get(Common.EMAIL_DOMAIN)); }
From source file:org.b3log.xiaov.service.QQService.java
/** * Initializes QQ client./*from www.j a v a2 s .c o m*/ */ public void initQQClient() { LOGGER.info("??"); xiaoV = new SmartQQClient(new MessageCallback() { @Override public void onMessage(final Message message) { new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(500 + RandomUtils.nextInt(1000)); final String content = message.getContent(); final String key = XiaoVs.getString("qq.bot.key"); if (!StringUtils.startsWith(content, key)) { // ????? // ?? xiaoV.sendMessageToFriend(message.getUserId(), XIAO_V_INTRO); return; } final String msg = StringUtils.substringAfter(content, key); LOGGER.info("Received admin message: " + msg); sendToPushQQGroups(msg); } catch (final Exception e) { LOGGER.log(Level.ERROR, "XiaoV on group message error", e); } } }).start(); } @Override public void onGroupMessage(final GroupMessage message) { new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(500 + RandomUtils.nextInt(1000)); onQQGroupMessage(message); } catch (final Exception e) { LOGGER.log(Level.ERROR, "XiaoV on group message error", e); } } }).start(); } @Override public void onDiscussMessage(final DiscussMessage message) { new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(500 + RandomUtils.nextInt(1000)); onQQDiscussMessage(message); } catch (final Exception e) { LOGGER.log(Level.ERROR, "XiaoV on group message error", e); } } }).start(); } }); // Load groups & disscusses reloadGroups(); reloadDiscusses(); LOGGER.info("??"); if (MSG_ACK_ENABLED) { // ??? LOGGER.info("??https://github.com/b3log/xiaov/issues/3"); xiaoVListener = new SmartQQClient(new MessageCallback() { @Override public void onMessage(final Message message) { try { Thread.sleep(500 + RandomUtils.nextInt(1000)); final String content = message.getContent(); final String key = XiaoVs.getString("qq.bot.key"); if (!StringUtils.startsWith(content, key)) { // ?? // ?? xiaoVListener.sendMessageToFriend(message.getUserId(), XIAO_V_LISTENER_INTRO); return; } final String msg = StringUtils.substringAfter(content, key); LOGGER.info("Received admin message: " + msg); sendToPushQQGroups(msg); } catch (final Exception e) { LOGGER.log(Level.ERROR, "XiaoV on group message error", e); } } @Override public void onGroupMessage(final GroupMessage message) { final String content = message.getContent(); if (GROUP_SENT_MSGS.contains(content)) { // indicates message received GROUP_SENT_MSGS.remove(content); } } @Override public void onDiscussMessage(final DiscussMessage message) { final String content = message.getContent(); if (DISCUSS_SENT_MSGS.contains(content)) { // indicates message received DISCUSS_SENT_MSGS.remove(content); } } }); LOGGER.info("??"); } LOGGER.info("? QQ ??"); }
From source file:org.beanfuse.bean.comparators.PropertyComparator.java
/** * new OrderedBeanComparator("id") or<br> * new OrderedBeanComparator("name desc"); new * OrderedBeanComparator("[0].name desc"); * // w w w . j a v a 2 s. c o m * @param cmpStr */ public PropertyComparator(final String cmpStr) { if (StringUtils.isEmpty(cmpStr)) { return; } if (StringUtils.contains(cmpStr, ',')) { throw new RuntimeException( "PropertyComparator don't suport comma based order by." + " Use MultiPropertyComparator "); } cmpWhat = cmpStr.trim(); // ?[]? if ('[' == cmpWhat.charAt(0)) { index = NumberUtils.toInt(StringUtils.substringBetween(cmpWhat, "[", "]")); cmpWhat = StringUtils.substringAfter(cmpWhat, "]"); if ('.' == cmpWhat.charAt(0)) { cmpWhat = cmpWhat.substring(1); } } // ?? asc = true; if (StringUtils.contains(cmpWhat, ' ')) { if (StringUtils.contains(cmpWhat, " desc")) { asc = false; } cmpWhat = cmpWhat.substring(0, cmpWhat.indexOf(' ')); } stringComparator = new CollatorStringComparator(asc); }
From source file:org.beanfuse.struts2.plugin.result.DefaultResultBuilder.java
public Result build(String resultCode, ActionConfig actionConfig, ActionContext context) { String path = null;//from w w w .jav a2 s .c om ResultTypeConfig resultTypeConfig = null; Map params = new HashMap(); log.debug("result code:{} for actionConfig:{}", resultCode, actionConfig); if (null == resultTypeConfigs) { PackageConfig pc = configuration.getPackageConfig(actionConfig.getPackageName()); this.resultTypeConfigs = pc.getAllResultTypeConfigs(); } // prefix // TODO jsp,vm,ftl if (!StringUtils.contains(resultCode, ':')) { String className = context.getActionInvocation().getProxy().getAction().getClass().getName(); String methodName = context.getActionInvocation().getProxy().getMethod(); if (StringUtils.isEmpty(resultCode)) { resultCode = "index"; } StringBuilder buf = new StringBuilder(); buf.append(viewMapper.getViewPath(className, methodName, resultCode)); buf.append('.'); buf.append(profileService.getProfile(className).getViewExtension()); path = buf.toString(); resultTypeConfig = (ResultTypeConfig) resultTypeConfigs.get("freemarker"); } else { String prefix = StringUtils.substringBefore(resultCode, ":"); resultTypeConfig = (ResultTypeConfig) resultTypeConfigs.get(prefix); String redirectParamStr = null; if (prefix.startsWith("redirect")) { redirectParamStr = ServletActionContext.getRequest().getParameter("params"); } Action action = (Action) ActionContext.getContext().getContextMap().get("dispatch_action"); if (null != action) { if (null != action.getClazz()) { action.setName(actionNameBuilder.build(action.getClazz().getName())); } if (StringUtils.isBlank(action.getName())) { String t_path = ServletActionContext.getRequest().getServletPath(); if (StringUtils.isBlank(t_path)) { // webspheret_pathworkaround t_path = ServletActionContext.getRequest().getRequestURI(); t_path = t_path.substring(t_path.indexOf('/', 1)); action.setName(t_path); } else action.setName(t_path); } path = buildAction(action, params, redirectParamStr); } else { path = buildAction(StringUtils.substringAfter(resultCode, ":"), params, redirectParamStr); } } return buildResult(path, resultCode, resultTypeConfig, context, params); }
From source file:org.beanfuse.struts2.plugin.result.DefaultResultBuilder.java
/** * ??/* w w w .j av a 2 s.c o m*/ * * @param path * @param param * @param redirectParamStr * @return */ private String buildAction(String path, Map<String, Object> param, String redirectParamStr) { String newPath = path; if (path.startsWith("?")) { newPath = ServletActionContext.getRequest().getServletPath() + path; } // ???? if (null != redirectParamStr) { if (newPath.indexOf('?') == -1) { newPath += ('?' + redirectParamStr.substring(1)); } else { newPath += redirectParamStr; } } String paramString = StringUtils.substringAfter(newPath, "?"); if (null != paramString) { Map requestParams = new HashMap(); paramString = StringUtils.replace(paramString, "?", ""); String[] paramPairs = StringUtils.split(paramString, "&"); for (int i = 0; i < paramPairs.length; i++) { String name = StringUtils.substringBefore(paramPairs[i], "="); String value = StringUtils.substringAfter(paramPairs[i], "="); if (name == "method") { param.put("method", value); } requestParams.put(name, value); } if (!requestParams.isEmpty()) { param.put("requestParameters", requestParams); } } return addNamespaceAction(newPath, param); }
From source file:org.beanfuse.struts2.route.Action.java
public void addParams(String paramStr) { if (null == params) { params = new HashMap(); }/*from w ww . j a v a2 s. co 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.beanfuse.utils.multilevelseq.SeqPattern.java
public SeqPattern(SeqNumStyle seqStyle, String pattern) { this.seqNumStyle = seqStyle; this.pattern = pattern; String remainder = pattern;//from w ww.j a va 2s . c o m while (StringUtils.isNotEmpty(remainder)) { String p = StringUtils.substringBetween(remainder, "{", "}"); if (StringUtils.isEmpty(p)) { break; } if (NumberUtils.isDigits(p)) { params.add(new Integer(p)); } remainder = StringUtils.substringAfter(remainder, "{" + p + "}"); } Collections.sort(params); this.level = ((Integer) params.get(params.size() - 1)).intValue(); params.remove(params.size() - 1); }
From source file:org.beangle.commons.comparators.PropertyComparator.java
/** * new OrderedBeanComparator("id") or<br> * new OrderedBeanComparator("name desc"); new * OrderedBeanComparator("[0].name desc"); * //from w w w .j a v a2 s .c o m * @param cmpStr */ public PropertyComparator(final String cmpStr) { if (StringUtils.isEmpty(cmpStr)) { return; } if (StringUtils.contains(cmpStr, ',')) { throw new RuntimeException( "PropertyComparator don't suport comma based order by." + " Use MultiPropertyComparator "); } cmpWhat = cmpStr.trim(); // ?[]? if ('[' == cmpWhat.charAt(0)) { index = NumberUtils.toInt(StringUtils.substringBetween(cmpWhat, "[", "]")); cmpWhat = StringUtils.substringAfter(cmpWhat, "]"); if (cmpWhat.length() > 0 && '.' == cmpWhat.charAt(0)) { cmpWhat = cmpWhat.substring(1); } } // ?? asc = true; if (StringUtils.contains(cmpWhat, ' ')) { if (StringUtils.contains(cmpWhat, " desc")) { asc = false; } cmpWhat = cmpWhat.substring(0, cmpWhat.indexOf(' ')); } stringComparator = new CollatorStringComparator(asc); }
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;// ww w .java 2s . c o 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();//from w w w . j a v a2s. c o m } 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; }