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:com.egt.core.db.util.Exporter.java

static ExporterMessage export(String report, String number, String userid, String target, String format,
        String select, Object[] args, boolean logging) {
    Bitacora.trace(Exporter.class, "export", report, number, target, format);
    String informe = StringUtils.trimToEmpty(report);
    Long rastro = trimToNullNumber(number);
    Long usuario = StringUtils.isNotBlank(userid) && StringUtils.isNumeric(userid) ? Long.valueOf(userid)
            : null;/*from ww w  .  ja  va  2s.  c om*/
    String destino = trimToNullTarget(target);
    EnumFormatoArchivo tipo = getExportType(format);
    String decode = Utils.decodeSelect(trimToNullSelect(select));
    return export(informe, rastro, usuario, destino, tipo, decode, args, logging);
}

From source file:fr.paris.lutece.plugins.asynchronousupload.web.AsynchronousUploadApp.java

/**
 * Removes the uploaded fileItem.//w w w.  ja  v a  2 s  .  com
 * @param request the request
 * @return The JSON result
 */
public String doRemoveAsynchronousUploadedFile(HttpServletRequest request) {
    String strFieldName = request.getParameter(PARAMETER_FIELD_NAME);

    String strFieldIndex = request.getParameter(PARAMETER_FIELD_INDEX);

    List<Integer> listIndexesFilesToRemove = new ArrayList<Integer>();

    if (StringUtils.isNotEmpty(strFieldIndex)) {
        for (String strIndex : StringUtils.split(strFieldIndex, CONSTANT_COMA)) {
            if (StringUtils.isNotEmpty(strIndex) && StringUtils.isNumeric(strIndex)) {
                listIndexesFilesToRemove.add(Integer.parseInt(strIndex));
            }
        }
    }

    IAsyncUploadHandler handler = getHandler(request);

    return (handler == null) ? StringUtils.EMPTY
            : handler.doRemoveUploadedFile(request, strFieldName, listIndexesFilesToRemove);
}

From source file:fr.paris.lutece.plugins.crm.modules.mylutece.web.CRMMyluteceJspBean.java

/**
 * Do anonymize crm user.// w w w  .j  a  v a  2 s.c  om
 *
 * @param request the request
 * @return the string
 */
public String doAnonymizeCRMUser(HttpServletRequest request) {
    String strIdCRMUser = request.getParameter(PARAMETER_ID_CRM_USER);

    if (StringUtils.isBlank(strIdCRMUser) || !StringUtils.isNumeric(strIdCRMUser)) {
        return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
    }

    int nIdCRMUser = Integer.parseInt(strIdCRMUser);
    CRMUser user = _crmUserService.findByPrimaryKey(nIdCRMUser);

    if (user != null) {
        _anonymizationService.anonymizeUser(user.getIdCRMUser(), getLocale());
        MyLuteceUserManager.doAnonymizeMyLuteceUser(user.getUserGuid(), request, getLocale());
    }

    return getUrlManageUsers(request, true).getUrl();
}

From source file:fr.paris.lutece.plugins.contextinclude.web.ContextJspBean.java

/**
 * Get modify context/*from ww w .ja va 2 s .  c  om*/
 * @param request the HTTP request
 * @return the HTML code
 */
public String getModifyContext(HttpServletRequest request) {
    setPageTitleProperty(PROPERTY_MODIFY_CONTEXT_PAGE_TITLE);

    String strIdContext = request.getParameter(PARAMETER_ID_CONTEXT);

    if (StringUtils.isNotBlank(strIdContext) && StringUtils.isNumeric(strIdContext)) {
        int nIdContext = Integer.parseInt(strIdContext);
        Map<String, Object> model = new HashMap<String, Object>();
        model.put(MARK_CONTEXT, _contextService.findByPrimaryKey(nIdContext));
        model.put(MARK_WEBAPP_URL, AppPathService.getBaseUrl(request));
        model.put(MARK_LOCALE, this.getLocale());

        HtmlTemplate templateList = AppTemplateService.getTemplate(TEMPLATE_MODIFY_CONTEXT, getLocale(), model);

        return getAdminPage(templateList.getHtml());
    }

    return getErrorPage(I18nService.getLocalizedString(Messages.MANDATORY_FIELDS, this.getLocale()));
}

