List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:de.micromata.genome.gwiki.fssvn.DavFileSystem.java
@Override public long getModificationCounter() { FsObject obj = getFileObject(""); if (obj instanceof FsAttributedObject) { FsAttributedObject ao = (FsAttributedObject) obj; String vname = ao.getAttribute("version-name"); if (StringUtils.isNumeric(vname) == true) { return Long.parseLong(vname); }// w ww .j a va2 s. co m } return 0; }
From source file:com.glaf.jbpm.web.rest.MxJbpmProcessViewResource.java
@GET @POST//from ww w . java 2 s . com @Path("image/{processDefinitionId}") @Produces({ MediaType.APPLICATION_OCTET_STREAM }) @ResponseBody public byte[] image(@PathParam("processDefinitionId") String processDefinitionId) { byte[] bytes = null; try { if (StringUtils.isNotEmpty(processDefinitionId) && StringUtils.isNumeric(processDefinitionId)) { bytes = JbpmProcessConfig.getImage(Long.parseLong(processDefinitionId)); } } catch (Exception ex) { ex.printStackTrace(); } return bytes; }
From source file:com.bjond.utilities.MiscUtils.java
public static int defaultIfNotNumeric(final String value, final int defaultValue) { return (StringUtils.isNumeric(value)) ? Integer.parseInt(value) : defaultValue; }
From source file:com.glaf.core.xml.XmlMappingReader.java
protected void readField(Element elem, ColumnModel field) { field.setName(elem.attributeValue("name")); field.setType(elem.attributeValue("type")); field.setColumnName(elem.attributeValue("column")); field.setTitle(elem.attributeValue("title")); field.setSecondTitle(elem.attributeValue("secondTitle")); field.setTrimType(elem.attributeValue("trimType")); field.setValueExpression(elem.attributeValue("valueExpression")); field.setFormat(elem.attributeValue("format")); field.setCurrency(elem.attributeValue("currency")); /**/*w w w. ja va2 s.co m*/ * ??? */ if ("true".equals(elem.attributeValue("temporary"))) { field.setTemporary(true); } /** * */ if ("true".equals(elem.attributeValue("required"))) { field.setRequired(true); } String length = elem.attributeValue("length"); if (StringUtils.isNumeric(length)) { field.setLength(Integer.parseInt(length)); } String precision = elem.attributeValue("precision"); if (StringUtils.isNumeric(precision)) { field.setPrecision(Integer.parseInt(precision)); } String decimal = elem.attributeValue("decimal"); if (StringUtils.isNumeric(decimal)) { field.setDecimal(Integer.parseInt(decimal)); } String position = elem.attributeValue("position"); if (StringUtils.isNumeric(position)) { field.setPosition(Integer.parseInt(position)); } }
From source file:com.cz4031.SAXHandler.java
private void parsePages(String pageStr) { int index = pageStr.indexOf("-"); if (index > 0) { String pageFromStr = pageStr.substring(0, index); String pageToStr = pageStr.substring(index + 1, pageStr.length()); if (pageFromStr.length() > 0 && pageToStr.length() > 0) { if (StringUtils.isNumeric(pageFromStr) && StringUtils.isNumeric(pageToStr)) { int pageFrom = Integer.parseInt(pageFromStr); int pageTo = Integer.parseInt(pageToStr); int pages = pageTo - pageFrom; pages = Math.abs(pages); if (pages > 0) { pages += 1;//from www . j a v a 2 s. c o m } else { pages = 0; } publication.setPages(pages); } else { int pageFrom = romanToDecimal(pageFromStr); int pageTo = romanToDecimal(pageToStr); int pages = pageTo - pageFrom; pages = Math.abs(pages); if (pages > 0) { pages += 1; } else { pages = 0; } publication.setPages(pages); } } } else { if (StringUtils.isNumeric(pageStr)) { int pages = 1; publication.setPages(pages); } else { int pages = 1; publication.setPages(pages); } } }
From source file:attacks.AttackSqlExtended.java
@Override public boolean performNextAttack() { String origParamValue = attackWorkEntry.attackHttpParam.getDecodedValue(); String data;/*from w ww . j av a 2 s .com*/ // Overwrite insert position, as we will always overwrite here attackWorkEntry.insertPosition = PanelLeftInsertions.InsertPositions.REPLACE; if (StringUtils.isNumeric(origParamValue)) { data = getDataInt(attackWorkEntry, origParamValue); } else { data = getDataStr(attackWorkEntry, origParamValue); } try { SentinelHttpMessage httpMessage = attack(data); } catch (ConnectionTimeoutException ex) { BurpCallbacks.getInstance().print("Connection timeout"); state++; return false; } analyzeResponse(); state++; return doContinue; }
From source file:com.interopbridges.tools.windowsazure.JSONHelper.java
/** * Sets the given parameter with given value. * //from w w w . j a v a 2 s. c o m * @param cache * @param param * @param val * @return * @throws WindowsAzureInvalidProjectOperationException */ public static String setParamValue(String cache, String param, String val) throws WindowsAzureInvalidProjectOperationException { try { String decodedCache = decodeHTML(cache); JSONObject cacheObj = new JSONObject(decodedCache); if (!cacheObj.has(param) && param.contains(".")) { String[] params = param.split("\\."); JSONObject newobj = cacheObj; for (int i = 0; i < params.length; i++) { if (params.length - i == 1) { if (StringUtils.isNumeric(val)) { if (params[i].equalsIgnoreCase("isExpirable")) { newobj.put(params[i], Boolean.valueOf(val)); } else { newobj.put(params[i], Integer.valueOf(val)); } } else { newobj.put(params[i], val); } return encodeHTML(cacheObj.toString()); } newobj = (JSONObject) newobj.get(params[i]); } } else { if (StringUtils.isNumeric(val)) { cacheObj.put(param, Integer.valueOf(val)); } else { cacheObj.put(param, val); } } return encodeHTML(cacheObj.toString()); } catch (Exception ex) { throw new WindowsAzureInvalidProjectOperationException(WindowsAzureConstants.EXCP, ex); } }
From source file:com.nridge.core.app.mgr.ServiceTimer.java
private Date getNextTS(String aFieldName, Date aTS) { String timeString = getAppString(aFieldName); if (StringUtils.isNotEmpty(timeString)) { if (StringUtils.endsWithIgnoreCase(timeString, "m")) { String minuteString = StringUtils.stripEnd(timeString, "m"); if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) { int minuteAmount = Integer.parseInt(minuteString); return DateUtils.addMinutes(aTS, minuteAmount); }/* w ww . ja v a2s .c om*/ } else if (StringUtils.endsWithIgnoreCase(timeString, "h")) { String hourString = StringUtils.stripEnd(timeString, "h"); if ((StringUtils.isNotEmpty(hourString)) && (StringUtils.isNumeric(hourString))) { int hourAmount = Integer.parseInt(hourString); return DateUtils.addHours(aTS, hourAmount); } } else // we assume days { String dayString = StringUtils.stripEnd(timeString, "d"); if ((StringUtils.isNotEmpty(dayString)) && (StringUtils.isNumeric(dayString))) { int dayAmount = Integer.parseInt(dayString); return DateUtils.addDays(aTS, dayAmount); } } } // Push 1 hour ahead to avoid triggering a match with TS return DateUtils.addHours(new Date(), 1); }
From source file:edu.usc.lunchnlearn.elasticsearch.interceptor.BreadCrumbInterceptor.java
private Crumb getCurrentCrumb(HttpServletRequest request, Map<String, Long> breadcrumbUrls, Map<Long, Crumb> breadcrumbs, ModelAndView modelAndView) { Crumb crumb = new Crumb(); StringBuffer stringBuffer = request.getRequestURL(); if (request.getQueryString() != null) { stringBuffer.append("?").append(request.getQueryString()); }//from w w w .j av a 2s . c om crumb.setUrl(stringBuffer.toString()); //if the exact URL has already been requested, use that crumb instead of creating a new one. if (breadcrumbUrls.containsKey(crumb.getUrl())) { return breadcrumbs.get(breadcrumbUrls.get(crumb.getUrl())); } //set the display text of the breadcrumb crumb.setDisplayText(""); if (modelAndView.getModelMap().containsAttribute("title")) { crumb.setDisplayText((String) modelAndView.getModelMap().get("title")); } else { for (String uri : uriDisplayTextMapping.keySet()) { if (crumb.getUrl().contains(uri)) { crumb.setDisplayText(uriDisplayTextMapping.get(uri)); break; } } } //set the parent value if (request.getParameterMap().containsKey("x")) { if (StringUtils.isNumeric(request.getParameter("x"))) { crumb.setParentX(Long.parseLong(request.getParameter("x"))); } } //set the time in millis for X crumb.setX(System.currentTimeMillis()); return crumb; }
From source file:com.glaf.ui.web.springmvc.MxConsoleController.java
@RequestMapping public ModelAndView main(ModelMap modelMap, HttpServletRequest request) { LoginContext loginContext = RequestUtils.getLoginContext(request); if (loginContext == null) { return new ModelAndView("/modules/login"); }// w w w . j av a 2 s . c om RequestUtils.setRequestParameterToAttribute(request); String actorId = loginContext.getActorId(); Skin skin = skinService.getUserSkin(actorId); if (skin == null) { skin = skinService.getSkin("blue"); } String treeCode = request.getParameter("treeCode"); if (StringUtils.isEmpty(treeCode)) { if (loginContext.isSystemAdministrator()) { treeCode = "M_SYS"; } else { treeCode = "M_MY"; } } TreeModel root = IdentityFactory.getTreeModelByCode(treeCode); List<TreeModel> treeModels = IdentityFactory.getChildrenTreeModels(root.getId()); Collection<Long> roles = loginContext.getRoleIds(); List<Long> list = new java.util.ArrayList<Long>(); if (roles != null && !roles.isEmpty()) { for (Long r : roles) { list.add(r); } } UserPanel userPanel = panelService.getUserPanel(loginContext.getActorId()); if (userPanel == null) { userPanel = panelService.getUserPanel("system"); } Map<String, Integer> panelPxMap = new java.util.HashMap<String, Integer>(); Map<String, Integer> panelMap = new java.util.HashMap<String, Integer>(); if (userPanel != null && userPanel.getPanelInstances() != null) { String layoutName = userPanel.getLayoutName(); Set<PanelInstance> set = userPanel.getPanelInstances(); Iterator<PanelInstance> iter = set.iterator(); while (iter.hasNext()) { PanelInstance p = iter.next(); if (StringUtils.isNumeric(p.getName())) { int pos = Math.abs(Integer.parseInt(p.getName())); if (pos > 0) { panelPxMap.put(p.getPanelId(), pos); if ("P2".equals(layoutName)) { if (pos % 2 == 1) { panelMap.put(p.getPanelId(), 0); } else { panelMap.put(p.getPanelId(), 1); } } else if ("P3".equals(layoutName)) { if (pos % 3 == 1) { panelMap.put(p.getPanelId(), 0); } else if (pos % 3 == 2) { panelMap.put(p.getPanelId(), 1); } else if (pos % 3 == 0) { panelMap.put(p.getPanelId(), 2); } } else { panelMap.put(p.getPanelId(), 0); } } } } } List<UserPortal> userPortals = userPortalService.getUserPortals(loginContext.getActorId()); if (userPortals == null || userPortals.isEmpty()) { userPortals = userPortalService.getUserPortals("system"); if (userPortals == null || userPortals.isEmpty()) { List<Panel> panels = panelService.getPanels("system"); if (panels != null && !panels.isEmpty()) { int i = 100; for (Panel panel : panels) { UserPortal p = new UserPortal(); p.setActorId(loginContext.getActorId()); p.setPanelId(panel.getId()); if (panelMap.get(panel.getId()) != null) { p.setColumnIndex(panelMap.get(panel.getId())); } else { p.setColumnIndex(0); } if (panelPxMap.get(panel.getId()) != null) { p.setPosition(panelPxMap.get(panel.getId())); } else { p.setPosition(i++); } userPortals.add(p); } userPortalService.save(loginContext.getActorId(), userPortals); userPortals = userPortalService.getUserPortals(loginContext.getActorId()); } } } List<UserPortal> sysPortals = userPortalService.getUserPortals("system"); if (userPortals != null && !userPortals.isEmpty()) { if (sysPortals != null && !sysPortals.isEmpty()) { userPortals.addAll(sysPortals); } for (UserPortal p : userPortals) { String panelId = p.getPanelId(); p.setPanel(panelService.getPanel(panelId)); } } modelMap.put("userPanel", userPanel); modelMap.put("userPortals", userPortals); modelMap.put("root", root); modelMap.put("skin", skin); modelMap.put("treeNodes", treeModels); modelMap.put("treeModels", treeModels); logger.debug("#######################################################"); logger.debug("treeNodes:" + treeModels.size()); Collections.sort(treeModels); TreeHelper treeHelper = new TreeHelper(); JSONObject treeJson = treeHelper.getTreeJson(root, treeModels); modelMap.put("treeJson", treeJson); logger.debug(treeJson.toJSONString()); StringBuffer buffer = new StringBuffer(); String text = treeJson.getString("text"); if (text != null) { buffer.append("\n <li iconCls=\"icon-root\"><span>").append(text).append("</span>"); JSONArray children = treeJson.getJSONArray("children"); if (children != null && !children.isEmpty()) { buffer.append("\n <ul>"); Iterator<Object> iterator = children.iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj instanceof JSONObject) { JSONObject json = (JSONObject) obj; this.fill(json, buffer); } } buffer.append("\n </ul>"); } buffer.append("\n</li>"); } modelMap.put("json", buffer.toString()); logger.debug("#######################################"); logger.debug(loginContext.getRoleIds()); String jx_view = request.getParameter("jx_view"); if (StringUtils.isNotEmpty(jx_view)) { return new ModelAndView(jx_view, modelMap); } String x_view = ViewProperties.getString("sys_console.console"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/console/main", modelMap); }