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:fr.xebia.management.statistics.ProfileAspect.java

public ObjectName getObjectName() throws MalformedObjectNameException {
    if (objectName == null) {
        String objectNameAsString = jmxDomain + ":type=ProfileAspect";
        if (StringUtils.hasLength(name)) {
            objectNameAsString += ",name=" + ObjectName.quote(name);
        }//  ww  w  . ja  v a 2 s.  c  o  m
        objectName = new ObjectName(objectNameAsString);
    }
    return objectName;
}

From source file:org.smf4j.spring.RegistryNodeTemplateDefinitionParser.java

protected String createNodeTemplateRef(ParserContext context, Element element) {
    String id = element.getAttribute(REF_ATTR);
    if (!StringUtils.hasLength(id)) {
        context.getReaderContext().error("<node-template> MUST must have a 'name'.",
                context.extractSource(element));
        return null;
    }/*from  www.  j av  a  2 s  .  com*/

    BeanDefinitionBuilder bdb = getBdb(RegistryNodeTemplateProxy.class);
    String newName = element.getAttribute(NAME_ATTR);
    if (StringUtils.hasLength(newName)) {
        bdb.addPropertyValue(NAME_ATTR, newName);
    }

    bdb.addPropertyReference(TEMPLATE_ATTR, id);
    return context.getReaderContext().registerWithGeneratedName(bdb.getBeanDefinition());
}

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

/**
 * ??/*from w w w  .  j a  va  2  s.  c o m*/
 *
 * @param pageNo
 * @param pageSize
 * @param group
 * @param dataId
 * @return
 */
public Page<ConfigInfo> findConfigInfo(final int pageNo, final int pageSize, final String group,
        final String dataId) {
    if (StringUtils.hasLength(dataId) && StringUtils.hasLength(group)) {
        ConfigInfo ConfigInfo = this.diamondConfigInfoDAO.findConfigInfo(dataId, group);
        Page<ConfigInfo> page = new Page<ConfigInfo>();
        if (ConfigInfo != null) {
            page.setPageNumber(1);
            page.setTotalCount(1);
            page.setPagesAvailable(1);
            page.getPageItems().add(ConfigInfo);
        }
        return page;
    } else if (StringUtils.hasLength(dataId) && !StringUtils.hasLength(group)) {
        ConfigInfo query = new ConfigInfo();
        query.setDataId(dataId);
        return this.diamondConfigInfoDAO.findAllConfigInfo(pageNo, pageSize, query);
    } else if (!StringUtils.hasLength(dataId) && StringUtils.hasLength(group)) {
        ConfigInfo query = new ConfigInfo();
        query.setGroup(group);
        return this.diamondConfigInfoDAO.findAllConfigInfo(pageNo, pageSize, query);
    } else {
        return this.diamondConfigInfoDAO.findAllConfigInfo(pageNo, pageSize, new ConfigInfo());
    }
}

From source file:edu.msstate.nsparc.spring.view.DynamicTilesViewProcessor.java

/**
 * Processes values to get tiles template definition name.  First 
 * a Tiles definition matching the url is checked, then a 
 * url specific template is checked, and then just the 
 * default root definition is used.// www .jav a2 s  . c o m
 * 
 * @throws    TilesException      If no valid Tiles definition is found. 
 */
