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.jbpm.web.springmvc.MxJbpmDefinitionController.java

@RequestMapping("/task")
public ModelAndView task(
        @RequestParam(value = "processDefinitionId", required = false) String processDefinitionId,
        @RequestParam(value = "processName", required = false) String processName, ModelMap modelMap) {
    List<Task> rows = new java.util.ArrayList<Task>();
    ProcessDefinition processDefinition = null;
    GraphSession graphSession = null;//from w w w .j a v a  2s. co m
    JbpmContext jbpmContext = null;
    try {
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();
        graphSession = jbpmContext.getGraphSession();
        if (StringUtils.isNumeric(processDefinitionId)) {
            processDefinition = graphSession.getProcessDefinition(Long.valueOf(processDefinitionId));
        } else if (StringUtils.isNotEmpty(processName)) {
            processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(processName);
        }

        if (processDefinition != null) {
            modelMap.put("processDefinition", processDefinition);
            Map<String, Task> taskMap = processDefinition.getTaskMgmtDefinition().getTasks();
            if (taskMap != null && taskMap.size() > 0) {
                Set<Entry<String, Task>> entrySet = taskMap.entrySet();
                for (Entry<String, Task> entry : entrySet) {
                    String name = entry.getKey();
                    Task task = entry.getValue();
                    if (name != null && task != null) {
                        rows.add(task);
                    }
                }
                modelMap.put("tasks", rows);
            }
        }

    } catch (Exception ex) {
        logger.debug(ex);
    } finally {
        Context.close(jbpmContext);
    }

    String x_view = ViewProperties.getString("jbpm_definition.task");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/jbpm/definition/task", modelMap);
}

From source file:com.xpn.xwiki.plugin.image.ImagePlugin.java

/**
 * Tries to initializes the image cache. If the initialization fails the image cache remains {@code null}.
 * /*from w w w .  j  a  va2s. c o m*/
 * @param context the XWiki context
 */
private void initCache(XWikiContext context) {
    CacheConfiguration configuration = new CacheConfiguration();

    configuration.setConfigurationId("xwiki.plugin.image");

    // Set folder to store cache.
    File tempDir = context.getWiki().getTempDirectory(context);
    File imgTempDir = new File(tempDir, configuration.getConfigurationId());
    try {
        imgTempDir.mkdirs();
    } catch (Exception ex) {
        LOG.warn("Cannot create temporary files.", ex);
    }
    configuration.put("cache.path", imgTempDir.getAbsolutePath());
    // Set cache constraints.
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);

    String capacityParam = context.getWiki().Param("xwiki.plugin.image.cache.capacity");
    if (!StringUtils.isBlank(capacityParam) && StringUtils.isNumeric(capacityParam.trim())) {
        try {
            this.capacity = Integer.parseInt(capacityParam.trim());
        } catch (NumberFormatException e) {
            LOG.warn(String.format("Failed to parse xwiki.plugin.image.cache.capacity configuration parameter. "
                    + "Using %s as the cache capacity.", this.capacity), e);
        }
    }
    lru.setMaxEntries(this.capacity);

    try {
        this.imageCache = context.getWiki().getLocalCacheFactory().newCache(configuration);
    } catch (CacheException e) {
        LOG.error("Error initializing the image cache.", e);
    }
}

From source file:com.glaf.activiti.extension.model.ExtensionEntity.java

public int getIntFieldValue(String name) {
    if (fields != null) {
        ExtensionFieldEntity extensionField = fields.get(name);
        if (extensionField != null && extensionField.getValue() != null) {
            String value = extensionField.getValue();
            if (StringUtils.isNumeric(value)) {
                return Integer.parseInt(value);
            }//from w w  w.  java  2 s .  c om
        }
    }
    return 0;
}

From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogResource.java

@GET
@Path("/roles/{roleNameOrId}/users")
@Timed/*from ww  w . j a  v  a2  s.c  o m*/
public Response getRoleUsers(@PathParam("roleNameOrId") String roleNameOrId,
        @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
    Long roleId = StringUtils.isNumeric(roleNameOrId) ? Long.parseLong(roleNameOrId)
            : getIdFromRoleName(roleNameOrId);
    return getRoleUsers(roleId);
}

From source file:de.undercouch.citeproc.bibtex.DateParser.java

/**
 * Parses the given year and month to a {@link CSLDate} object. Does not
 * handle ranges./*from  w  ww  .  j  av  a  2 s.  c  o m*/
 * @param year the year to parse. Should be a four-digit number or a String
 * whose last four characters are digits.
 * @param month the month to parse. May be a number (<code>1-12</code>),
 * a short month name (<code>Jan</code> to <code>Dec</code>), or a
 * long month name (<code>January</code> to </code>December</code>). This
 * method is also able to recognize month names in several locales.
 * @return the {@link CSLDate} object or null if both, the year and the
 * month, could not be parsed
 */
