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.redhat.rhn.common.util.RecurringEventPicker.java

/**
 * @return Returns the dayOfMonth./*from   w w w  .  j  a v  a2 s.  c o m*/
 */
public Long getDayOfMonthLong() {
    String st = getCronValue(3);
    if (StringUtils.isNumeric(st)) {
        return Long.parseLong(st);
    }
    return -1L;
}

From source file:fr.paris.lutece.portal.web.user.attribute.AttributeFieldJspBean.java

/**
 * Remove the attribute field/*www.  ja  v  a 2  s  . com*/
 * @param request HttpServletRequest
 * @return The Jsp URL of the process result
 */
public String doRemoveAttributeField(HttpServletRequest request) {
    String strIdAttribute = request.getParameter(PARAMETER_ID_ATTRIBUTE);
    String strIdField = request.getParameter(PARAMETER_ID_FIELD);

    if (StringUtils.isNotBlank(strIdField) && StringUtils.isNumeric(strIdField)) {
        int nIdField = Integer.parseInt(strIdField);

        _attributeFieldService.removeAttributeFieldFromIdField(nIdField);
        AdminUserFieldService.doRemoveUserFieldsByIdField(nIdField);
    }

    return JSP_MODIFY_ATTRIBUTE + QUESTION_MARK + PARAMETER_ID_ATTRIBUTE + EQUAL + strIdAttribute;
}

From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java

private void initEmailInfo(Email email) throws EmailException {
    email.setMailSession(mailSession);//from   ww  w.  ja  v  a 2  s  .  c  om

    String smtpPort = email.getMailSession().getProperty(Email.MAIL_PORT);

    email.setFrom(senderEmail, senderName);
    if (StringUtils.isNumeric(smtpPort) && Integer.valueOf(smtpPort) > 0) {
        email.setSmtpPort(Integer.valueOf(smtpPort));
    }
}

From source file:eu.stork.peps.auth.commons.PEPSUtil.java

/**
 * Gets the Stork error code in the error message if exists!
 * //from  www  . j a  v  a 2s. com
 * @param errorMessage The message to get the error code if exists;
 * 
 * @return the error code if exists. Returns null otherwise.
 */
public static String getStorkErrorCode(final String errorMessage) {
    if (StringUtils.isNotBlank(errorMessage)
            && errorMessage.indexOf(PEPSValues.ERROR_MESSAGE_SEP.toString()) >= 0) {
        final String[] msgSplitted = errorMessage.split(PEPSValues.ERROR_MESSAGE_SEP.toString());
        if (msgSplitted.length == 2 && StringUtils.isNumeric(msgSplitted[0])) {
            return msgSplitted[0];
        }
    }
    return null;
}

From source file:com.redhat.rhn.common.util.RecurringEventPicker.java

/**
 * @return Returns the dayOfMonth String.
 *//*from w ww .  j  a va  2 s .c  o m*/
public String getDayOfWeekString() {
    String num = getCronValue(5);
    if (num == null || !StringUtils.isNumeric(num) || getDayNames().length < Integer.parseInt(num)
            || Integer.parseInt(num) < 1) {
        return null;
    }
    return getDayNames()[Integer.parseInt(num) - 1];
}

From source file:com.cloudera.whirr.cm.server.CmServerCluster.java

public synchronized Map<String, Map<String, String>> getServiceConfiguration(int versionApi) {
    Map<String, Map<String, String>> configuration = new HashMap<String, Map<String, String>>();
    for (String configVersion : this.configuration.keySet()) {
        for (String configGroup : this.configuration.get(configVersion).keySet()) {
            for (String configSetting : this.configuration.get(configVersion).get(configGroup).keySet()) {
                if (StringUtils.isNumeric(configVersion)) {
                    if (versionApi < 0 || Integer.parseInt(configVersion) <= versionApi) {
                        if (configuration.get(configGroup) == null) {
                            configuration.put(configGroup, new HashMap<String, String>());
                        }//from  w  w  w .j  a va  2  s. com
                        configuration.get(configGroup).put(configSetting,
                                this.configuration.get(configVersion).get(configGroup).get(configSetting));
                    }
                }
            }
        }
    }
    return configuration;
}

