Example usage for org.apache.commons.lang3 StringUtils isNumeric

List of usage examples for org.apache.commons.lang3 StringUtils isNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isNumeric.

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:com.glaf.core.web.springmvc.MxSystemSequenceController.java

@RequestMapping("/saveAll")
public ModelAndView saveAll(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);

    List<Dbid> rows = tableDataService.getAllDbids();
    if (rows != null && !rows.isEmpty()) {
        for (Dbid dbid : rows) {
            String value = request.getParameter(dbid.getName());
            if (StringUtils.isNotEmpty(value) && StringUtils.isNumeric(value)) {
                dbid.setValue(value);/*from   w w  w.  j a v  a2 s  . com*/
            }
        }
        tableDataService.updateAllDbids(rows);
    }

    String jx_view = request.getParameter("jx_view");

    if (StringUtils.isNotEmpty(jx_view)) {
        return new ModelAndView(jx_view, modelMap);
    }

    String x_view = ViewProperties.getString("sys_sequence.edit");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }
    return this.edit(request, modelMap);
}

From source file:com.glaf.jbpm.web.springmvc.MxJbpmProcessTreeController.java

@RequestMapping("/json")
public ModelAndView json(HttpServletRequest request) {
    RequestUtils.setRequestParameterToAttribute(request);
    String node = request.getParameter("node");
    String process_name = null;/*from ww  w .j a v  a  2  s .co m*/
    String processDefinitionId = null;
    if (StringUtils.isNotEmpty(node)) {
        if (StringUtils.startsWith(node, "x_pdid:")) {
            processDefinitionId = StringUtils.replace(node, "x_pdid:", "");
        } else if (StringUtils.startsWith(node, "x_pdname:")) {
            process_name = StringUtils.replace(node, "x_pdname:", "");
        }
    }
    logger.debug("process_name:" + process_name);
    logger.debug("processDefinitionId:" + processDefinitionId);
    List<ProcessDefinition> result = null;
    GraphSession graphSession = null;
    JbpmContext jbpmContext = null;
    try {
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();
        graphSession = jbpmContext.getGraphSession();
        if (StringUtils.isNotEmpty(process_name)) {
            result = graphSession.findAllProcessDefinitionVersions(process_name);
        } else {
            result = graphSession.findAllProcessDefinitions();
        }
        if (StringUtils.isNotEmpty(processDefinitionId) && StringUtils.isNumeric(processDefinitionId)) {
            ProcessDefinition pd = graphSession.getProcessDefinition(Long.parseLong(processDefinitionId));
            if (pd != null) {
                Map<String, Task> tasks = pd.getTaskMgmtDefinition().getTasks();
                if (tasks != null) {
                    List<Task> rows = new java.util.ArrayList<Task>();
                    Iterator<Task> iterator = tasks.values().iterator();
                    while (iterator.hasNext()) {
                        Task task = iterator.next();
                        rows.add(task);
                    }
                    request.setAttribute("tasks", rows);
                    request.setAttribute("processDefinition", pd);
                }
            }
        }
        request.setAttribute("rows", result);
    } catch (Exception ex) {
        logger.debug(ex);
    } finally {
        Context.close(jbpmContext);
    }

    String jx_view = request.getParameter("jx_view");

    if (StringUtils.isNotEmpty(jx_view)) {
        return new ModelAndView(jx_view);
    }

    String x_view = ViewProperties.getString("jbpm_tree.json");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view);
    }

    return new ModelAndView("/jbpm/tree/json");
}

From source file:com.omertron.yamjtrakttv.tools.TraktTools.java

public static TvShow getTvShowSummary(Video video) {
    TvShow tvshow;/*from w w w  . ja va 2s . c  o  m*/

    video.setSearchOnTrakt(Boolean.TRUE);
    try {
        if (StringUtils.isNumeric(video.getId(Video.ID_TVDB))) {
            tvshow = MANAGER.showService().summary(video.getId(Video.ID_TVDB)).fire();
        } else {
            tvshow = MANAGER.showService().summary(video.getTitle()).fire();
            video.addId(Video.ID_TVDB, tvshow.tvdbId);
            video.addId(Video.ID_IMDB, tvshow.imdbId);
        }
    } catch (TraktException ex) {
        LOG.debug(
                "Error getting information for TV show: " + video.getTitle() + " - Error: " + ex.getMessage());
        video.setFoundOnTrakt(Boolean.FALSE);
        tvshow = null;
    }

    if (tvshow != null) {
        video.getSummaryInfo().addSummaryInfo(tvshow);
        video.setFoundOnTrakt(Boolean.TRUE);
    }
    return tvshow;
}