protected String processTilesDefinitionName(String beanName, TilesContainer container,
        HttpServletRequest request, HttpServletResponse response) throws TilesException {
    // check for request parameter override.
    if (request.getParameter("template") != null
            && container.isValidDefinition(request.getParameter("template"), request, response)) {
        return request.getParameter("template");
    } else if (derivedDefinitionName != null) {
        // if definition already derived use it, otherwise 
        // check if url (bean name) is a template definition, then 
        // check for main template
        return derivedDefinitionName;
    } else if (container.isValidDefinition(beanName, request, response)) {
        derivedDefinitionName = beanName;

        return beanName;
    } else if (container.isValidDefinition("." + beanName.replace("/", "."), request, response)) {
        derivedDefinitionName = "." + beanName.replace("/", ".");
        return derivedDefinitionName;
    } else {
        String result = null;

        StringBuilder sb = new StringBuilder();
        int lastIndex = beanName.lastIndexOf("/");
        boolean rootDefinition = false;

        // if delim, tiles def will start with it
        if (StringUtils.hasLength(tilesDefinitionDelimiter)) {
            sb.append(tilesDefinitionDelimiter);
        }

        // if no '/', then at context root
        if (lastIndex == -1) {
            rootDefinition = true;
        } else {
            String path = (beanName != null ? beanName.substring(0, lastIndex) : "");

            if (StringUtils.hasLength(tilesDefinitionDelimiter)) {
                path = StringUtils.replace(path, "/", tilesDefinitionDelimiter);

            }

            sb.append(path);

            if (StringUtils.hasLength(tilesDefinitionDelimiter)) {
                sb.append(tilesDefinitionDelimiter);
            }
        }

        sb.append(tilesDefinitionName);

        if (container.isValidDefinition(sb.toString(), request, response)) {
            result = sb.toString();
        } else if (!rootDefinition) {
            String root = null;

            if (StringUtils.hasLength(tilesDefinitionDelimiter)) {
                root = tilesDefinitionDelimiter;
            }

            root += tilesDefinitionName;

            if (container.isValidDefinition(root, request, response)) {
                result = root;
            } else {
                throw new TilesException(
                        "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'");
            }
        }

        derivedDefinitionName = result;

        return result;
    }
}

From source file:com.xdtech.core.orm.utils.AssertUtils.java

/**
 * Assert that the given text does not contain the given substring.
 * <pre class="code">Assert.doesNotContain(name, "rod", "Name must not contain 'rod'");</pre>
 * @param textToSearch the text to search
 * @param substring the substring to find within the text
 * @param message the exception message to use if the assertion fails
 *///  ww  w. j  a  v  a2 s. c o  m
public static void doesNotContain(String textToSearch, String substring, String message) {
    if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring)
            && textToSearch.indexOf(substring) != -1) {
        throw new IllegalArgumentException(message);
    }
}

From source file:org.smf4j.spring.CsvFileBeanDefinitionParser.java

private String createLayout(Element element, ParserContext context, BeanDefinitionBuilder builder) {
    List<String> filters = new ArrayList<String>();
    List<Element> children = DomUtils.getChildElementsByTagName(element, FILTER_TAG);
    for (Element child : children) {
        String tmp = child.getAttribute(VALUE_ATTR);
        if (StringUtils.hasLength(tmp)) {
            filters.add(tmp);/*from   ww  w .  j  a v  a2  s.  c  o  m*/
        }
    }

    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(CSVFILELAYOUT_CLASS);
    bdb.addPropertyValue(FILTERS_ATTR, filters);
    return context.getReaderContext().registerWithGeneratedName(bdb.getBeanDefinition());
}

From source file:org.springmodules.validation.valang.ValangValidator.java

public void validate(Object target, Errors errors) {

    BeanWrapper beanWrapper = (target instanceof BeanWrapper) ? (BeanWrapper) target
            : new BeanWrapperImpl(target);

    if (getCustomPropertyEditors() != null) {
        for (Iterator iter = getCustomPropertyEditors().iterator(); iter.hasNext();) {
            CustomPropertyEditor customPropertyEditor = (CustomPropertyEditor) iter.next();

            if (customPropertyEditor.getRequiredType() == null) {
                throw new IllegalArgumentException(
                        "[requiredType] is required on CustomPropertyEditor instances!");
            } else if (customPropertyEditor.getPropertyEditor() == null) {
                throw new IllegalArgumentException(
                        "[propertyEditor] is required on CustomPropertyEditor instances!");
            }// w ww.  j  a v a2  s.co  m

            if (StringUtils.hasLength(customPropertyEditor.getPropertyPath())) {
                beanWrapper.registerCustomEditor(customPropertyEditor.getRequiredType(),
                        customPropertyEditor.getPropertyPath(), customPropertyEditor.getPropertyEditor());
            } else {
                beanWrapper.registerCustomEditor(customPropertyEditor.getRequiredType(),
                        customPropertyEditor.getPropertyEditor());
            }
        }
    }

    for (Iterator iter = rules.iterator(); iter.hasNext();) {
        ValidationRule rule = (ValidationRule) iter.next();
        rule.validate(beanWrapper, errors);
    }
}

From source file:com.insframework.common.spring.jdbc.mapper.BeanPropertyRowMapper.java

/**
 * Convert a name in camelCase to an underscored name in lower case.
 * Any upper case letters are converted to lower case with a preceding underscore.
 * @param name the string containing original name
 * @return the converted name//from   w  w  w  .j a  v a 2s . c  om
 */
