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.plugins.workflow.modules.ticketing.web.EditTicketXPage.java

/**
 * {@inheritDoc}//from w  ww.j a v a 2  s . c o  m
 */
@Override
public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin)
        throws UserNotSignedException, SiteMessageException {
    XPage page = null;

    String strUrlReturn = AppPropertiesService.getProperty(PROPERTY_URL_RETURN);

    if (isRequestAuthenticated(request)) {
        String strIdHistory = request.getParameter(TaskEditTicketConstants.PARAMETER_ID_HISTORY);
        String strIdTask = request.getParameter(TaskEditTicketConstants.PARAMETER_ID_TASK);
        String strIdAction = request.getParameter(TaskEditTicketConstants.PARAMETER_ID_ACTION);

        if (StringUtils.isNotBlank(strIdHistory) && StringUtils.isNumeric(strIdHistory)
                && StringUtils.isNotBlank(strIdTask) && StringUtils.isNumeric(strIdTask)
                && StringUtils.isNotBlank(strIdAction) && StringUtils.isNumeric(strIdAction)) {
            int nIdHistory = Integer.parseInt(strIdHistory);
            int nIdTask = Integer.parseInt(strIdTask);
            int nIdAction = Integer.parseInt(strIdAction);

            page = getPage(request, nIdHistory, nIdTask, nIdAction, strUrlReturn);
        } else {
            setSiteMessage(request, Messages.MANDATORY_FIELDS, SiteMessage.TYPE_STOP, strUrlReturn);
        }
    } else {
        setSiteMessage(request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP, strUrlReturn);
    }

    return page;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.FinalDegreeWorkProposalsDispatchAction.java

private void filterBranchList(ActionForm form, HttpServletRequest request) {
    DynaActionForm finalWorkForm = (DynaActionForm) form;
    String branchOID = (String) finalWorkForm.get("branchOID");

    if (branchOID != null && !branchOID.equals("") && StringUtils.isNumeric(branchOID)) {
        Collection headers = (Collection) request.getAttribute("publishedFinalDegreeWorkProposalHeaders");
        CollectionUtils.filter(headers, new FILTER_INFOPROSAL_HEADERS_BY_BRANCH_PREDICATE(branchOID));
    }/*  ww  w. ja  v a2  s . c o  m*/
}

From source file:net.mindengine.oculus.frontend.service.project.build.JdbcBuildDAO.java

public SqlSearchCondition createSearchCondition(BuildSearchFilter filter) {
    SqlSearchCondition condition = new SqlSearchCondition();
    // Name//from ww  w  .j  ava  2  s .c  om
    {
        String name = filter.getName();
        if (name != null && !name.isEmpty()) {
            if (name.contains(",")) {
                condition.append(condition.createArrayCondition(name, "b.name"));
            } else {
                condition.append(condition.createSimpleCondition(name, true, "b.name"));
            }
        }
    }
    // Project
    {
        String project = filter.getProject();
        if (project != null && !project.isEmpty()) {
            // checking whether it is an id of project or just a name
            if (StringUtils.isNumeric(project)) {
                // The id of a project was provided
                condition.append(condition.createSimpleCondition(false, "p.id", project));
            } else {
                if (project.contains(",")) {
                    condition.append(condition.createArrayCondition(project, "p.name"));
                } else {
                    condition.append(condition.createSimpleCondition(project, true, "p.name"));
                }
            }
        }
    }
    return condition;
}

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

/**
 * Gets the confirm remove crm user./* w ww. j a  v a  2 s .  c  o m*/
 *
 * @param request the request
 * @return the confirm remove crm user
 */
public String getConfirmRemoveCRMUser(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);
    }

    UrlItem url = new UrlItem(JSP_URL_REMOVE_CRM_USER);
    url.addParameter(PARAMETER_ID_CRM_USER, strIdCRMUser);

    return AdminMessageService.getMessageUrl(request, MESSAGE_CONFIRM_REMOVE_CRM_USER, url.getUrl(),
            AdminMessage.TYPE_CONFIRMATION);
}

From source file:com.yahoo.semsearch.fastlinking.io.Datapack.java