public static CSLDate toDateSingle(String year, String month) {
    int m = toMonth(month);

    //parse year
    int y = -1;
    Boolean circa = null;
    if (year != null && year.length() >= 4) {
        if (StringUtils.isNumeric(year)) {
            y = Integer.parseInt(year);
        } else {
            String fourDigit = year.substring(year.length() - 4);
            if (StringUtils.isNumeric(fourDigit)) {
                y = Integer.parseInt(fourDigit);
                if (year.length() > 4) {
                    circa = Boolean.TRUE;
                }
            }
        }
    }

    //create result
    CSLDateBuilder builder = new CSLDateBuilder();
    if (y < 0) {
        return null;
    }
    if (m < 0) {
        return builder.dateParts(y).circa(circa).build();
    }
    return builder.dateParts(y, m).circa(circa).build();
}

From source file:form.house.NewHouseForm.java

public void pushBuildInfo(House house) {
    house.setHouseType(this.houseType);
    house.setOwner(this.owner);
    house.setOwnerType(this.ownerType);
    house.setPropertyRightType(propertyRightType);
    house.setFloor(this.floor);
    house.setAreas(StringUtils.isNumeric(areas) ? Long.valueOf(this.areas) : 0l);
    house.setBuildAreas(StringUtils.isNumeric(buildAreas) ? Long.valueOf(this.buildAreas) : 0l);
    house.setUseAreas(StringUtils.isNumeric(useAreas) ? Long.valueOf(this.useAreas) : 0l);
    house.setShowLength(this.showLength);
    house.setHeight(StringUtils.isNumeric(this.height) ? Long.valueOf(this.height) : 0l);
    house.setShade(StringUtils.isNumeric(this.shade) ? Long.valueOf(this.shade) : 0l);
    house.setDecoration(this.decoration);
}

From source file:com.ewcms.content.vote.service.PersonService.java

public List<String> getRecordToHtml(Long questionnaireId, Long personId) {
    List<String> htmls = new ArrayList<String>();
    Questionnaire questionnaire = questionnaireDao.findOne(questionnaireId);
    Assert.notNull(questionnaire);//from  w w w. j a  v a  2  s. co  m
    List<Subject> subjects = questionnaire.getSubjects();
    Assert.notNull(subjects);
    if (!subjects.isEmpty()) {
        Long number = 1L;
        for (Subject subject : subjects) {
            StringBuffer html = new StringBuffer();
            html.append(number + "." + subject.getTitle() + " : ");

            String subjectName = "Subject_" + subject.getId();

            List<Record> records = personDao.findRecordBySubjectTitle(personId, subjectName);
            if (records == null || records.isEmpty())
                continue;
            if (subject.getStatus() != Subject.Status.INPUT) {
                for (Record record : records) {
                    String name = record.getSubjectName();
                    String[] names = name.split("_");
                    if (names.length == 2) {
                        if (!record.getSubjectValue().equals("")
                                && StringUtils.isNumeric(record.getSubjectValue())) {
                            SubjectItem subjectItem = subjectItemDao
                                    .findOne(new Long(record.getSubjectValue()));
                            if (subjectItem == null)
                                continue;
                            html.append("?" + subjectItem.getTitle() + " ");
                            String subjectItemName = subjectName + "_Item_" + subjectItem.getId();
                            Record recordItem = personDao.findRecordBySubjectItemTitle(personId,
                                    subjectItemName);
                            if (recordItem == null)
                                continue;
                            html.append(recordItem.getSubjectValue() + " ");
                        } else {
                            html.append(record.getSubjectValue() + " ");
                        }
                    } else if (names.length == 4) {
                        html.append(record.getSubjectValue() + " ");
                    }
                }
            } else {
                Record record = records.get(0);
                html.append(record.getSubjectValue());
            }
            htmls.add(html.toString());
            number++;
        }
    }
    return htmls;
}

From source file:com.moviejukebox.plugin.MovieMeterPlugin.java

/**
 * Get the ID for the movie/*from w w w .  j  a v  a  2 s . c  o  m*/
 *
 * @param movie Movie to get the ID for
 * @return The ID, or empty if no idea found
 */
public String getMovieId(Movie movie) {
    // Try to get the MovieMeter ID from the movie
    String id = movie.getId(MOVIEMETER_PLUGIN_ID);
    if (isValidString(id) && StringUtils.isNumeric(id)) {
        return id;
    }

    // Try to get the MovieMeter ID using the IMDB ID
    id = movie.getId(IMDB_PLUGIN_ID);
    if (isValidString(id)) {
        try {
            // Get the Movie Meter ID using IMDB ID
            FilmInfo mm = api.getFilm(id);
            id = Integer.toString(mm.getId());
            movie.setId(MOVIEMETER_PLUGIN_ID, mm.getId());
            return id;
        } catch (MovieMeterException ex) {
            LOG.warn("Failed to get MovieMeter ID for {}: {}", movie.getBaseName(), ex.getMessage(), ex);
        }
    }

    // Try to get the MovieMeter ID using the title/year
    if (isNotValidString(id)) {
        id = getMovieId(movie.getTitle(), movie.getYear());

        // Try the original title next
        if (isNotValidString(id)) {
            id = getMovieId(movie.getOriginalTitle(), movie.getYear());
        }
    }

    return id;
}

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