From source file:eu.europeana.uim.plugin.solr.service.SolrWorkflowPlugin.java

@Override
public boolean process(MetaDataRecord<I> mdr, ExecutionContext<MetaDataRecord<I>, I> context)
        throws IngestionPluginFailedException, CorruptedDatasetException {
    mdr.deleteValues(EuropeanaModelRegistry.EDMDEREFERENCEDRECORD);

    String overrideChecks = context.getProperties().getProperty(OVERRIDECHECKS);
    boolean check = false;
    if (StringUtils.isNotEmpty(overrideChecks)) {
        check = Boolean.parseBoolean(overrideChecks);
    }//from  www. j  a v a  2 s.c  om
    if (StringUtils.isNotEmpty(context.getProperties().getProperty(CLEARCACHE))) {
        if (Boolean.parseBoolean(context.getProperties().getProperty(CLEARCACHE))) {
            OsgiExtractor.clearCache();
            VocMemCache.clearCache(solrWorkflowService);
        }
    }
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);
    try {

        Date updateDate = sdf.parse((mdr.getValues(EuropeanaModelRegistry.UIMUPDATEDDATE).size() > 0)
                ? mdr.getValues(EuropeanaModelRegistry.UIMUPDATEDDATE).get(0)
                : new Date(0).toString());
        Date ingestionDate = new Date(context.getValue(date));

        if (updateDate.after(ingestionDate) || updateDate.toString().equals(ingestionDate.toString())
                || check) {
            if (mdr.getValues(EuropeanaModelRegistry.STATUS).size() == 0
                    || !mdr.getValues(EuropeanaModelRegistry.STATUS).get(0).equals(Status.DELETED)) {
                try {

                    String value = mdr.getValues(EuropeanaModelRegistry.EDMRECORD).get(0);
                    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
                    IMarshallingContext marshallingContext = bfact.createMarshallingContext();
                    marshallingContext.setIndent(2);
                    RDF rdf = (RDF) uctx.unmarshalDocument(new StringReader(value));
                    RDF rdfCopy = clone(rdf);
                    if (rdf.getAgentList() != null) {
                        for (AgentType agent : rdf.getAgentList()) {
                            dereferenceAgent(rdfCopy, agent);
                        }
                    }
                    if (rdf.getConceptList() != null) {
                        for (Concept concept : rdf.getConceptList()) {
                            dereferenceConcept(rdfCopy, concept);
                        }
                    }

                    if (rdf.getPlaceList() != null) {
                        for (PlaceType place : rdf.getPlaceList()) {
                            dereferencePlace(rdfCopy, place);
                        }
                    }

                    for (ProxyType proxy : rdf.getProxyList()) {
                        if (proxy.getEuropeanaProxy() == null
                                || !proxy.getEuropeanaProxy().isEuropeanaProxy()) {
                            if (StringUtils
                                    .isNotEmpty(context.getProperties().getProperty(LIBRARYOFCONGRESS))) {
                                if (Boolean
                                        .parseBoolean(context.getProperties().getProperty(LIBRARYOFCONGRESS))) {
                                    for (Choice choice : proxy.getChoiceList()) {
                                        if (choice.ifSubject()) {
                                            if (StringUtils.startsWith(choice.getSubject().getString(), "sh")
                                                    && StringUtils.isNumeric(StringUtils.substringAfter(
                                                            choice.getSubject().getString(), "sh"))) {
                                                Subject sbj = choice.getSubject();
                                                String subject = "http://data.europeana.eu/concept/loc/"
                                                        + sbj.getString();
                                                ResourceOrLiteralType.Resource rs = new ResourceOrLiteralType.Resource();
                                                rs.setResource(subject);
                                                Subject sbjNrm = new Subject();
                                                sbjNrm.setResource(rs);
                                                sbjNrm.setLang(new ResourceOrLiteralType.Lang());
                                                sbjNrm.setString("");
                                                choice.setSubject(sbjNrm);
                                            }
                                        }
                                    }
                                }
                            }
                            dereferenceProxy(rdfCopy, proxy);
                        }
                    }

                    if (rdf.getTimeSpanList() != null) {
                        for (TimeSpanType timespan : rdf.getTimeSpanList()) {
                            dereferenceTimespan(rdfCopy, timespan);
                        }
                    }
                    if (rdf.getWebResourceList() != null) {
                        for (WebResourceType webresource : rdf.getWebResourceList()) {
                            dereferenceWebResource(rdfCopy, webresource);
                        }
                    }

                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    RDF rdfFinal = cleanRDF(rdfCopy);

                    ProxyType europeanaProxy = new ProxyType();
                    EuropeanaProxy prx = new EuropeanaProxy();
                    prx.setEuropeanaProxy(true);
                    europeanaProxy.setEuropeanaProxy(prx);
                    List<String> years = new ArrayList<String>();
                    for (ProxyType proxy : rdfFinal.getProxyList()) {
                        years.addAll(new EuropeanaDateUtils().createEuropeanaYears(proxy));
                        europeanaProxy.setType(proxy.getType());
                    }
                    List<Year> yearList = new ArrayList<Year>();
                    for (String year : years) {
                        Year yearObj = new Year();
                        Lang lang = new Lang();
                        lang.setLang("def");
                        yearObj.setLang(lang);
                        yearObj.setString(year);
                        yearList.add(yearObj);
                    }
                    europeanaProxy.setYearList(yearList);
                    for (ProxyType proxy : rdfFinal.getProxyList()) {
                        if (proxy != null && proxy.getEuropeanaProxy() != null
                                && proxy.getEuropeanaProxy().isEuropeanaProxy()) {
                            rdfFinal.getProxyList().remove(proxy);
                        }
                    }
                    rdfFinal.getProxyList().add(europeanaProxy);

                    marshallingContext.marshalDocument(rdfFinal, "UTF-8", null, out);
                    String der = out.toString("UTF-8");

                    mdr.addValue(EuropeanaModelRegistry.EDMDEREFERENCEDRECORD, der);
                    return true;

                } catch (JiBXException e) {
                    e.printStackTrace();
                    context.getLoggingEngine().logFailed(Level.SEVERE, this, e,
                            "JiBX unmarshalling has failed with the following error: " + e.getMessage());

                } catch (MalformedURLException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (IOException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (SecurityException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());

                    e.printStackTrace();
                }

            }
        }
    } catch (Exception e) {
        if (logEngine != null) {
            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
        }
        e.printStackTrace();
    }
    return false;
}