private void merge(String anchorMapPath, String dfMapPath, String multiple_out, String out, String ngram)
        throws IOException {

    JobConf conf = new JobConf(getConf(), Datapack.class);
    FileSystem fs = FileSystem.get(conf);

    BufferedWriter anchorsDataOut;
    BufferedWriter anchorsTSVOut;

    Boolean multiple_output = (multiple_out != null && multiple_out.equalsIgnoreCase("true"));
    Boolean ngram_output = (ngram != null && ngram.equalsIgnoreCase("true"));

    if (!multiple_output) {
        anchorsDataOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), outputEncoding));
        anchorsTSVOut = null;/*from  w  w w.j a  va 2 s. com*/
    } else {
        anchorsDataOut = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(out + ".dat"), outputEncoding));
        anchorsTSVOut = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(out + ".tsv"), outputEncoding));
    }

    // Loop over anchors
    MapFile.Reader anchorMapReader = new MapFile.Reader(new Path(anchorMapPath + "/part-00000"), conf);
    MapFile.Reader dfMapReader = new MapFile.Reader(new Path(dfMapPath + "/part-00000"), conf);

    /*FileStatus[] status = fs.listStatus( new Path( dfMapPath ) );  // you need to pass in your hdfs path
    for( FileStatus fileStatus : status ) {
    if( !fileStatus.getPath().toString().contains( "part-" )) continue;
    MapFile.Reader dfMapReader = new MapFile.Reader( fileStatus.getPath(), conf );
    */
    Text akey = new Text();
    Text dkey = new Text();
    IntWritable df = new IntWritable();
    HMapSIW map = new HMapSIW();

    while (anchorMapReader.next(akey, map)) {

        // since they are both sorted we can just iterate over both
        // TODO if need be, artificially add a 0 count to unseen anchors
        dfMapReader.next(dkey, df);
        while (!akey.toString().equalsIgnoreCase(dkey.toString())) {
            //System.err.println("Mismatch: '" + akey + "' and '" + dkey + "'");
            anchorMapReader.next(akey, map);
        }
        String l = akey.toString();

        //            while( dfMapReader.next( dkey, df ) ) {

        //              String l = dkey.toString();
        if (l.trim().length() < 2)
            continue;

        StringBuilder targets = new StringBuilder();
        int total = 0;
        for (String target : map.keySet()) {

            int count = map.get(target);
            total += count;

            String entity = URLEncoder.encode(target.replaceAll(" ", "_"), "UTF-8");

            targets.append(entity);
            targets.append(SEPARATOR);
            targets.append(Integer.toString(count));
            targets.append("\t");

        }

        if (StringUtils.isNumeric(l) && total < 2)
            continue;

        //System.err.println("targets " + targets);
        if (targets.length() < 2)
            continue;
        if (!ngram_output) {
            anchorsDataOut.write(l);
            anchorsDataOut.write(SEPARATOR);
            anchorsDataOut.write(Integer.toString(df.get()));
            anchorsDataOut.write(SEPARATOR);
            anchorsDataOut.write(Integer.toString(total));
            anchorsDataOut.write("\t");
            anchorsDataOut.write(targets.substring(0, targets.length() - 1));
            anchorsDataOut.write("\n");
            anchorsDataOut.flush();

            if (multiple_output) {
                for (String target : map.keySet()) {
                    int count = map.get(target);
                    String entity = URLEncoder.encode(target.replaceAll(" ", "_"), "UTF-8");
                    anchorsTSVOut.write(l);
                    anchorsTSVOut.write("\t");
                    anchorsTSVOut.write(Integer.toString(df.get()));
                    anchorsTSVOut.write("\t");
                    anchorsTSVOut.write(Integer.toString(total));
                    anchorsTSVOut.write("\t");
                    anchorsTSVOut.write(entity);
                    anchorsTSVOut.write("\t");
                    anchorsTSVOut.write(Integer.toString(count));
                    anchorsTSVOut.write("\n");
                    anchorsTSVOut.flush();
                }
            }
        } else {
            String parts[] = l.split("\\s+");
            for (int i = 0; i < parts.length; i++) {
                StringBuilder sb = new StringBuilder();
                for (int j = i; j < parts.length; j++) {
                    sb.append(parts[j]);
                    String ss = sb.toString();
                    anchorsDataOut.write(ss);
                    anchorsDataOut.write(SEPARATOR);
                    anchorsDataOut.write(Integer.toString(df.get()));
                    anchorsDataOut.write(SEPARATOR);
                    anchorsDataOut.write(Integer.toString(total));
                    anchorsDataOut.write("\t");
                    anchorsDataOut.write(targets.substring(0, targets.length() - 1));
                    anchorsDataOut.write("\n");
                    anchorsDataOut.flush();
                    if (multiple_output) {
                        for (String target : map.keySet()) {
                            int count = map.get(target);
                            String entity = URLEncoder.encode(target.replaceAll(" ", "_"), "UTF-8");
                            anchorsTSVOut.write(ss);
                            anchorsTSVOut.write("\t");
                            anchorsTSVOut.write(Integer.toString(df.get()));
                            anchorsTSVOut.write("\t");
                            anchorsTSVOut.write(Integer.toString(total));
                            anchorsTSVOut.write("\t");
                            anchorsTSVOut.write(entity);
                            anchorsTSVOut.write("\t");
                            anchorsTSVOut.write(Integer.toString(count));
                            anchorsTSVOut.write("\n");
                            anchorsTSVOut.flush();
                        }
                        sb.append(" ");
                    }
                }
            }
        }
    }
    dfMapReader.close();
    //}

    anchorsDataOut.close();

    if (multiple_output) {
        anchorsTSVOut.close();
    }

    //anchorMapReader.close();

    fs.close();

}

