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

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

Introduction

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

Prototype

public static boolean isNumeric(String str) 

Source Link

Document

Checks if the String contains only unicode digits.

Usage

From source file:fr.paris.lutece.portal.web.admin.AdminPagePortletJspBean.java

/**
 * Displays the confirm message for deleting the portlet
 *
 * @param request The http request//from   w w w  . j av  a 2s.com
 * @return The confirm page
 * @throws AccessDeniedException if the user is not authorized to manage the portlet
 */
public String getRemovePortlet(HttpServletRequest request) throws AccessDeniedException {
    String strPortletId = request.getParameter(Parameters.PORTLET_ID);
    if (!StringUtils.isNumeric(strPortletId)) {
        return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_ERROR);
    }
    int nPortletId = Integer.parseInt(strPortletId);
    Portlet portlet = null;
    try {
        portlet = PortletHome.findByPrimaryKey(nPortletId);
    } catch (NullPointerException e) {
        AppLogService.error("Error looking for portlet with id " + nPortletId, e);
    }
    if (portlet == null || portlet.getId() != nPortletId) {
        return AdminMessageService.getMessageUrl(request, Messages.MESSAGE_INVALID_ENTRY,
                new Object[] { nPortletId }, AdminMessage.TYPE_ERROR);
    }
    AdminUser user = AdminUserService.getAdminUser(request);
    if (!RBACService.isAuthorized(PortletType.RESOURCE_TYPE, portlet.getPortletTypeId(),
            PortletResourceIdService.PERMISSION_MANAGE, user)) {
        throw new AccessDeniedException("User " + user + " is not authorized to permission "
                + PortletResourceIdService.PERMISSION_MANAGE + " on portlet " + nPortletId);
    }
    String strUrl = JSP_REMOVE_PORTLET + "?portlet_id=" + strPortletId;
    String strTarget = "_top";
    if (PortletHome.hasAlias(nPortletId)) {
        return AdminMessageService.getMessageUrl(request, PROPERTY_MESSAGE_WARNING_PORTLET_ALIAS,
                new Object[] { portlet.getName() }, null, strUrl, strTarget, AdminMessage.TYPE_CONFIRMATION);
    }

    ArrayList<String> listErrors = new ArrayList<String>();
    Locale locale = AdminUserService.getLocale(request);
    if (!PortletRemovalListenerService.getService().checkForRemoval(strPortletId, listErrors, locale)) {
        String strCause = AdminMessageService.getFormattedList(listErrors, locale);
        Object[] args = { strCause, portlet.getName() };

        return AdminMessageService.getMessageUrl(request, MESSAGE_CANNOT_REMOVE_PORTLET, args,
                MESSAGE_CANNOT_REMOVE_PORTLET_TITLE, strUrl, strTarget, AdminMessage.TYPE_STOP);
    }

    return AdminMessageService.getMessageUrl(request, PROPERTY_MESSAGE_CONFIRM_REMOVE_PORTLET,
            new Object[] { portlet.getName() }, null, strUrl, strTarget, AdminMessage.TYPE_CONFIRMATION);
}

From source file:eu.artist.migration.mdt.umlprofilediscovery.codemodel2umlprofile.files.CodeModel2UMLProfilePostProcessor.java