From source file:com.clican.pluto.fsm.engine.state.DefaultStateImpl.java

/**
 * ???timeOutListenner??Job/*from  w  w  w . j a  v a2 s.  com*/
 * 
 * @param state
 * @param event
 * @param startTime
 *            ?job
 */
protected void prepareJobs(State state, Event event, Date startTime) {
    if (timeoutListeners != null && !timeoutListeners.isEmpty()) {
        for (String name : timeoutListeners.keySet()) {
            if (log.isDebugEnabled()) {
                log.debug("prepare timeout listener[" + name + "] of state[" + state.getName() + "].");
            }
            TimeOutListener listener = timeoutListeners.get(name);
            BusinessCalendar businessCalendar = listener.getBusinessCalendar() != null
                    ? listener.getBusinessCalendar()
                    : this.businessCalendar;
            Calendar temp = Calendar.getInstance();
            if (StringUtils.isNotEmpty(listener.getStartTime())) {
                Serializable startTimeSer = getVariableValueByEL(listener.getStartTime(), event, true);
                if (startTimeSer instanceof Date) {
                    temp.setTime((Date) startTimeSer);
                } else if (startTimeSer instanceof Calendar) {
                    temp.setTime(((Calendar) startTimeSer).getTime());
                } else {
                    if (StringUtils.isNumeric(startTimeSer.toString())) {
                        temp.setTimeInMillis(Long.parseLong(startTimeSer.toString()));
                    }
                }
            }
            Job job = new Job();
            job.setName(name);
            job.setBusinessCalendarName(listener.getBusinessCalendarName());
            Serializable dueTime = this.getVariableValueByEL(listener.getDueTime(), event, true);
            if (dueTime == null) {
                // Job, ?Job
                if (startTime == null) {
                    log.warn("Job: " + name + " have no dueTime, create fail!");
                    continue;
                } else {
                    job.setExecuteTime(startTime);
                }
            } else {
                if (dueTime instanceof Date) {
                    temp.setTimeInMillis(((Date) dueTime).getTime());
                } else if (dueTime instanceof Calendar) {
                    temp.setTimeInMillis(((Calendar) dueTime).getTimeInMillis());
                } else if (dueTime instanceof Long) {
                    temp.setTimeInMillis((Long) dueTime);
                } else if (dueTime instanceof String) {
                    temp.setTimeInMillis(businessCalendar.add(temp.getTime(), (String) dueTime).getTime());
                } else {
                    throw new RuntimeException("Unsupported DueTime format");
                }
                job.setExecuteTime(temp.getTime());
            }
            if (StringUtils.isNotEmpty(listener.getRepeatDuration())) {
                job.setRepeatDuration((String) getVariableValueByEL(listener.getRepeatDuration(), event, true));
            }
            if (StringUtils.isNotEmpty(listener.getRepeatTime())) {
                job.setRepeatTime(Integer
                        .valueOf(getVariableValueByEL(listener.getRepeatTime(), event, true).toString()));
            }
            job.setState(state);
            jobContext.addJob(job);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("there is no timeout listener in state[" + state.getName() + "].");
        }
    }
}