From source file:fr.paris.lutece.plugins.calendar.service.AgendaSubscriberService.java

/**
 * Performs unsubscription process/*  w  w w .j  a v  a2  s  .  c  om*/
 * Throw a SiteMessage
 * @param request The http request
 * @param plugin The plugin
 * @throws fr.paris.lutece.portal.service.message.SiteMessageException The
 *             error message handled by the front office
 */
public void doUnSubscribe(HttpServletRequest request, Plugin plugin) throws SiteMessageException {
    String strEmail = request.getParameter(Constants.PARAMETER_EMAIL);
    String strAgenda = request.getParameter(Constants.PARAM_AGENDA);
    if (StringUtils.isNotBlank(strEmail)) {
        if (StringUtils.isNotBlank(strAgenda) && StringUtils.isNumeric(strAgenda)) {
            CalendarSubscriber subscriber = CalendarSubscriberHome.findByEmail(strEmail, plugin);

            CalendarSubscriberHome.removeSubscriber(subscriber.getId(), Integer.parseInt(strAgenda), plugin);
            if (!CalendarSubscriberHome.isUserSubscribed(subscriber.getId(), plugin)) {
                CalendarSubscriberHome.remove(subscriber.getId(), plugin);
            }

            SiteMessageService.setMessage(request, PROPERTY_UNSUBSCRIPTION_OK_ALERT_MESSAGE,
                    PROPERTY_UNSUBSCRIPTION_OK_TITLE_MESSAGE, SiteMessage.TYPE_INFO);
        } else {
            SiteMessageService.setMessage(request, PROPERTY_NO_CALENDAR_CHOSEN_ERROR_MESSAGE,
                    PROPERTY_NO_CALENDAR_CHOSEN_TITLE_MESSAGE, SiteMessage.TYPE_STOP);
        }
    } else {
        SiteMessageService.setMessage(request, PROPERTY_INVALID_MAIL_ERROR_MESSAGE,
                PROPERTY_INVALID_MAIL_TITLE_MESSAGE, SiteMessage.TYPE_STOP);
    }
}

From source file:com.adobe.acs.commons.images.impl.NamedTransformImageServlet.java

/**
 * Gets the NamedImageTransformers based on the Suffix segments in order.
 *
 * @param request the SlingHttpServletRequest object
 * @return a list of the NamedImageTransformers specified by the HTTP Request suffix segments
 *///from ww w.  j  a  v  a  2 s . com
protected final List<NamedImageTransformer> getNamedImageTransformers(final SlingHttpServletRequest request) {
    final List<NamedImageTransformer> transformers = new ArrayList<NamedImageTransformer>();

    String[] suffixes = PathInfoUtil.getSuffixSegments(request);
    if (suffixes.length < 2) {
        log.warn("Named Transform Image Servlet requires at least one named transform");
        return transformers;
    }

    int endIndex = suffixes.length - 1;
    // Its OK to check; the above check ensures there are 2+ segments
    if (StringUtils.isNumeric(PathInfoUtil.getSuffixSegment(request, suffixes.length - 2))) {
        endIndex--;
    }

    suffixes = (String[]) ArrayUtils.subarray(suffixes, 0, endIndex);

    for (final String transformerName : suffixes) {
        final NamedImageTransformer transformer = this.namedImageTransformers.get(transformerName);
        if (transformer != null) {
            transformers.add(transformer);
        }
    }

    return transformers;
}