From source file:hydrograph.ui.engine.converter.Converter.java

/**
 * Converts the String to {@link BigInteger} for port
 * //ww  w. j  a  v a 2s  . c  om
 * @param propertyName
 * @return {@link BigInteger}
 */
protected BigInteger getPortValue(String propertyName) {
    logger.debug("Getting boolean Value for {}={}",
            new Object[] { propertyName, properties.get(propertyName) });
    BigInteger bigInteger = null;
    String propertyValue = (String) properties.get(propertyName);
    if (StringUtils.isNotBlank(propertyValue) && StringUtils.isNumeric(propertyValue)) {
        bigInteger = new BigInteger(String.valueOf(propertyValue));
    } else if (ParameterUtil.isParameter(propertyValue)) {
        ComponentXpath.INSTANCE.getXpathMap()
                .put((ComponentXpathConstants.COMPONENT_XPATH_BOOLEAN.value().replace(ID, componentId))
                        .replace(Constants.PARAM_PROPERTY_NAME, propertyName),
                        new ComponentsAttributeAndValue(null, properties.get(propertyName).toString()));
        return null;
    }
    return bigInteger;

}

From source file:com.jwmsolutions.timeCheck.gui.TodoForm.java

private boolean isValidHours() {
    String hours = jtfHours.getText().trim();
    if (StringUtils.isNotBlank(hours) && StringUtils.isNumeric(hours)) {
        double h = Double.valueOf(hours);
        return h > 0;
    }/*from ww  w.jav  a  2 s  . co  m*/
    return false;
}

From source file:net.erdfelt.android.sdkfido.local.LocalAndroidPlatforms.java

public AndroidPlatform getPlatform(String id) throws AndroidPlatformNotFoundException {
    String platformId = id;/*from  w ww  . j  a v  a 2 s . c  o m*/
    if (StringUtils.isNumeric(id)) {
        platformId = "android-" + id;
    }
    AndroidPlatform platform = platforms.get(platformId);
    if (platform == null) {
        throw new AndroidPlatformNotFoundException(platformId);
    }
    return platform;
}

From source file:jp.sf.fess.solr.plugin.suggest.util.SolrConfigUtil.java