From source file:com.hmsinc.epicenter.webapp.remoting.AbstractRemoteService.java

/**
 * @param value//from  ww  w.  j a va  2  s  . co  m
 * @return
 */
protected static Collection<Long> splitStringToIdList(final String idList) {
    Set<Long> ret = null;
    try {

        final String value = StringUtils.trimToNull(codec.decode(idList));
        if (value != null) {
            ret = new HashSet<Long>();
            for (String v : value.split(",")) {
                if (StringUtils.isNumeric(v)) {
                    ret.add(Long.valueOf(v));
                }
            }
        }
    } catch (DecoderException e) {
        throw new IllegalArgumentException(e);
    }
    return ret;
}

From source file:com.microsoft.azure.util.AzureUtil.java

/**
 * Returns a template name that can be used for the base of a VM name
 * @return A shortened template name if required, the full name otherwise
 *//*from   www.j a  v  a 2s .c  o m*/
private static String getShortenedTemplateName(String templateName, String usageType, int dateDigits,
        int extraSuffixDigits) {
    // We'll be adding on 10 characters for the deployment ID (which is a formatted date)
    // Plus an index of the 
    // The template name should already be valid at least, so check that first
    if (!isValidTemplateName(templateName)) {
        throw new IllegalArgumentException("Template name is not valid");
    }
    // If the template name ends in a number, we add a dash
    // to split up the name

    int maxLength;
    if (usageType.equals(Constants.OS_TYPE_LINUX)) {
        // Linux, length <= 63 characters, 10 characters for the date
        maxLength = 63;
    } else if (usageType.equals(Constants.OS_TYPE_WINDOWS)) {
        // Windows, length is 15 characters.  10 characters for the date
        maxLength = 15;
    } else if (usageType.equals(Constants.USAGE_TYPE_DEPLOYMENT)) {
        // Maximum is 64 characters
        maxLength = 64;
    } else {
        throw new IllegalArgumentException("Unknown OS/Usage type");
    }

    // Chop of what we need for date digits
    maxLength -= dateDigits;
    // Chop off extra if needed for suffix digits
    maxLength -= extraSuffixDigits;

    // Shorten the name
    String shortenedName = templateName.substring(0, Math.min(templateName.length(), maxLength));

    // If the name ends in a digit, either append or replace the last char with a - so it's
    // not confusing
    if (StringUtils.isNumeric(shortenedName.substring(shortenedName.length() - 1))) {
        shortenedName = shortenedName.substring(0, Math.min(templateName.length(), maxLength - 1));
        shortenedName += '-';
    }

    return shortenedName;
}

