List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str)
Strips whitespace from the start and end of a String.
From source file:com.htmlhifive.tools.rhino.Main.java
/** * ????.//www .j a v a 2s .c o m * * @param comments ? */ private void cleanComment(SortedSet<Comment> comments) { for (Comment comment : comments) { if (comment.getCommentType() == CommentType.JSDOC) { if (comment.getCommentType() == CommentType.JSDOC) { StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(comment.getValue(), Constants.LINE_SEPARATOR); while (st.hasMoreTokens()) { String token = st.nextToken(); sb.append(StringUtils.strip(token)); sb.append("\n"); } // comment.setJsDoc(sb.toString()); comment.setJsDocNode(new Comment(0, 0, CommentType.JSDOC, sb.toString())); } } } }
From source file:biz.netcentric.cq.tools.actool.validators.impl.AceBeanValidatorImpl.java
@Override public boolean validateActions(final AceBean tmpAclBean) throws InvalidActionException, TooManyActionsException, DoubledDefinedActionException { final String principal = tmpAclBean.getPrincipalName(); if (!StringUtils.isNotBlank(tmpAclBean.getActionsStringFromConfig())) { return false; }/*from w ww . j a va2 s . c o m*/ final String[] actions = tmpAclBean.getActionsStringFromConfig().split(","); if (actions.length > CqActions.ACTIONS.length) { final String errorMessage = getBeanDescription(this.currentBeanCounter, principal) + " too many actions defined!"; LOG.error(errorMessage); throw new TooManyActionsException(errorMessage); } final Set<String> actionsSet = new HashSet<String>(); for (int i = 0; i < actions.length; i++) { // remove leading and trailing blanks from action name actions[i] = StringUtils.strip(actions[i]); if (!Validators.isValidAction(actions[i])) { final String errorMessage = getBeanDescription(this.currentBeanCounter, principal) + ", invalid action: " + actions[i]; LOG.error(errorMessage); throw new InvalidActionException(errorMessage); } if (!actionsSet.add(actions[i])) { final String errorMessage = getBeanDescription(this.currentBeanCounter, principal) + ", doubled defined action: " + actions[i]; LOG.error(errorMessage); throw new DoubledDefinedActionException(errorMessage); } } tmpAclBean.setActions(actions); return true; }
From source file:com.hangum.tadpole.rdb.core.editors.main.composite.QueryHistoryComposite.java
/** * add grid row//from ww w . j a va2 s . c om * * @param reqResultDAO */ private void addRowData(RequestResultDAO reqResultDAO) { GridItem item = new GridItem(gridSQLHistory, SWT.V_SCROLL | SWT.H_SCROLL); String strSQL = StringUtils.strip(reqResultDAO.getStrSQLText()); int intLine = StringUtils.countMatches(strSQL, "\n"); //$NON-NLS-1$ if (intLine >= 1) { int height = (intLine + 1) * 24; if (height > 100) item.setHeight(100); else item.setHeight(height); } item.setText(0, "" + gridSQLHistory.getRootItemCount()); //$NON-NLS-1$ item.setText(1, Utils.dateToStr(reqResultDAO.getStartDateExecute())); item.setText(2, Utils.convLineToHtml(strSQL)); item.setToolTipText(2, strSQL); item.setText(3, "" + ((reqResultDAO.getEndDateExecute().getTime() - reqResultDAO.getStartDateExecute().getTime()) //$NON-NLS-1$ / 1000f)); item.setText(4, "" + reqResultDAO.getRows()); //$NON-NLS-1$ item.setText(5, reqResultDAO.getResult()); item.setText(6, Utils.convLineToHtml(reqResultDAO.getMesssage())); item.setToolTipText(6, reqResultDAO.getMesssage()); if ("F".equals(reqResultDAO.getResult())) { //$NON-NLS-1$ item.setBackground(SWTResourceManager.getColor(240, 180, 167)); } }
From source file:com.neusoft.mid.clwapi.service.homePage.HomePageServiceImpl.java
/** * ???/*from www . jav a 2s. c o m*/ * * @param uptime * @return */ // ??? private Date[] getEtag(String uptime) { if (StringUtils.isEmpty(uptime)) { logger.error(""); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } // ? String[] s = StringUtils.split(uptime, "|"); Date[] d = new Date[s.length]; if (s.length != 2) { logger.error("????[" + s.length + "]"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } for (int i = 0; i < s.length; i++) { s[i] = StringUtils.strip(s[i]); if (!s[i].equals(HttpConstant.TIME_ZERO)) { try { d[i] = TimeUtil.parseStringToDate(s[i], HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("?" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } else { s[i] = null; } } return d; }
From source file:biz.netcentric.cq.tools.actool.validators.impl.AceBeanValidatorImpl.java
@Override public boolean validatePrivileges(final AceBean tmpAclBean, AccessControlManager aclManager) throws InvalidJcrPrivilegeException, DoubledDefinedJcrPrivilegeException { final String currentEntryValue = tmpAclBean.getPrivilegesString(); final String principal = tmpAclBean.getPrincipalName(); if (!StringUtils.isNotBlank(currentEntryValue)) { return false; }/*from www. j a v a 2s . co m*/ final String[] privileges = currentEntryValue.split(","); final Set<String> privilegesSet = new HashSet<String>(); for (int i = 0; i < privileges.length; i++) { // remove leading and trailing blanks from privilege name privileges[i] = StringUtils.strip(privileges[i]); if (!Validators.isValidJcrPrivilege(privileges[i], aclManager)) { final String errorMessage = getBeanDescription(this.currentBeanCounter, principal) + ", invalid jcr privilege: " + privileges[i]; LOG.error(errorMessage); throw new InvalidJcrPrivilegeException(errorMessage); } if (!privilegesSet.add(privileges[i])) { final String errorMessage = getBeanDescription(this.currentBeanCounter, principal) + ", doubled defined jcr privilege: " + privileges[i]; LOG.error(errorMessage); throw new DoubledDefinedJcrPrivilegeException(errorMessage); } } tmpAclBean.setPrivilegesString(currentEntryValue); return true; }
From source file:com.neusoft.mid.clwapi.service.tacks.TacksServiceImpl.java
/** * ???.//from w ww . ja v a 2s. c o m * * @param token * ?. * * @param vin * vin?. * * @param alarmTime * ,?yyyymmddhh24miss. * * @param alarmID * ID. * @return . */ @Override public Response getVinTackByAlarm(String token, String alarmID, String vin, String alarmTime) { vin = StringUtils.strip(vin); alarmID = StringUtils.strip(alarmID); alarmTime = StringUtils.strip(alarmTime); logger.info("vin?:" + vin + ",:" + alarmTime + ",ID:" + alarmID); try { TimeUtil.parseStringToDate(alarmTime, HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.info("-?" + alarmTime + "??yyyyMMddHHmmss"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } List<TackResp> trackList = tcMapper.getRunRecsByTime(vin, alarmTime); if (CheckRequestParam.isEmpty(trackList)) { logger.info("-VIN:" + vin + "" + alarmTime + ""); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } TackResp driveRec = trackList.get(0); return Response.ok(JacksonUtils.toJsonRuntimeException(driveRec)) .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build(); }
From source file:com.redhat.rhn.frontend.action.monitoring.notification.BaseFilterEditAction.java
private String[] validateDestination(ActionErrors errors, DynaActionForm form) { String dest = form.getString(DEST); if (StringUtils.isBlank(dest)) { return new String[0]; }//w w w.j av a 2s . c o m String[] addr = StringUtils.split(dest, ","); for (int i = 0; i < addr.length; i++) { addr[i] = StringUtils.strip(addr[i]); if (!RhnValidationHelper.isValidEmailAddress(addr[i])) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.addr_invalid", addr[i])); } } return addr; }
From source file:com.neusoft.mid.clwapi.service.msg.MsgServiceImpl.java
/** * ???./*from w w w. j a v a2s . c om*/ * * @param token * ?. * @param tempId * ??ID. * @param remark * ???. * @return ETag. */ @Override public String eidtMsgMold(String token, String tempId, String remark) { tempId = StringUtils.strip(tempId); MsgMoldReq req = JacksonUtils.fromJsonRuntimeException(remark, MsgMoldReq.class); try { BeanUtil.checkObjectLegal(req); } catch (Exception e) { logger.error("??-???" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } String userId = context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID); if (CheckRequestParam.isEmpty(userId)) { logger.info("??-ID"); throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR); } int num = msgMapper.getMsgMoldCount(tempId, userId); if (num == 0) { logger.info("??-?" + tempId + "?"); throw new ApplicationException(ErrorConstant.ERROR10010, Response.Status.NOT_FOUND); } logger.info("??-??"); MsgMoldInfo obj = new MsgMoldInfo(); obj.setId(tempId); obj.setUserId(userId); obj.setRemark(req.getTtmsg_remark()); msgMapper.updateUserMsgMold(obj); logger.info("??-??"); obj = msgMapper.getMsgMoldInfo(obj); if (CheckRequestParam.isEmpty(obj) || CheckRequestParam.isEmpty(obj.getId())) { logger.info("??-?" + tempId + "?"); throw new ApplicationException(ErrorConstant.ERROR10010, Response.Status.NOT_FOUND); } logger.info("??-??ETag"); upUserETag(token, userId, obj.getEditT()); MsgMoldResp result = new MsgMoldResp(); result.setEditT(obj.getEditT()); return JacksonUtils.toJsonRuntimeException(result); }
From source file:com.neusoft.mid.clwapi.service.statistics.StatisticsServiceImpl.java
/** * ??./*from w w w . j a va 2 s . c om*/ * * @param token * ?. * @param month * ,?yyyymm * @return ??. */ @Override public Response getEntiReport(String token, String month) { month = StringUtils.strip(month); String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID); logger.info("?-?ID:" + epid + "," + month); Date reportMonth; try { reportMonth = TimeUtil.parseStringToDate(month, HttpConstant.MONTH_FORMAT); } catch (ParseException e) { logger.error("?-yyyyMM?" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } if (reportMonth.after(TimeUtil.getLastMonthD())) { logger.info("?-??" + month + "?"); throw new ApplicationException(ErrorConstant.ERROR10004, Response.Status.BAD_REQUEST); } if (CheckRequestParam.isEmpty(epid)) { logger.info("?--?ID"); throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR); } List<EpMonthData> infos = stMapper.getEpMonthData(month, epid); if (CheckRequestParam.isEmpty(infos)) { logger.info("?-?ID:" + epid + "???"); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } EpStatReport resp = convertEpResp(infos, reportMonth); if (CheckRequestParam.isEmpty(resp)) { logger.info("?-?ID:" + epid + "???"); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } return Response.ok(JacksonUtils.toJsonRuntimeException(resp)).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); }
From source file:c5db.tablet.TabletService.java
private String launchTablet(String commandString) throws IOException, DeserializationException { BASE64Decoder decoder = new BASE64Decoder(); String createString = commandString.substring(commandString.indexOf(":") + 1); String[] tableCreationStrings = createString.split(","); HTableDescriptor hTableDescriptor = HTableDescriptor .parseFrom(decoder.decodeBuffer(tableCreationStrings[0])); HRegionInfo hRegionInfo = HRegionInfo.parseFrom(decoder.decodeBuffer(tableCreationStrings[1])); List<Long> peers = new ArrayList<>(); for (String s : Arrays.copyOfRange(tableCreationStrings, 2, tableCreationStrings.length)) { s = StringUtils.strip(s); peers.add(new Long(s)); }// www . j a v a 2 s.c o m startTabletHere(hTableDescriptor, hRegionInfo, ImmutableList.copyOf(peers)); return "OK"; }