From source file:com.glaf.core.web.springmvc.MxDiskFileUploadJsonController.java

@RequestMapping
public void upload(HttpServletRequest request, HttpServletResponse response) throws Exception {
    response.setContentType("text/html; charset=UTF-8");
    String businessKey = request.getParameter("businessKey");
    String serviceKey = request.getParameter("serviceKey");
    // ?//from   w  ww .jav  a2 s .  co  m
    LoginContext loginContext = RequestUtils.getLoginContext(request);
    String savePath = SystemProperties.getAppPath() + "/upload/" + loginContext.getUser().getId() + "/";
    // ?URL
    String saveUrl = request.getContextPath() + "/upload/" + loginContext.getUser().getId() + "/";
    if (StringUtils.isNotEmpty(serviceKey)) {
        saveUrl = saveUrl + serviceKey + "/";
    }
    // ???
    String[] fileTypes = new String[] { "gif", "jpg", "jpeg", "png", "bmp", "swf" };
    // ?
    long maxSize = 10240000;

    String allowSize = CustomProperties.getString("upload.maxSize");
    if (StringUtils.isEmpty(allowSize)) {
        allowSize = SystemProperties.getString("upload.maxSize");
    }

    if (StringUtils.isNotEmpty(allowSize) && StringUtils.isNumeric(allowSize)) {
        maxSize = Long.parseLong(allowSize);
    }

    // 
    File uploadDir = new File(savePath);
    try {
        if (!uploadDir.exists()) {
            FileUtils.mkdirs(savePath);
        }
    } catch (Exception ex) {
    }

    if (!uploadDir.isDirectory()) {
        response.getWriter().write(getError("?"));
        return;
    }
    // ??
    if (!uploadDir.canWrite()) {
        response.getWriter().write(getError("??"));
        return;
    }

    MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = req.getFileMap();
    Set<Entry<String, MultipartFile>> entrySet = fileMap.entrySet();
    for (Entry<String, MultipartFile> entry : entrySet) {
        MultipartFile mFile = entry.getValue();
        if (mFile.getOriginalFilename() != null && mFile.getSize() > 0) {
            // ?
            if (mFile.getSize() > maxSize) {
                response.getWriter().write(getError("??"));
                return;
            }
            String fileName = mFile.getOriginalFilename();
            // ??
            String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
            if (!Arrays.<String>asList(fileTypes).contains(fileExt)) {
                response.getWriter().write(getError("??????"));
                return;
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
            String newFileName = df.format(new Date()) + "_" + new Random().nextInt(10000) + "." + fileExt;
            try {
                DataFile dataFile = new BlobItemEntity();
                dataFile.setBusinessKey(businessKey);
                dataFile.setCreateBy(loginContext.getActorId());
                dataFile.setCreateDate(new Date());
                dataFile.setFileId(newFileName);
                dataFile.setLastModified(System.currentTimeMillis());
                dataFile.setName(fileName);
                if (StringUtils.isNotEmpty(serviceKey)) {
                    dataFile.setServiceKey(serviceKey);
                } else {
                    dataFile.setServiceKey("IMG_" + loginContext.getActorId());
                }
                dataFile.setFilename(fileName);
                dataFile.setType(fileExt);
                dataFile.setSize(mFile.getSize());
                dataFile.setStatus(1);
                blobService.insertBlob(dataFile);

                FileUtils.save(savePath + sp + newFileName, mFile.getInputStream());

            } catch (Exception ex) {
                ex.printStackTrace();
                response.getWriter().write(getError("?"));
                return;
            }

            JSONObject object = new JSONObject();
            object.put("error", 0);
            object.put("url", saveUrl + newFileName);
            response.getWriter().write(object.toString());
        }
    }
}

From source file:com.glaf.core.domain.SystemProperty.java

public double getDoubleValue() {
    if (StringUtils.isNotEmpty(value) && StringUtils.isNumeric(value)) {
        return Double.parseDouble(value);
    }/*ww  w  .  jav  a 2 s .  c om*/
    if (StringUtils.isNotEmpty(initValue) && StringUtils.isNumeric(initValue)) {
        return Double.parseDouble(initValue);
    }
    return -1;
}

From source file:com.glaf.template.TemplateReader.java

@SuppressWarnings("unchecked")
public Map<String, Template> getTemplates(InputStream inputStream) {
    Map<String, Template> dataMap = new java.util.HashMap<String, Template>();
    Element root = this.getRootElement(inputStream);
    List<?> templates = root.elements("template");
    if (templates != null && templates.size() > 0) {
        Iterator<?> iterator = templates.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            Template template = new Template();

            List<Element> elems = element.elements();
            if (elems != null && !elems.isEmpty()) {
                Map<String, Object> rowMap = new java.util.HashMap<String, Object>();
                for (Element em : elems) {
                    rowMap.put(em.getName(), em.getStringValue());
                }//from w  w  w  . j  a v  a2 s .c  o  m
                Tools.populate(template, rowMap);
            }

            String text = element.elementText("text");
            String name = element.elementText("name");
            String title = element.elementText("title");
            String templateId = element.attributeValue("id");
            String dataFile = element.elementText("dataFile");
            String moduleId = element.elementText("moduleId");
            String moduleName = element.elementText("moduleName");
            String callbackUrl = element.elementText("callbackUrl");
            String description = element.elementText("description");
            String language = element.elementText("language");
            String objectId = element.elementText("objectId");
            String objectValue = element.elementText("objectValue");
            String _fileType = element.elementText("fileType");

            template.setLanguage(language);

            int fileType = 0;
            if (StringUtils.isNumeric(_fileType)) {
                fileType = Integer.parseInt(_fileType);
            }
            if (dataFile.endsWith(".java")) {
                fileType = 50;
            } else if (dataFile.endsWith(".jsp")) {
                fileType = 51;
            } else if (dataFile.endsWith(".ftl")) {
                fileType = 52;
                template.setLanguage("freemarker");
            } else if (dataFile.endsWith(".vm")) {
                fileType = 54;
                template.setLanguage("velocity");
            } else if (dataFile.endsWith(".xml")) {
                fileType = 60;
            } else if (dataFile.endsWith(".htm") || dataFile.endsWith(".html")) {
                fileType = 80;
            }

            template.setTemplateType(FileUtils.getFileExt(dataFile));

            if (StringUtils.isEmpty(text)) {
                String filename = SystemProperties.getConfigRootPath() + dataFile;
                File file = new File(filename);
                template.setLastModified(file.lastModified());
                template.setFileSize(file.length());
                byte[] data = FileUtils.getBytes(file);
                template.setData(data);
            }
            if (template.getData() == null || template.getFileSize() == 0) {
                throw new RuntimeException(" template content is null ");
            }

            template.setContent(text);
            template.setDataFile(dataFile);
            template.setTitle(title);
            template.setName(name);
            if (StringUtils.isNotEmpty(name)) {
                template.setName(name);
            } else {
                template.setName(title);
            }
            template.setFileType(fileType);
            template.setCallbackUrl(callbackUrl);
            template.setDescription(description);
            template.setTemplateId(templateId);

            template.setModuleId(moduleId);
            template.setModuleName(moduleName);
            template.setObjectId(objectId);
            template.setObjectValue(objectValue);

            dataMap.put(templateId, template);
        }
    }

    return dataMap;
}