private static void setDefaultValues() {
    for (EObject eObj : codeModel2ProfileModeltraceMap.keySet()) {
        if (eObj instanceof AnnotationTypeMemberDeclaration) {
            AnnotationTypeMemberDeclaration member = (AnnotationTypeMemberDeclaration) eObj;

            if (member.getDefault() != null) {
                Object value = getValueFromExpression(member.getDefault());

                if (value != null) {
                    EObject umlElement = codeModel2ProfileModeltraceMap.get(member);

                    if (umlElement != null) {
                        Property umlProperty = (Property) umlElement;

                        // TODO: We need to properly deal with "empty" values, e.g., {}
                        if (!(value.toString().equalsIgnoreCase("[]")
                                || value.toString().equalsIgnoreCase("\"\""))) {

                            if (!isNumericPrimitiveType(umlProperty.getType())
                                    || (isNumericPrimitiveType(umlProperty.getType())
                                            && StringUtils.isNumeric(value.toString()))) {

                                if (umlProperty.getType() instanceof Enumeration
                                        && umlProperty.isMultivalued()) {
                                    // remove brackets
                                    value = value.toString().substring(1, value.toString().length() - 1);
                                }//from ww w.j a v a2  s.c  o m
                                umlProperty.setDefault(value.toString());
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.bitium.confluence.config.ConfigureAction.java

@Override
public void validate() {
    if (StringUtils.isBlank(getLoginUrl())) {
        addActionError(getText("saml2Plugin.admin.loginUrlEmpty"));
    } else {//  w  ww  . ja v  a 2s.  c  o  m
        try {
            new URL(getLoginUrl());
        } catch (MalformedURLException e) {
            addActionError(getText("saml2Plugin.admin.loginUrlInvalid"));
        }
    }
    if (StringUtils.isBlank(getLogoutUrl())) {
        // addActionError(getText("saml2Plugin.admin.logoutUrlEmpty"));
    } else {
        try {
            new URL(getLogoutUrl());
        } catch (MalformedURLException e) {
            addActionError(getText("saml2Plugin.admin.logoutUrlInvalid"));
        }
    }
    if (StringUtils.isBlank(getEntityId())) {
        addActionError(getText("saml2Plugin.admin.entityIdEmpty"));
    }
    if (StringUtils.isBlank(getX509Certificate())) {
        addActionError(getText("saml2Plugin.admin.x509CertificateEmpty"));
    } else {
        try {
            X509Utils.generateX509Certificate(getX509Certificate());
        } catch (Exception e) {
            addActionError(getText("saml2Plugin.admin.x509CertificateInvalid"));
        }
    }
    if (StringUtils.isBlank(getIdpRequired())) {
        setIdpRequired("false");
    } else {
        setIdpRequired("true");
    }
    if (StringUtils.isBlank(getAutoCreateUser())) {
        setAutoCreateUser("false");
    } else {
        setAutoCreateUser("true");
    }

    if (StringUtils.isBlank(getMaxAuthenticationAge()) || (!StringUtils.isNumeric(getMaxAuthenticationAge()))) {
        addActionError(getText("saml2Plugin.admin.maxAuthenticationAgeInvalid"));
    }

    super.validate();
}

From source file:com.greenline.guahao.web.module.home.controllers.mobile.patient.MobilePatientController.java

/**
 * html5 ?/*www.ja v  a2s. co  m*/
 * 
 * @param model
 * @param patientId
 * @return String
 */
@MethodRemark(value = "remark=html?method=get")
@RequestMapping(value = MobileConstants.M_PAIENT_INFO_PATH, method = RequestMethod.GET)
public String patient(ModelMap model, @RequestParam("pid") String patientId) {
    // id
    String decodePatientId = DESUtil.DESDecode(patientId, EncodeKeyConstants.PATIENT_ENCODE_KEY);
    if (!StringUtils.isNumeric(decodePatientId)) {
        model.put("message", MobileMsgConstants.L_ERROR);
        return MobileConstants.M_ERROR;
    } else {
        PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(Long.parseLong(decodePatientId));
        if (null != patientInfoDO) {
            Long userId = UserCookieUtil.getUserId(request);
            if (!userId.toString().equals(String.valueOf(patientInfoDO.getUser_id()))) {
                // ??
                model.put("message", MobileMsgConstants.L_ERROR);
                return MobileConstants.M_ERROR;
            } else {
                PatientInfoDO patient = patientManager.getPatientByPatientId(Long.valueOf(decodePatientId));
                if (null == patient) {
                    model.put("message", MobileMsgConstants.L_ERROR);
                    return MobileConstants.M_ERROR;
                }
                patient.setEncodePatientId(patientId);
                patient.setEncodeUserId(DESUtil.DESEncode(String.valueOf(patient.getUser_id()),
                        EncodeKeyConstants.USER_ENCODE_KEY));
                model.put("patient", patient);
                model.put("redict", patientManager.getRelationDictDef());
            }
        }
    }
    return MobileConstants.M_PAIENT_INFO;
}

From source file:com.fiveamsolutions.nci.commons.web.struts2.converter.AbstractPersistentObjectTypeConverter.java

/**
 * {@inheritDoc}//from   ww w  . j  av a2 s.c o  m
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object convertFromString(Map context, String[] values, Class toClass) {
    XWorkBasicConverter converter = new XWorkBasicConverter();
    PersistentObject convertedObj = null;
    // the check for numeric is needed here to support checkboxes.
    if (StringUtils.isNotBlank(values[0]) && StringUtils.isNumeric(values[0])) {
        Long id = (Long) converter.convertValue(context, values[0], Long.class);
        convertedObj = getGenericDataService().getPersistentObject(toClass, id);
    }
    return convertedObj;
}

From source file:fr.paris.lutece.plugins.workflow.modules.appointment.web.UpdateAppointmentCancelActionTaskComponent.java

/**
 * {@inheritDoc}// w w  w  .j  av a  2s  . com
 */
@Override
public String doSaveConfig(HttpServletRequest request, Locale locale, ITask task) {
    TaskUpdateAppointmentCancelActionConfig config = _taskUpdateAppointmentCancelActionConfigService
            .findByPrimaryKey(task.getId());
    boolean bCreate = false;

    if (config == null) {
        bCreate = true;
        config = new TaskUpdateAppointmentCancelActionConfig();
        config.setIdTask(task.getId());
    }

    String strIdActionCancel = request.getParameter(PARAMETER_ID_ACTION_CANCEL);
    int nIdActionCancel = 0;

    if (StringUtils.isEmpty(strIdActionCancel) || !StringUtils.isNumeric(strIdActionCancel)) {
        Object[] tabRequiredFields = { I18nService.getLocalizedString(FIELD_CANCEL_ACTION, locale) };

        return AdminMessageService.getMessageUrl(request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
                AdminMessage.TYPE_STOP);
    }

    nIdActionCancel = Integer.parseInt(strIdActionCancel);
    config.setIdActionCancel(nIdActionCancel);

    if (bCreate) {
        _taskUpdateAppointmentCancelActionConfigService.create(config);
    } else {
        _taskUpdateAppointmentCancelActionConfigService.update(config);
    }

    return null;
}

From source file:com.ewcms.plugin.vote.manager.service.PersonService.java

@Override
public List<String> getRecordToHtml(Long questionnaireId, Long personId) {
    List<String> htmls = new ArrayList<String>();
    Questionnaire questionnaire = questionnaireDAO.get(questionnaireId);
    Assert.notNull(questionnaire);/*from w w w.  ja v a  2s. c  o 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.get(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:msi.gama.kernel.model.GamlModelSpecies.java

@Override
public IExperimentPlan getExperiment(final String s) {
    // First we try to get it using its "internal" name
    IExperimentPlan e = experiments.get(s);
    if (e == null) {
        // Otherwise with its title
        e = titledExperiments.get(s);/*w w w.j  a va 2  s. com*/
        if (e == null) {
            // Finally, if the string is an int, we try to get the n-th
            // experiment
            if (StringUtils.isNumeric(s)) {
                final int i = Integer.parseInt(s);
                final List<String> names = new ArrayList(experiments.keySet());
                if (names.size() > 0) {
                    e = getExperiment(names.get(i));
                }
            }
        }
    }
    return e;
}

From source file:morphy.user.Formula.java

private boolean cmp(Object o, String cmpoper, String value) {
    // String[] operators = { ">=","<=",">","<","!=","<>","=" };
    int intobj = 0;
    int intval = 0;
    if (o instanceof Integer)
        intobj = objToInt(o);/*  w  ww .  j  av a  2s. c  om*/
    if (o instanceof Boolean)
        intobj = objToBoolean(o) ? 1 : 0;
    if (StringUtils.isNumeric(value))
        intval = Integer.parseInt(value);

    if (cmpoper.equals(">="))
        return intobj >= intval;
    if (cmpoper.equals(">"))
        return intobj > intval;
    if (cmpoper.equals("<="))
        return intobj <= intval;
    if (cmpoper.equals("<"))
        return intobj < intval;
    if (cmpoper.equals("="))
        return intobj == intval;
    if (cmpoper.equals("!=") || cmpoper.equals("<>"))
        return intobj >= intval;
    return false;
}

From source file:com.micro.rent.common.comm.aio.AsyncClientHttpExchangeFutureCallback.java

public static String duration(String responseString) {
    String status = StringUtils.substringBetween(responseString, "<status>", "</status>");
    String duration = "1";
    if (!StringUtils.isNumeric(status)) {
        duration = "0";
    }//from  w  ww.  j a  v  a2 s.  c  om
    if (MSG_OK != Integer.valueOf(status).intValue()) {
        log.info("baidu map redirect error:"
                + StringUtils.substringBetween(responseString, "<message>", "</message>"));
    } else {
        duration = StringUtils.substringBetween(responseString, "<duration>", "</duration>");
        //         duration=StringUtil.secondToHm(Double.valueOf(duration)
        //               .intValue());
    }
    return duration;
}