Example usage for org.springframework.util StringUtils hasLength

List of usage examples for org.springframework.util StringUtils hasLength

Introduction

In this page you can find the example usage for org.springframework.util StringUtils hasLength.

Prototype

public static boolean hasLength(@Nullable String str) 

Source Link

Document

Check that the given String is neither null nor of length 0.

Usage

From source file:com.starit.diamond.server.service.ConfigService.java

String generatePath(String dataId, final String group) {
    if (!StringUtils.hasLength(dataId) || StringUtils.containsWhitespace(dataId))
        throw new IllegalArgumentException("dataId");

    if (!StringUtils.hasLength(group) || StringUtils.containsWhitespace(group))
        throw new IllegalArgumentException("group");
    String fnDataId = SystemConfig.encodeDataIdForFNIfUnderWin(dataId);
    StringBuilder sb = new StringBuilder("/");
    sb.append(Constants.BASE_DIR).append("/");
    sb.append(group).append("/");
    sb.append(fnDataId);/*ww w  . j av a 2s . com*/
    return sb.toString();
}

From source file:org.zilverline.web.ExtractorMappingsController.java

/** Method updates an existing IndexService's ExtractorFactory. */
/*/*from  w  w  w. j  av  a 2s . c om*/
 * (non-Javadoc)
 * 
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws ServletException {
    // reconstruct the extractor map, it contains pairs of (extension,
    // extractor)
    // in the request they are related by the fact that the extension is in
    // a parameter with an integer value
    // and the extractor contains 'prefix' and corresponding integer value

    // first get the prefix (posted as hidden field)
    String prefix = request.getParameter("prefix");
    if (!StringUtils.hasLength(prefix)) {
        log.warn("no prefix set");
        prefix = "select_";
    }

    // get keys and values
    Map reqMap = request.getParameterMap();
    Iterator iter = reqMap.entrySet().iterator();
    String[] keys = new String[reqMap.size()];
    String[] values = new String[reqMap.size()];
    while (iter.hasNext()) {
        Map.Entry element = (Map.Entry) iter.next();
        String key = (String) element.getKey();
        String value = ((String[]) element.getValue())[0];
        log.debug("Parsing request for: " + key + ", " + value);
        try {
            if (key.startsWith(prefix)) {
                String indexStr = key.substring(prefix.length());
                int index = Integer.parseInt(indexStr);
                log.debug("Adding " + value + " to values[" + index + "]");
                values[index] = value;
            } else {
                int index = Integer.parseInt(key);
                log.debug("Adding " + value + " to keys[" + index + "]");
                keys[index] = value;
            }
        } catch (NumberFormatException e) {
            // not an extractor related requestParameter
            log.debug("Skipping " + key + ", " + value);
        }
    }

    // add the key value pairs to Map, if value contains value
    Map props = new Properties();
    for (int i = 0; i < values.length; i++) {
        if (StringUtils.hasLength(values[i])) {
            log.debug("Adding " + keys[i] + "," + values[i] + " to map");
            props.put(keys[i], values[i]);
        } else {
            log.debug("Skipping (remove) " + keys[i] + "," + values[i] + " to map");
        }
    }
    collectionManager.getFactory()
            .setCaseSensitive(RequestUtils.getBooleanParameter(request, "casesensitive", false));
    collectionManager.getFactory()
            .setDefaultFileinfo(RequestUtils.getBooleanParameter(request, "defaultfileinfo", false));
    collectionManager.getFactory().setMappings(props);
    try {
        collectionManager.store();
    } catch (IndexException e) {
        throw new ServletException("Error storing new CollectionManager Defaults", e);
    }

    return new ModelAndView(getSuccessView());
}

From source file:edu.uchicago.duo.service.DuoPhoneObjImpl.java