From source file:com.bekwam.examples.javafx.oldscores.ScoresDialogController.java

@FXML
public void updateVerbalRecentered() {
    if (logger.isDebugEnabled()) {
        logger.debug("[UPD V RECENTERED]");
    }/*from   w w  w  .j  a  v  a 2s  .co m*/

    if (dao == null) {
        throw new IllegalArgumentException(
                "dao has not been set; call setRecenteredDAO() before calling this method");
    }

    String score1995_s = txtVerbalScore1995.getText();

    if (StringUtils.isNumeric(score1995_s)) {
        Integer score1995 = NumberUtils.toInt(score1995_s);

        if (withinRange(score1995)) {

            if (needsRound(score1995)) {
                score1995 = round(score1995);
                txtVerbalScore1995.setText(String.valueOf(score1995));
            }

            resetErrMsgs();
            Integer scoreRecentered = dao.lookupRecenteredVerbalScore(score1995);
            txtVerbalScoreRecentered.setText(String.valueOf(scoreRecentered));
        } else {
            errMsgVerbal1995.setVisible(true);
        }
    } else {
        errMsgVerbal1995.setVisible(true);
    }
}

From source file:com.ibm.appscan.bamboo.plugin.impl.SASTScanTaskConfigurator.java

private void validateNumber(ActionParametersMap params, ErrorCollection errorCollection, String field) {
    String value = params.getString(field);
    if (!("".equals(value) || StringUtils.isNumeric(value))) //$NON-NLS-1$
        errorCollection.addError(field, i18nBean.getText("err.nan")); //$NON-NLS-1$
}