private String underscoreName(String name) {
    if (!StringUtils.hasLength(name)) {
        return "";
    }
    StringBuilder result = new StringBuilder();
    result.append(name.substring(0, 1).toLowerCase());
    for (int i = 1; i < name.length(); i++) {
        String s = name.substring(i, i + 1);
        String slc = s.toLowerCase();
        if (!s.equals(slc)) {
            result.append("_").append(slc);
        } else {
            result.append(s);
        }
    }
    return result.toString();
}

From source file:uk.ac.gda.dls.client.views.ImageFileDisplayer.java

void openViewandSendImage(String filename) throws Exception {
    if (StringUtils.hasLength(filename)) {
        registerListener();//w w  w.  j  a va  2  s .c  o m
        if (showView == null) {
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

                        if (openViewAutomatically) {
                            showView = window.getActivePage().showView(viewID);
                        } else {
                            showView = window.getActivePage().findView(viewID);
                        }

                        if (isPlotView()) {

                            if (showView == null) {
                                plotView = null;
                            }

                            else if (!(showView instanceof PlotView))
                                throw new IllegalArgumentException(viewID + " is not a PlotView");
                            plotView = (PlotView) showView;
                        }

                        partVisible = (showView != null);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        sendIfVisible(filename);
    }
}

From source file:com.aestheticsw.jobkeywords.service.termextractor.impl.fivefilters.FiveFiltersClient.java

@PostConstruct
private Map<Pattern, String> initRegExMap() {
    if (StringUtils.hasLength(blacklistRegEx)) {
        blacklistPattern = Pattern.compile("\\W(" + blacklistRegEx + ")\\W");
    }//www.j  av a  2  s  . co m

    Map<Pattern, String> regExMap = new HashMap<>();

    regExMap.put(Pattern.compile("<font[^>]*>"), "");
    regExMap.put(Pattern.compile("</font>"), "");
    regExMap.put(Pattern.compile("<span[^>]*>"), "");
    regExMap.put(Pattern.compile("</span>"), "");
    regExMap.put(Pattern.compile("<ul[^>]*>"), "");
    regExMap.put(Pattern.compile("</ul>"), "");
    regExMap.put(Pattern.compile("<li[^>]*>"), " ");
    regExMap.put(Pattern.compile("</li>"), ". ");
    regExMap.put(Pattern.compile("<div[^>]*>"), " ");
    regExMap.put(Pattern.compile("</div>"), ". ");
    regExMap.put(Pattern.compile("<p>"), ". ");
    regExMap.put(Pattern.compile("<p [^>]*>"), ". ");
    regExMap.put(Pattern.compile("</p>"), ". ");
    regExMap.put(Pattern.compile("<br>"), " ");
    regExMap.put(Pattern.compile("<br [^>]*>"), " ");
    regExMap.put(Pattern.compile("<p/>"), " ");
    regExMap.put(Pattern.compile("<b>"), "");
    regExMap.put(Pattern.compile("<b [^>]*>"), "");
    regExMap.put(Pattern.compile("</b>"), "");
    regExMap.put(Pattern.compile("<em>"), "");
    regExMap.put(Pattern.compile("<em [^>]*>"), "");
    regExMap.put(Pattern.compile("</em>"), "");

    regExMap.put(Pattern.compile("&[^;]*;"), " ");
    regExMap.put(Pattern.compile("- "), " ");
    regExMap.put(Pattern.compile(""), " ");
    regExMap.put(Pattern.compile("\\(s\\)"), "");
    regExMap.put(Pattern.compile(""), ""); // wacky character

    regExMap.put(Pattern.compile("\\W"), " ");

    // <U+0091> and other characters that are common in the UK

    regExMap.put(Pattern.compile("[\\u0091\\u0092]"), "'");

    regExMap.put(Pattern.compile("[\\u0095]"), "");
    // regExMap.put(Pattern.compile(""), "");
    // regExMap.put(Pattern.compile(""), "");
    // regExMap.put(Pattern.compile(""), "");

    // remove accent characters that were separated from the associated character by
    // Normalize.normalize()
    regExMap.put(Pattern.compile("\\p{M}"), "");

    // Non-printable characters are not a significant problem in the US, UK or France
    // regExMap.put(Pattern.compile("[\\x00\\x08\\x0B\\x0C\\x0E-\\x1F]"), "");

    return regExMap;
}