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:org.verwandlung.voj.web.controller.AdministrationController.java

/**
 * ?.//  w  w  w. j a v  a2s. co  m
 * @param problemName - ??
 * @param timeLimit - ?
 * @param memoryLimit - ??
 * @param description - ??
 * @param hint - ??
 * @param inputFormat - ?
 * @param outputFormat - ?
 * @param inputSample - 
 * @param outputSample - 
 * @param testCases - (JSON ?)
 * @param problemCategories - (JSON ?)
 * @param problemTags - ((JSON ?)
 * @param isPublic - ?
 * @param isExactlyMatch - ??
 * @param request - HttpServletRequest
 * @return ? Map<String, Boolean>
 */
@RequestMapping(value = "/createProblem.action", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> createProblemAction(
        @RequestParam(value = "problemName") String problemName,
        @RequestParam(value = "timeLimit") String timeLimit,
        @RequestParam(value = "memoryLimit") String memoryLimit,
        @RequestParam(value = "description") String description, @RequestParam(value = "hint") String hint,
        @RequestParam(value = "inputFormat") String inputFormat,
        @RequestParam(value = "outputFormat") String outputFormat,
        @RequestParam(value = "inputSample") String inputSample,
        @RequestParam(value = "outputSample") String outputSample,
        @RequestParam(value = "testCases") String testCases,
        @RequestParam(value = "problemCategories") String problemCategories,
        @RequestParam(value = "problemTags") String problemTags,
        @RequestParam(value = "isPublic") boolean isPublic,
        @RequestParam(value = "isExactlyMatch") boolean isExactlyMatch, HttpServletRequest request) {
    if (timeLimit.isEmpty() || !StringUtils.isNumeric(timeLimit)) {
        timeLimit = "-1";
    }
    if (memoryLimit.isEmpty() || !StringUtils.isNumeric(memoryLimit)) {
        memoryLimit = "-1";
    }
    Map<String, Object> result = problemService.createProblem(problemName, Integer.parseInt(timeLimit),
            Integer.parseInt(memoryLimit), description, hint, inputFormat, outputFormat, inputSample,
            outputSample, testCases, problemCategories, problemTags, isPublic, isExactlyMatch);

    if ((boolean) result.get("isSuccessful")) {
        long problemId = (Long) result.get("problemId");
        String ipAddress = HttpRequestParser.getRemoteAddr(request);

        LOGGER.info(String.format("Problem: [ProblemId=%s] was created by administrator at %s.",
                new Object[] { problemId, ipAddress }));
    }
    return result;
}

From source file:org.verwandlung.voj.web.controller.AdministrationController.java

/**
 * ?.//from  w w w.jav a 2 s  .com
 * @param problemName - ??
 * @param timeLimit - ?
 * @param memoryLimit - ??
 * @param description - ??
 * @param hint - ??
 * @param inputFormat - ?
 * @param outputFormat - ?
 * @param inputSample - 
 * @param outputSample - 
 * @param testCases - (JSON ?)
 * @param problemCategories - (JSON ?)
 * @param problemTags - ((JSON ?)
 * @param isPublic - ?
 * @param isExactlyMatch - ??
 * @param request - HttpServletRequest
 * @return ? Map<String, Boolean>
 */
@RequestMapping(value = "/editProblem.action", method = RequestMethod.POST)
public @ResponseBody Map<String, Boolean> editProblemAction(@RequestParam(value = "problemId") long problemId,
        @RequestParam(value = "problemName") String problemName,
        @RequestParam(value = "timeLimit") String timeLimit,
        @RequestParam(value = "memoryLimit") String memoryLimit,
        @RequestParam(value = "description") String description, @RequestParam(value = "hint") String hint,
        @RequestParam(value = "inputFormat") String inputFormat,
        @RequestParam(value = "outputFormat") String outputFormat,
        @RequestParam(value = "inputSample") String inputSample,
        @RequestParam(value = "outputSample") String outputSample,
        @RequestParam(value = "testCases") String testCases,
        @RequestParam(value = "problemCategories") String problemCategories,
        @RequestParam(value = "problemTags") String problemTags,
        @RequestParam(value = "isPublic") boolean isPublic,
        @RequestParam(value = "isExactlyMatch") boolean isExactlyMatch, HttpServletRequest request) {
    if (timeLimit.isEmpty() || !StringUtils.isNumeric(timeLimit)) {
        timeLimit = "-1";
    }
    if (memoryLimit.isEmpty() || !StringUtils.isNumeric(memoryLimit)) {
        memoryLimit = "-1";
    }
    Map<String, Boolean> result = problemService.editProblem(problemId, problemName,
            Integer.parseInt(timeLimit), Integer.parseInt(memoryLimit), description, hint, inputFormat,
            outputFormat, inputSample, outputSample, testCases, problemCategories, problemTags, isPublic,
            isExactlyMatch);

    if (result.get("isSuccessful")) {
        String ipAddress = HttpRequestParser.getRemoteAddr(request);

        LOGGER.info(String.format("Problem: [ProblemId=%s] was edited by administrator at %s.",
                new Object[] { problemId, ipAddress }));
    }
    return result;
}

From source file:org.whispersystems.textsecuregcm.auth.AuthorizationHeader.java

public static AuthorizationHeader fromUserAndPassword(String user, String password)
        throws InvalidAuthorizationHeaderException {
    try {//from   www.  j a va2s  . co m

        final String id = StringUtils.substringAfterLast(user, ".");
        if (StringUtils.isNumeric(id)) {
            return new AuthorizationHeader(StringUtils.substringBeforeLast(user, "."), Long.parseLong(id),
                    password);
        } else {
            return new AuthorizationHeader(user, 1, password);
        }

    } catch (NumberFormatException nfe) {
        throw new InvalidAuthorizationHeaderException(nfe);
    }
}

From source file:org.xwiki.rendering.internal.wiki.XWikiWikiModel.java

/**
 * Creates the query string that can be added to an image URL to resize the image on the server side.
 *
 * @param imageParameters image parameters, including width and height then they are specified
 * @return the query string to be added to an image URL in order to resize the image on the server side
 *///from   w w  w .ja va 2 s .c om
private StringBuilder getImageURLQueryString(Map<String, String> imageParameters) {
    String width = StringUtils.chomp(getImageDimension(WIDTH, imageParameters), PIXELS);
    String height = StringUtils.chomp(getImageDimension(HEIGHT, imageParameters), PIXELS);
    boolean useHeight = StringUtils.isNotEmpty(height) && StringUtils.isNumeric(height);
    StringBuilder queryString = new StringBuilder();
    if (StringUtils.isEmpty(width) || !StringUtils.isNumeric(width)) {
        // Width is unspecified or is not measured in pixels.
        if (useHeight) {
            // Height is specified in pixels.
            queryString.append('&').append(HEIGHT).append('=').append(height);
        } else {
            // If image width and height are unspecified or if they are not expressed in pixels then limit the image
            // size to best fit the rectangle specified in the configuration (keeping aspect ratio).
            int widthLimit = this.xwikiRenderingConfiguration.getImageWidthLimit();
            if (widthLimit > 0) {
                queryString.append('&').append(WIDTH).append('=').append(widthLimit);
            }
            int heightLimit = this.xwikiRenderingConfiguration.getImageHeightLimit();
            if (heightLimit > 0) {
                queryString.append('&').append(HEIGHT).append('=').append(heightLimit);
            }
            if (widthLimit > 0 && heightLimit > 0) {
                queryString.append("&keepAspectRatio=").append(true);
            }
        }
    } else {
        // Width is specified in pixels.
        queryString.append('&').append(WIDTH).append('=').append(width);
        if (useHeight) {
            // Height is specified in pixels.
            queryString.append('&').append(HEIGHT).append('=').append(height);
        }
    }
    return queryString;
}

From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java

/**
 * Avoid using the Access key attribute. If the decision is nevertheless made to apply this attribute, only use it
 * on links that remain unchanged throughout the site (e.g. main navigation) and limit the shortcut key combinations
 * to numbers.//from  w  ww  .j  a va2s.c o  m
 */
public void validateRpd8s11() {
    for (Node link : getElements(ELEM_LINK)) {
        if (hasAttribute(link, ATTR_ACCESSKEY)) {
            assertTrue(Type.ERROR, "rpd8s11.accesskey",
                    StringUtils.isNumeric(getAttributeValue(link, ATTR_ACCESSKEY)));
        }
    }
}

From source file:org.xwiki.validator.HTML5DutchWebGuidelinesValidator.java

/**
 * Avoid using the Access key attribute. If the decision is nevertheless made to apply this attribute, only use it
 * on links that remain unchanged throughout the site (e.g. main navigation) and limit the shortcut key combinations
 * to numbers./*from  w w w. ja  v  a  2s  . com*/
 */
public void validateRpd8s11() {
    for (Element link : getElements(ELEM_LINK)) {
        if (hasAttribute(link, ATTR_ACCESSKEY)) {
            assertTrue(Type.ERROR, "rpd8s11.accesskey",
                    StringUtils.isNumeric(getAttributeValue(link, ATTR_ACCESSKEY)));
        }
    }
}

From source file:org.yamj.core.api.json.CommonController.java

@RequestMapping(value = "/genre/{name}", method = RequestMethod.GET)
@ResponseBody// ww  w  . ja v a2  s . c o  m
public ApiWrapperSingle<Genre> getGenre(@PathVariable String name) {
    Genre genre;
    ApiWrapperSingle<Genre> wrapper = new ApiWrapperSingle<Genre>();
    if (StringUtils.isNumeric(name)) {
        LOG.info("Getting genre with ID '{}'", name);
        genre = jsonApiStorageService.getGenre(Long.parseLong(name));
    } else {
        LOG.info("Getting genre with name '{}'", name);
        genre = jsonApiStorageService.getGenre(name);
    }
    wrapper.setResult(genre);
    wrapper.setStatusCheck();
    return wrapper;
}

From source file:org.yamj.core.api.json.CommonController.java

@RequestMapping(value = "/certification/{name}", method = RequestMethod.GET)
@ResponseBody//from w ww.j  a v a 2s .  com
public ApiWrapperSingle<Certification> getCertification(@PathVariable String name) {
    Certification certification;
    ApiWrapperSingle<Certification> wrapper = new ApiWrapperSingle<Certification>();
    if (StringUtils.isNumeric(name)) {
        LOG.info("Getting genre with ID '{}'", name);
        certification = jsonApiStorageService.getCertification(Long.parseLong(name));
    } else {
        LOG.info("Getting certification '{}'", name);
        certification = jsonApiStorageService.getCertification(name);
    }
    wrapper.setResult(certification);
    wrapper.setStatusCheck();
    return wrapper;
}

From source file:org.yamj.core.api.json.CommonController.java

@RequestMapping(value = "/studio/{name}", method = RequestMethod.GET)
@ResponseBody//  w  ww .j  a  v  a 2  s .co m
public ApiWrapperSingle<Studio> getStudio(@PathVariable String name) {
    Studio studio;
    ApiWrapperSingle<Studio> wrapper = new ApiWrapperSingle<Studio>();
    if (StringUtils.isNumeric(name)) {
        LOG.info("Getting studio with ID '{}'", name);
        studio = jsonApiStorageService.getStudio(Long.parseLong(name));
    } else {
        LOG.info("Getting studio '{}'", name);
        studio = jsonApiStorageService.getStudio(name);
    }
    wrapper.setResult(studio);
    wrapper.setStatusCheck();
    return wrapper;
}

From source file:org.yamj.core.api.json.CommonController.java

@RequestMapping(value = "/boxedset/{name}", method = RequestMethod.GET)
@ResponseBody//from   ww w. jav a2s. c o  m
public ApiWrapperSingle<BoxedSet> getBoxSet(@PathVariable String name) {
    BoxedSet boxedSet;
    ApiWrapperSingle<BoxedSet> wrapper = new ApiWrapperSingle<BoxedSet>();
    if (StringUtils.isNumeric(name)) {
        LOG.info("Getting boxset with ID '{}'", name);
        boxedSet = jsonApiStorageService.getBoxedSet(Long.parseLong(name));
    } else {
        LOG.info("Getting boxset '{}'", name);
        boxedSet = jsonApiStorageService.getBoxedSet(name);
    }
    wrapper.setResult(boxedSet);
    wrapper.setStatusCheck();
    return wrapper;
}