@Override
public String getObjByParam(String phoneNumber, String landLineExtension, String attribute) {
    String returnObj = null;//  w  ww  . j  ava2 s. c om

    request = genHttpRequest("GET", duoPhoneApi, "admin");
    request.addParam("number", phoneNumber);
    if (StringUtils.hasLength(landLineExtension)) {
        request.addParam("extension", landLineExtension);
    }
    request = signHttpRequest("admin");

    try {
        jResults = (JSONArray) request.executeRequest();

        switch (attribute) {
        case "username":
            JSONArray userproperty = jResults.getJSONObject(0).getJSONArray("users");
            returnObj = userproperty.getJSONObject(0).getString("username");
            break;
        }

    } catch (Exception ex) {
        logger.debug(
                "2FA Exception - " + "Phone Not Exist!!!If triggered by Validation is a good thing, not error");
        logger.debug("2FA Exception - " + "The Error is: " + ex.toString());
    }

    return returnObj;

}

From source file:com.starit.diamond.server.service.NotifyService.java

String generateNotifyGroupChangedPath(String address) {
    String specialUrl = this.nodeProperties.getProperty(address);
    String urlString = PROTOCOL + address + URL_PREFIX;
    // urlurl/*from  ww  w.ja va  2  s  . c o m*/
    if (specialUrl != null && StringUtils.hasLength(specialUrl.trim())) {
        urlString = specialUrl;
    }
    return urlString + "?method=notifyGroup";
}

From source file:com.trigonic.utils.spring.beans.ImportBeanDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    String primaryLocation = element.getAttribute(RESOURCE_ATTRIBUTE);
    if (!StringUtils.hasText(primaryLocation)) {
        readerContext.error("Resource location must not be empty", element);
        return null;
    }//from w ww. jav  a2s  .  com

    String alternateLocation = element.getAttribute(ALTERNATE_ATTRIBUTE);
    boolean optional = Boolean.parseBoolean(element.getAttribute(OPTIONAL_ATTRIBUTE));

    String currentLocation = primaryLocation;
    try {
        Set<Resource> actualResources = ImportHelper.importResource(readerContext.getReader(),
                readerContext.getResource(), currentLocation);

        if (actualResources.isEmpty() && StringUtils.hasLength(alternateLocation)) {
            currentLocation = alternateLocation;
            actualResources = ImportHelper.importResource(readerContext.getReader(),
                    readerContext.getResource(), currentLocation);
        }

        if (actualResources.isEmpty() && !optional) {
            readerContext.error("Primary location [" + primaryLocation + "]"
                    + (alternateLocation == null ? "" : " and alternate location [" + alternateLocation + "]")
                    + " are not optional", element);
            return null;
        }

        Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]);
        readerContext.fireImportProcessed(primaryLocation, actResArray, readerContext.extractSource(element));
    } catch (BeanDefinitionStoreException ex) {
        readerContext.error("Failed to import bean definitions from location [" + currentLocation + "]",
                element, ex);
    }

    return null;
}

From source file:org.zilverline.web.HandlersController.java