@RequestMapping("/chooseUser")
public ModelAndView chooseUser(ModelMap modelMap, HttpServletRequest request) {
    String processInstanceId = request.getParameter("processInstanceId");
    String taskName = request.getParameter("taskName");
    StringBuffer taskNameBuffer = new StringBuffer();
    StringBuffer userBuffer = new StringBuffer();
    StringBuffer taskUserBuffer = new StringBuffer();
    Set<String> actorIds = new HashSet<String>();
    JbpmContext jbpmContext = null;/*from  w  ww. j a  v  a2s . c om*/
    try {
        Map<String, User> userMap = ProcessContainer.getContainer().getUserMap();
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();
        if (StringUtils.isNotEmpty(processInstanceId) && StringUtils.isNumeric(processInstanceId)) {
            ProcessInstance processInstance = jbpmContext.getProcessInstance(Long.parseLong(processInstanceId));
            if (processInstance != null) {
                TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
                Collection<TaskInstance> taskInstances = tmi.getUnfinishedTasks(processInstance.getRootToken());
                if (taskInstances != null && taskInstances.size() > 0) {
                    Iterator<TaskInstance> iter = taskInstances.iterator();
                    while (iter.hasNext()) {
                        TaskInstance taskInstance = iter.next();
                        if (StringUtils.equals(taskName, taskInstance.getName())) {
                            taskNameBuffer.append("<option value=\"").append(taskInstance.getName())
                                    .append("\" selected>").append(taskInstance.getName()).append('[')
                                    .append(taskInstance.getDescription()).append("]</option>");
                            if (StringUtils.isNotEmpty(taskInstance.getActorId())) {
                                actorIds.add(taskInstance.getActorId());
                            } else {
                                Set<PooledActor> pooledActors = taskInstance.getPooledActors();
                                if (pooledActors != null && pooledActors.size() > 0) {
                                    Iterator<PooledActor> iter2 = pooledActors.iterator();
                                    while (iter2.hasNext()) {
                                        PooledActor actor = iter2.next();
                                        String pooledActorId = actor.getActorId();
                                        actorIds.add(pooledActorId);
                                    }
                                }
                            }
                        } else {
                            taskNameBuffer.append("<option value=\"").append(taskInstance.getName())
                                    .append("\">").append(taskInstance.getName()).append('[')
                                    .append(taskInstance.getDescription()).append("]</option>");
                        }
                    }

                    if (userMap != null && userMap.size() > 0) {
                        Set<Entry<String, User>> entrySet = userMap.entrySet();
                        for (Entry<String, User> entry : entrySet) {
                            String name = entry.getKey();
                            User user = entry.getValue();
                            if (name != null && user != null) {
                                if (actorIds.contains(user.getActorId())) {
                                    taskUserBuffer.append("<option value=\"").append(user.getActorId())
                                            .append("\">").append(user.getActorId()).append('[')
                                            .append(user.getName()).append("]</option>");
                                } else {
                                    userBuffer.append("<option value=\"").append(user.getActorId())
                                            .append("\">").append(user.getActorId()).append('[')
                                            .append(user.getName()).append("]</option>");
                                }
                            }
                        }
                    }
                }
            }

            modelMap.put("selectedScript", taskUserBuffer.toString());
            modelMap.put("noselectedScript", userBuffer.toString());
            modelMap.put("taskNameScript", taskNameBuffer.toString());
        }
    } catch (Exception ex) {
        if (LogUtils.isDebug()) {
            logger.debug(ex);
            ex.printStackTrace();
        }
    } finally {
        Context.close(jbpmContext);
    }

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

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

    String x_view = ViewProperties.getString("jbpm_task.chooseUser");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/jbpm/task/chooseUser", modelMap);
}

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

@FXML
public void updateMathRecentered() {
    if (logger.isDebugEnabled()) {
        logger.debug("[UPD M RECENTERED]");
    }/*w w w.ja v  a 2s.c  o m*/

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

    String score1995_s = txtMathScore1995.getText();

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

        if (withinRange(score1995)) {

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

            resetErrMsgs();
            Integer scoreRecentered = dao.lookupRecenteredMathScore(score1995);
            txtMathScoreRecentered.setText(String.valueOf(scoreRecentered));
        } else {
            errMsgMath1995.setVisible(true);
        }
    } else {
        errMsgMath1995.setVisible(true);
    }
}