From source file:net.sourceforge.fenixedu.domain.organizationalStructure.UnitName.java

private static boolean existsTheSameCode(UnitName unitName,
        UnitNameLimitedOrderedSet unitNameLimitedOrderedSet) {
    for (UnitName unitNameTemp : unitNameLimitedOrderedSet) {
        if (StringUtils.isEmpty(unitName.getUnit().getCode())
                || !StringUtils.isNumeric(unitName.getUnit().getCode())) {
            return false;
        }//from  w  w  w . jav a  2s .  c om
        if (unitName.getUnit().getCode().equals(unitNameTemp.getUnit().getCode())) {
            return true;
        }
    }
    return false;
}

From source file:biblivre3.cataloging.holding.HoldingBO.java

public boolean createAutomaticHolding(final Record record, final Database base, final int recordSerial,
        final Availability availability, String[] ex_auto) {
    try {//from   w ww  . j av  a  2  s  .  c  om
        int holdingCount = StringUtils.isNumeric(ex_auto[0]) && StringUtils.isNotBlank(ex_auto[0])
                ? Integer.parseInt(ex_auto[0])
                : 1;
        int volumeNumber = StringUtils.isNumeric(ex_auto[1]) && StringUtils.isNotBlank(ex_auto[1])
                ? Integer.parseInt(ex_auto[1])
                : 0;
        int volumeCount = StringUtils.isNumeric(ex_auto[2]) && StringUtils.isNotBlank(ex_auto[2])
                ? Integer.parseInt(ex_auto[2])
                : 1;

        String deposit = ex_auto[3];
        String acquisitionType = ex_auto[4];
        String dt_tomb = ex_auto[5];

        String[] notes = new String[3];
        notes[0] = 'a' + deposit;
        notes[1] = 'c' + acquisitionType;
        notes[2] = 'd' + dt_tomb;

        boolean success = true;

        String[] location = Indexer.listLocation(record);

        for (int j = 0; j < volumeCount; j++) {
            for (int i = 0; i < holdingCount; i++) {
                String[] vetHolding = new String[4];

                vetHolding[0] = "a" + location[0];
                vetHolding[1] = "b" + location[1];
                vetHolding[2] = "c";

                if (StringUtils.isNotBlank(location[2])) {
                    vetHolding[2] += location[2];
                } else {
                    if (volumeNumber != 0) {
                        vetHolding[2] += "v." + volumeNumber;
                    } else if (volumeCount > 1) {
                        vetHolding[2] += "v." + (j + 1);
                    }
                }

                vetHolding[3] = 'd' + "ex." + (i + 1);

                Record holding = this.getRecordHolding(vetHolding, notes);
                MarcUtils.setAssetHolding(holding, this.getNextAvailableAsset());

                success &= this.insert(holding, recordSerial, base, availability);
            }
        }

        return success;
    } catch (RuntimeException rex) {
        throw rex;
    }
}