From source file:com.funtl.framework.smoke.core.commons.persistence.Page.java

/**
 * /*from   w ww.  j a  va  2  s. c  om*/
 *
 * @param request          repage ????
 * @param response         Cookie??
 * @param defaultPageSize ? -1 ??
 */
public Page(HttpServletRequest request, HttpServletResponse response, int defaultPageSize) {
    this.request = request;

    // ??repage????
    String no = request.getParameter("pageNo");
    if (StringUtils.isNumeric(no)) {
        CookieUtils.setCookie(response, "pageNo", no);
        this.setPageNo(Integer.parseInt(no));
    } else if (request.getParameter("repage") != null) {
        no = CookieUtils.getCookie(request, "pageNo");
        if (StringUtils.isNumeric(no)) {
            this.setPageNo(Integer.parseInt(no));
        }
    }
    // ???repage?????
    String size = request.getParameter("pageSize");
    if (StringUtils.isNumeric(size)) {
        CookieUtils.setCookie(response, "pageSize", size);
        this.setPageSize(Integer.parseInt(size));
    }

    // else ifif?????? --2016-08-22
    if (request.getParameter("repage") != null) {
        size = CookieUtils.getCookie(request, "pageSize");
        if (StringUtils.isNumeric(size)) {
            this.setPageSize(Integer.parseInt(size));
        }
    }
    if (defaultPageSize != -2) {
        this.pageSize = defaultPageSize;
    }
    // else ifif?????? --2016-08-22

    // ?
    String funcName = request.getParameter("funcName");
    if (StringUtils.isNotBlank(funcName)) {
        CookieUtils.setCookie(response, "funcName", funcName);
        this.setFuncName(funcName);
    } else if (request.getParameter("repage") != null) {
        funcName = CookieUtils.getCookie(request, "funcName");
        if (StringUtils.isNotBlank(funcName)) {
            this.setFuncName(funcName);
        }
    }
    // ??
    String orderBy = request.getParameter("orderBy");
    if (StringUtils.isNotBlank(orderBy)) {
        this.setOrderBy(orderBy);
    }
}

From source file:com.xpn.xwiki.plugin.svg.SVGMacro.java

/**
 * Main macro execution method, replaces the macro instance with the generated output.
 * /*from ww w  .j a  va  2  s . c o m*/
 * @param writer the place where to write the output
 * @param params the parameters this macro is called with
 * @throws IllegalArgumentException if the mandatory argument ({@code text}) is missing
 * @throws IOException if the output cannot be written
 * @see org.radeox.macro.BaseMacro#execute(Writer, MacroParameter)
 */
@Override
public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException {
    RenderContext context = params.getContext();
    RenderEngine engine = context.getRenderEngine();

    XWikiContext xcontext = ((XWikiRadeoxRenderEngine) engine).getXWikiContext();
    XWiki xwiki = xcontext.getWiki();

    SVGPlugin plugin = (SVGPlugin) xwiki.getPlugin("svg", xcontext);
    // If the SVG plugin is not loaded, exit.
    if (plugin == null) {
        writer.write("Plugin not loaded");
        return;
    }
    // {svg:alternate text|height|width}
    StringBuffer str = new StringBuffer();
    String text = params.get("text", 0);
    String height = params.get("height", 1);
    if (StringUtils.isBlank(height) || "none".equals(height) || !StringUtils.isNumeric(height.trim())) {
        height = "400";
    }
    String width = params.get("width", 2);
    if (StringUtils.isBlank(width) || "none".equals(width) || !StringUtils.isNumeric(width.trim())) {
        width = "400";
    }
    try {
        int intHeight = Integer.parseInt(height.trim());
        int intWidth = Integer.parseInt(width.trim());
        String svgtext = StringUtils.trimToEmpty(params.getContent());
        str.append("<img src=\"");
        // The SVG plugin generates the image and returns an URL for accessing it.
        str.append(plugin.getSVGImageURL(svgtext, intHeight, intWidth, xcontext));
        str.append("\" ");
        str.append("height=\"" + height + "\" ");
        str.append("width=\"" + width + "\" ");
        str.append("alt=\"");
        str.append(text);
        str.append("\" />");
        writer.write(str.toString());
    } catch (Throwable t) {
        XWikiException e = new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS,
                XWikiException.ERROR_XWIKI_UNKNOWN, "SVG Issue", t);
        writer.write("Exception converting SVG: " + e.getFullMessage());
    }
}