/** Method updates an existing SearchService. */
/*/*from   ww  w  . j  av a2s  . com*/
 * (non-Javadoc)
 * 
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws ServletException {
    Handler thisForm = (Handler) command;

    // reconstruct the extractor map, it contains pairs of (extension,
    // extractor)
    // in the request they are related by the fact that the extension is in
    // a parameter with an integer value
    // and the extractor contains 'prefix' and corresponding integer value

    // first get the prefix (posted as hidden field)
    String prefix = request.getParameter("prefix");
    if (!StringUtils.hasLength(prefix)) {
        log.warn("no prefix set");
        prefix = "select_";
    }

    // get keys and values
    Map reqMap = request.getParameterMap();
    Iterator iter = reqMap.entrySet().iterator();
    String[] keys = new String[reqMap.size()];
    String[] values = new String[reqMap.size()];
    while (iter.hasNext()) {
        Map.Entry element = (Map.Entry) iter.next();
        String key = (String) element.getKey();
        String value = ((String[]) element.getValue())[0];
        log.debug("Parsing request for: " + key + ", " + value);
        try {
            if (key.startsWith(prefix)) {
                String indexStr = key.substring(prefix.length());
                int index = Integer.parseInt(indexStr);
                log.debug("Adding " + value + " to values[" + index + "]");
                values[index] = value;
            } else {
                int index = Integer.parseInt(key);
                log.debug("Adding " + value + " to keys[" + index + "]");
                keys[index] = value;
            }
        } catch (NumberFormatException e) {
            // not an extractor related requestParameter
            log.debug("Skipping " + key + ", " + value);
        }
    }

    // add the key value pairs to Map, if key contains value
    Map props = new Properties();
    for (int i = 0; i < values.length; i++) {
        if (StringUtils.hasLength(keys[i])) {
            log.debug("Adding " + keys[i] + "," + values[i] + " to map");
            props.put(keys[i], values[i]);
        } else {
            log.debug("Skipping (remove) " + keys[i] + "," + values[i] + " to map");
        }
    }
    // set caseSensitivity before setting the map
    thisForm.setCaseSensitive(RequestUtils.getBooleanParameter(request, "casesensitive", false));
    // add the Map
    thisForm.setMappings(props);
    collectionManager.getArchiveHandler()
            .setCaseSensitive(RequestUtils.getBooleanParameter(request, "casesensitive", false));
    collectionManager.getArchiveHandler().setMappings(props);
    try {
        collectionManager.store();
    } catch (IndexException e) {
        throw new ServletException("Error storing new Search Defaults", e);
    }

    return new ModelAndView(getSuccessView());
}

From source file:org.jasypt.spring31.xml.encryption.EncryptablePropertyPlaceholderBeanDefinitionParser.java

@Override
protected void doParse(final Element element, final BeanDefinitionBuilder builder) {

    super.doParse(element, builder);

    builder.addPropertyValue("ignoreUnresolvablePlaceholders",
            Boolean.valueOf(element.getAttribute("ignore-unresolvable")));

    String systemPropertiesModeName = element.getAttribute("system-properties-mode");
    if (StringUtils.hasLength(systemPropertiesModeName)
            && !systemPropertiesModeName.equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) {
        builder.addPropertyValue("systemPropertiesModeName",
                "SYSTEM_PROPERTIES_MODE_" + systemPropertiesModeName);
    }/*www. ja v a2  s  . c  o  m*/

    final String encryptorBeanName = element.getAttribute(ENCRYPTOR_ATTRIBUTE);
    if (StringUtils.hasText(encryptorBeanName)) {
        builder.addConstructorArgReference(encryptorBeanName);
    }

}

From source file:com.taobao.diamond.server.service.NotifyService.java

String generateNotifyConfigInfoPath(String dataId, String group, String address) {
    String specialUrl = this.nodeProperties.getProperty(address);
    String urlString = PROTOCOL + address + URL_PREFIX;
    // urlurl/*from  w  ww . java  2 s . c  o m*/
    if (specialUrl != null && StringUtils.hasLength(specialUrl.trim())) {
        urlString = specialUrl;
    }
    urlString += "?method=notifyConfigInfo&dataId=" + dataId + "&group=" + group;
    return urlString;
}

From source file:com.example.securelogin.app.common.filter.InputValidationFilter.java

private void validate(String target, List<Character> prohibited) {
    if (StringUtils.hasLength(target)) {
        List<Character> chars = Chars.asList(target.toCharArray());
        for (Character prohibitedChar : prohibited) {
            if (chars.contains(prohibitedChar)) {
                throw new InvalidCharacterException("The request contains prohibited charcter.");
            }/*from   w  w w. j  a  va2 s . c  o  m*/
        }
    }
}

From source file:com.excilys.ebi.bank.util.Asserts.java

public static void hasLength(String text, String messagePattern, Object... args) {
    if (!StringUtils.hasLength(text)) {
        throw new IllegalArgumentException(MessageFormatter.arrayFormat(messagePattern, args).getMessage());
    }//  w w  w. ja  va 2  s  .  co  m
}