From source file:com.cloud.network.guru.BigSwitchBcfGuestNetworkGuru.java

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
        ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert (network.getState() == State.Implementing) : "Why are we implementing " + network;

    bcfUtilsInit();//  w  w w. j ava2  s . c o  m

    long dcId = dest.getDataCenter().getId();

    long physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(),
            offering.getTrafficType());

    NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(),
            network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
            network.getDataCenterId(), physicalNetworkId, false);

    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }

    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }

    String vnetId = "";
    if (network.getBroadcastUri() == null) {
        vnetId = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(),
                context.getReservationId(), UseSystemGuestVlans.valueIn(network.getAccountId()));
        if (vnetId == null) {
            throw new InsufficientVirtualNetworkCapacityException(
                    "Unable to allocate vnet as a " + "part of network " + network + " implement ",
                    DataCenter.class, dcId);
        }
        implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnetId));
        ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(),
                network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN,
                "Assigned Zone Vlan: " + vnetId + " Network Id: " + network.getId(), 0);
    } else {
        implemented.setBroadcastUri(network.getBroadcastUri());
    }

    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    if (name.length() > 64) {
        name = name.substring(0, 63); // max length 64
    }

    // update fields in network object
    NetworkVO networkObject = (NetworkVO) network;

    // determine whether this is VPC network or stand-alone network
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }

    // use uuid of networkVO as network id in BSN
    String networkId = networkObject.getUuid();

    String tenantId;
    String tenantName;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        tenantName = vpc.getName();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        // use network in CS as tenant in BSN
        // for non-VPC networks, use network name and id as tenant name and id
        tenantId = networkId;
        tenantName = name;
    }

    // store tenantId in networkObject for NetworkOrchestrator implementNetwork use
    networkObject.setNetworkDomain(tenantId);
    // store tenant Id in implemented object for future actions (e.g., shutdown)
    implemented.setNetworkDomain(tenantId);
    String vlanStr = BroadcastDomainType.getValue(implemented.getBroadcastUri());

    // get public net info - needed to set up source nat gateway
    NetworkVO pubNet = _bcfUtils.getPublicNetwork(physicalNetworkId);

    // locate subnet info
    SearchCriteria<VlanVO> sc = _vlanDao.createSearchCriteria();
    sc.setParameters("network_id", pubNet.getId());
    VlanVO pubVlanVO = _vlanDao.findOneBy(sc);
    String pubVlanStr = pubVlanVO.getVlanTag();

    Integer vlan;
    if (StringUtils.isNumeric(vlanStr)) {
        vlan = Integer.valueOf(vlanStr);
    } else {
        vlan = 0;
    }
    CreateBcfSegmentCommand cmd1 = new CreateBcfSegmentCommand(tenantId, tenantName, networkId, name, vlan);

    _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd1, networkObject);

    if (_bcfUtils.isNatEnabled()) {
        Integer pvlan;
        if (StringUtils.isNumeric(pubVlanStr)) {
            pvlan = Integer.valueOf(pubVlanStr);
        } else {
            pvlan = 0;
        }
        CreateBcfSegmentCommand cmd2 = new CreateBcfSegmentCommand("external", "external", "external",
                "external", pvlan);

        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd2, networkObject);

        CreateBcfRouterCommand cmd3 = new CreateBcfRouterCommand(tenantId);

        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd3, network);

        CreateBcfRouterInterfaceCommand cmd5 = new CreateBcfRouterInterfaceCommand(tenantId, network.getUuid(),
                network.getCidr(), network.getGateway(), network.getName());

        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd5, network);
    }
    return implemented;
}

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

/**
 * @return//  w  w  w  .j ava 2  s  .  c  o m
 *
@Secured("ROLE_USER")
@Transactional(readOnly = true)
@RemoteMethod
public Collection<GeographyDTO> autocompleteGeography() {
   return autocompleteGeography(null, "ALL");
}
*/

@Transactional(readOnly = true)
@RemoteMethod
private List<? extends Geography> getGeographiesInState(final State state, final String text) {
    Validate.notNull(state);
    String query = StringUtils.trimToNull(text);
    final Class<? extends Geography> geographyType;
    if (StringUtils.isNumeric(query)) {
        geographyType = Zipcode.class;
    } else {
        geographyType = County.class;
        query = stripCountyFromQuery(query);
    }
    List<? extends Geography> ret = geographyRepository.getGeographiesInState(state, query, geographyType,
            false);
    if (ret.size() == 0) {
        ret = geographyRepository.getGeographiesInState(state, query, geographyType, true);
    }
    return ret;
}