public static SuggestUpdateConfig getUpdateHandlerConfig(final SolrConfig config) {
    final SuggestUpdateConfig suggestUpdateConfig = new SuggestUpdateConfig();

    final Node solrServerNode = config.getNode("updateHandler/suggest/solrServer", false);
    if (solrServerNode != null) {
        try {// w  w  w  .j  a v a 2 s .  c  o m
            final Node classNode = solrServerNode.getAttributes().getNamedItem("class");
            String className;
            if (classNode != null) {
                className = classNode.getTextContent();
            } else {
                className = "org.codelibs.solr.lib.server.SolrLibHttpSolrServer";
            }
            @SuppressWarnings("unchecked")
            final Class<? extends SolrServer> clazz = (Class<? extends SolrServer>) Class.forName(className);
            final String arg = config.getVal("updateHandler/suggest/solrServer/arg", false);
            SolrServer solrServer;
            if (StringUtils.isNotBlank(arg)) {
                final Constructor<? extends SolrServer> constructor = clazz.getConstructor(String.class);
                solrServer = constructor.newInstance(arg);
            } else {
                solrServer = clazz.newInstance();
            }

            final String username = config.getVal("updateHandler/suggest/solrServer/credentials/username",
                    false);
            final String password = config.getVal("updateHandler/suggest/solrServer/credentials/password",
                    false);
            if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)
                    && solrServer instanceof SolrLibHttpSolrServer) {
                final SolrLibHttpSolrServer solrLibHttpSolrServer = (SolrLibHttpSolrServer) solrServer;
                final URL u = new URL(arg);
                final AuthScope authScope = new AuthScope(u.getHost(), u.getPort());
                final Credentials credentials = new UsernamePasswordCredentials(username, password);
                solrLibHttpSolrServer.setCredentials(authScope, credentials);
                solrLibHttpSolrServer.addRequestInterceptor(new PreemptiveAuthInterceptor());
            }

            final NodeList childNodes = solrServerNode.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                final Node node = childNodes.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    final String name = node.getNodeName();
                    if (!"arg".equals(name) && !"credentials".equals(name)) {
                        final String value = node.getTextContent();
                        final Node typeNode = node.getAttributes().getNamedItem("type");
                        final Method method = clazz.getMethod(
                                "set" + name.substring(0, 1).toUpperCase() + name.substring(1),
                                getMethodArgClass(typeNode));
                        method.invoke(solrServer, getMethodArgValue(typeNode, value));
                    }
                }
            }
            if (solrServer instanceof SolrLibHttpSolrServer) {
                ((SolrLibHttpSolrServer) solrServer).init();
            }
            suggestUpdateConfig.setSolrServer(solrServer);
        } catch (final Exception e) {
            throw new FessSuggestException("Failed to load SolrServer.", e);
        }
    }

    final String labelFields = config.getVal("updateHandler/suggest/labelFields", false);
    if (StringUtils.isNotBlank(labelFields)) {
        suggestUpdateConfig.setLabelFields(labelFields.trim().split(","));
    }
    final String roleFields = config.getVal("updateHandler/suggest/roleFields", false);
    if (StringUtils.isNotBlank(roleFields)) {
        suggestUpdateConfig.setRoleFields(roleFields.trim().split(","));
    }

    final String expiresField = config.getVal("updateHandler/suggest/expiresField", false);
    if (StringUtils.isNotBlank(expiresField)) {
        suggestUpdateConfig.setExpiresField(expiresField);
    }
    final String segmentField = config.getVal("updateHandler/suggest/segmentField", false);
    if (StringUtils.isNotBlank(segmentField)) {
        suggestUpdateConfig.setSegmentField(segmentField);
    }
    final String updateInterval = config.getVal("updateHandler/suggest/updateInterval", false);
    if (StringUtils.isNotBlank(updateInterval) && StringUtils.isNumeric(updateInterval)) {
        suggestUpdateConfig.setUpdateInterval(Long.parseLong(updateInterval));
    }

    //set suggestFieldInfo
    final NodeList nodeList = config.getNodeList("updateHandler/suggest/suggestFieldInfo", true);
    for (int i = 0; i < nodeList.getLength(); i++) {
        try {
            final SuggestUpdateConfig.FieldConfig fieldConfig = new SuggestUpdateConfig.FieldConfig();
            final Node fieldInfoNode = nodeList.item(i);
            final NamedNodeMap fieldInfoAttributes = fieldInfoNode.getAttributes();
            final Node fieldNameNode = fieldInfoAttributes.getNamedItem("fieldName");
            final String fieldName = fieldNameNode.getNodeValue();
            if (StringUtils.isBlank(fieldName)) {
                continue;
            }
            fieldConfig.setTargetFields(fieldName.trim().split(","));
            if (logger.isInfoEnabled()) {
                for (final String s : fieldConfig.getTargetFields()) {
                    logger.info("fieldName : " + s);
                }
            }

            final NodeList fieldInfoChilds = fieldInfoNode.getChildNodes();
            for (int j = 0; j < fieldInfoChilds.getLength(); j++) {
                final Node fieldInfoChildNode = fieldInfoChilds.item(j);
                final String fieldInfoChildNodeName = fieldInfoChildNode.getNodeName();

                if ("tokenizerFactory".equals(fieldInfoChildNodeName)) {
                    //field tokenier settings
                    final SuggestUpdateConfig.TokenizerConfig tokenizerConfig = new SuggestUpdateConfig.TokenizerConfig();

                    final NamedNodeMap tokenizerFactoryAttributes = fieldInfoChildNode.getAttributes();
                    final Node tokenizerClassNameNode = tokenizerFactoryAttributes.getNamedItem("class");
                    final String tokenizerClassName = tokenizerClassNameNode.getNodeValue();
                    tokenizerConfig.setClassName(tokenizerClassName);
                    if (logger.isInfoEnabled()) {
                        logger.info("tokenizerFactory : " + tokenizerClassName);
                    }

                    final Map<String, String> args = new HashMap<String, String>();
                    for (int k = 0; k < tokenizerFactoryAttributes.getLength(); k++) {
                        final Node attribute = tokenizerFactoryAttributes.item(k);
                        final String key = attribute.getNodeName();
                        final String value = attribute.getNodeValue();
                        if (!"class".equals(key)) {
                            args.put(key, value);
                        }
                    }
                    if (!args.containsKey(USER_DICT_PATH)) {
                        final String userDictPath = System.getProperty(SuggestConstants.USER_DICT_PATH, "");
                        if (StringUtils.isNotBlank(userDictPath)) {
                            args.put(USER_DICT_PATH, userDictPath);
                        }
                        final String userDictEncoding = System.getProperty(SuggestConstants.USER_DICT_ENCODING,
                                "");
                        if (StringUtils.isNotBlank(userDictEncoding)) {
                            args.put(USER_DICT_ENCODING, userDictEncoding);
                        }
                    }
                    tokenizerConfig.setArgs(args);

                    fieldConfig.setTokenizerConfig(tokenizerConfig);
                } else if ("suggestReadingConverter".equals(fieldInfoChildNodeName)) {
                    //field reading converter settings
                    final NodeList converterNodeList = fieldInfoChildNode.getChildNodes();
                    for (int k = 0; k < converterNodeList.getLength(); k++) {
                        final SuggestUpdateConfig.ConverterConfig converterConfig = new SuggestUpdateConfig.ConverterConfig();

                        final Node converterNode = converterNodeList.item(k);
                        if (!"converter".equals(converterNode.getNodeName())) {
                            continue;
                        }

                        final NamedNodeMap converterAttributes = converterNode.getAttributes();
                        final Node classNameNode = converterAttributes.getNamedItem("class");
                        final String className = classNameNode.getNodeValue();
                        converterConfig.setClassName(className);
                        if (logger.isInfoEnabled()) {
                            logger.info("converter : " + className);
                        }

                        final Map<String, String> properties = new HashMap<String, String>();
                        for (int l = 0; l < converterAttributes.getLength(); l++) {
                            final Node attribute = converterAttributes.item(l);
                            final String key = attribute.getNodeName();
                            final String value = attribute.getNodeValue();
                            if (!"class".equals(key)) {
                                properties.put(key, value);
                            }
                        }
                        converterConfig.setProperties(properties);
                        if (logger.isInfoEnabled()) {
                            logger.info("converter properties = " + properties);
                        }
                        fieldConfig.addConverterConfig(converterConfig);
                    }
                } else if ("suggestNormalizer".equals(fieldInfoChildNodeName)) {
                    //field normalizer settings
                    final NodeList normalizerNodeList = fieldInfoChildNode.getChildNodes();
                    for (int k = 0; k < normalizerNodeList.getLength(); k++) {
                        final SuggestUpdateConfig.NormalizerConfig normalizerConfig = new SuggestUpdateConfig.NormalizerConfig();

                        final Node normalizerNode = normalizerNodeList.item(k);
                        if (!"normalizer".equals(normalizerNode.getNodeName())) {
                            continue;
                        }

                        final NamedNodeMap normalizerAttributes = normalizerNode.getAttributes();
                        final Node classNameNode = normalizerAttributes.getNamedItem("class");
                        final String className = classNameNode.getNodeValue();
                        normalizerConfig.setClassName(className);
                        if (logger.isInfoEnabled()) {
                            logger.info("normalizer : " + className);
                        }

                        final Map<String, String> properties = new HashMap<String, String>();
                        for (int l = 0; l < normalizerAttributes.getLength(); l++) {
                            final Node attribute = normalizerAttributes.item(l);
                            final String key = attribute.getNodeName();
                            final String value = attribute.getNodeValue();
                            if (!"class".equals(key)) {
                                properties.put(key, value);
                            }
                        }
                        normalizerConfig.setProperties(properties);
                        if (logger.isInfoEnabled()) {
                            logger.info("normalize properties = " + properties);
                        }
                        fieldConfig.addNormalizerConfig(normalizerConfig);
                    }
                }
            }

            suggestUpdateConfig.addFieldConfig(fieldConfig);
        } catch (final Exception e) {
            throw new FessSuggestException("Failed to load Suggest Field Info.", e);
        }
    }

    return suggestUpdateConfig;
}

From source file:com.redhat.rhn.domain.session.test.WebSessionFactoryTest.java

public void testGetKey() {
    WebSession s = WebSessionFactory.createSession();
    //Try with an invalid session id (null)
    try {/*w  w  w  .ja va  2  s  .c  o  m*/
        s.getKey();
        fail();
    } catch (InvalidSessionIdException e) {
        //Success!!!
    }
    long expTime = TimeUtils.currentTimeSeconds() + EXP_TIME;
    s.setExpires(expTime);
    s.setWebUserId(null);

    WebSessionFactory.save(s);

    //Make sure we get a key
    assertNotNull(s.getKey());
    String id = s.getKey().substring(0, s.getKey().indexOf('x'));
    assertTrue(StringUtils.isNumeric(id));
}