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.excilys.ebi.utils.spring.log.logback.test.LogbackConfigurerTestExecutionListener.java

/**
 * If the supplied <code>location</code> is <code>null</code> or
 * <em>empty</em>, a default location will be
 * {@link #generateDefaultLocation(Class) generated} for the specified
 * {@link Class class} and the {@link #getResourceName resource file name} ;
 * otherwise, the supplied <code>location</code> will be
 * {@link #modifyLocation modified} if necessary and returned.
 * //from  w ww  . jav a 2  s  .c o m
 * @param clazz
 *            the class with which the location is associated: to be used
 *            when generating a default location
 * @param location
 *            the unmodified location to use for configuring logback (can be
 *            <code>null</code> or empty)
 * @return a logback config file location
 * @see #generateDefaultLocation
 * @see #modifyLocation
 */
public final String processLocation(Class<?> clazz, String location) {
    return (!StringUtils.hasLength(location)) ? generateDefaultLocation(clazz)
            : modifyLocation(clazz, location);
}

From source file:ch.sdi.core.impl.parser.CsvParser.java

/**
 * Parses the given input stream./*from  w ww  .ja  va2s.c  om*/
 * <p>
 *
 * @param aInputStream
 *        must not be null
 * @param aDelimiter
 *        must not be null
 * @param aEncoding
 *        The encoding to be used. If null or empty, the systems default encoding is used.
 * @return a list which contains a list for each found person. The inner list contains the found
 *         values for this person. The number and the order must correspond to the configured field
 *         name list (see
 *         in each line.
 * @throws SdiException
 */
public List<List<String>> parse(InputStream aInputStream, String aDelimiter, String aEncoding,
        List<RawDataFilterString> aFilters) throws SdiException {
    if (!StringUtils.hasLength(aDelimiter)) {
        throw new SdiException("Delimiter not set", SdiException.EXIT_CODE_CONFIG_ERROR);
    } // if myDelimiter == null

    try {
        myLog.debug("Using encoding " + aEncoding);

        BufferedReader br = new BufferedReader(
                !StringUtils.hasText(aEncoding) ? new InputStreamReader(aInputStream)
                        : new InputStreamReader(aInputStream, aEncoding));
        List<List<String>> result = new ArrayList<>();
        Collection<String> myLinesFiltered = new ArrayList<>();

        int lineNo = 0;
        String line;
        LineLoop: while ((line = br.readLine()) != null) {
            lineNo++;

            if (aFilters != null) {
                for (RawDataFilterString filter : aFilters) {
                    if (filter.isFiltered(line)) {
                        myLog.debug("Skipping commented line: " + line);
                        myLinesFiltered.add(line);
                        continue LineLoop;
                    }
                }
            }

            myLog.debug("Parsing line " + lineNo + ": " + line);

            List<String> list = new ArrayList<String>();
            Scanner sc = new Scanner(line);
            try {
                sc.useDelimiter(aDelimiter);
                while (sc.hasNext()) {
                    list.add(sc.next());
                }

                // Note: if the line is terminated by the delimiter (last entry not present, the last entry
                // will not appear in the scanned enumeration. Check for this special case:
                if (line.endsWith(aDelimiter)) {
                    list.add("");
                } // if line.endsWith( aDelimiter )
            } finally {
                sc.close();
            }

            result.add(list);
        }

        myLog.info(new ReportMsg(ReportMsg.ReportType.PREPARSE_FILTER, "Filtered lines", myLinesFiltered));

        return result;
    } catch (Throwable t) {
        throw new SdiException("Problems while parsing CSV file", t, SdiException.EXIT_CODE_PARSE_ERROR);
    }
}

From source file:ar.com.aleatoria.ue.rest.SimpleClientHttpResponse.java

public HttpHeaders getHeaders() {
    if (this.headers == null) {
        this.headers = new HttpHeaders();
        // Header field 0 is the status line for most HttpURLConnections, but not on GAE
        String name = this.connection.getHeaderFieldKey(0);
        if (StringUtils.hasLength(name)) {
            this.headers.add(name, this.connection.getHeaderField(0));
        }/*from   w ww  .  ja  v  a 2s  .c  om*/
        int i = 1;
        while (true) {
            name = this.connection.getHeaderFieldKey(i);
            if (!StringUtils.hasLength(name)) {
                break;
            }
            this.headers.add(name, this.connection.getHeaderField(i));
            i++;
        }
    }
    return this.headers;
}

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

private void parseTopLevelProperties(Element element, ParserContext context, BeanDefinitionBuilder builder) {
    String tmp;//from  w ww .ja  v a 2s. c om
    tmp = element.getAttribute(PATH_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(PATH_ATTR, tmp);
    }
    tmp = element.getAttribute(TIMESTAMP_COLUMN_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(TIMESTAMP_COLUMN_ATTR, tmp);
    }
    tmp = element.getAttribute(TIMESTAMP_COLUMN_HEADER_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(TIMESTAMP_COLUMN_HEADER_ATTR, tmp);
    }
    tmp = element.getAttribute(LINE_ENDING_ATTR);
    if (StringUtils.hasLength(tmp)) {
        String lineEnding = System.getProperty("line.separator");
        if (CR.equals(tmp)) {
            lineEnding = "\r";
        } else if (LF.equals(tmp)) {
            lineEnding = "\n";
        } else if (CRLF.equals(tmp)) {
            lineEnding = "\r\n";
        } else {
            context.getReaderContext().warning(
                    String.format("Unknown line ending '%s'.  Using system-default " + "instead.", tmp),
                    context.getReaderContext().extractSource(element));
        }
        builder.addPropertyValue(LINE_ENDING_ATTR, lineEnding);
    }
    tmp = element.getAttribute(APPEND_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(APPEND_ATTR, tmp);
    }
    tmp = element.getAttribute(DELIMETER_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(DELIMETER_ATTR, tmp);
    }
    tmp = element.getAttribute(QUOTE_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(QUOTE_ATTR, tmp);
    }
    tmp = element.getAttribute(CHARSET_ATTR);
    if (StringUtils.hasLength(tmp)) {
        boolean validCharset = false;
        try {
            validCharset = Charset.isSupported(tmp);
        } catch (IllegalCharsetNameException e) {
        }

        if (!validCharset) {
            String defaultCharset = Charset.defaultCharset().name();
            context.getReaderContext()
                    .warning(String.format(
                            "Unknown charset '%s'.  Using system-default charset " + "'%s' instead.", tmp,
                            defaultCharset), context.getReaderContext().extractSource(element));

        }
        builder.addPropertyValue(CHARSET_ATTR, tmp);
    }
    tmp = element.getAttribute(ROLLOVER_TIMESTAMP_PATTERN);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(ROLLOVER_TIMESTAMP_PATTERN, tmp);
    }
    tmp = element.getAttribute(COLUMN_TIMESTAMP_PATTERN);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(COLUMN_TIMESTAMP_PATTERN, tmp);
    }
    tmp = element.getAttribute(MAXSIZE_ATTR);
    if (StringUtils.hasLength(tmp)) {
        builder.addPropertyValue(MAXSIZE_ATTR, tmp);
    }

    tmp = element.getAttribute(DEPENDSON_ATTR);
    if (StringUtils.hasLength(tmp)) {
        for (String id : StringUtils.commaDelimitedListToSet(tmp)) {
            builder.addDependsOn(id);
        }
    } else {
        builder.addDependsOn(RegistrarBeanDefinitionParser.MASTER_REGISTRAR_ID);
    }
    builder.setLazyInit(false);
}

From source file:org.openmrs.module.appframework.api.impl.AppFrameworkServiceImpl.java

/**
 * @see org.openmrs.module.appframework.api.AppFrameworkService#getAppsForUser(org.openmrs.User)
 *//*from  www.j  ava 2 s .com*/
@Override
public List<AppDescriptor> getAppsForUser(User user) {
    Map<String, AppDescriptor> appMap = new HashMap<String, AppDescriptor>();
    for (AppDescriptor app : getAllApps()) {
        if (app.getRequiredPrivilegeName() == null || user.hasPrivilege(app.getRequiredPrivilegeName())) {
            appMap.put(app.getId(), app);
        }
    }

    // re-sort this list according to the "app_sort_order" user property
    String sortOrder = user.getUserProperty("app_sort_order");
    if (StringUtils.hasLength(sortOrder)) {
        List<AppDescriptor> ret = new ArrayList<AppDescriptor>();

        // loop over the sort order and add to new list in that order
        List<String> sortedIds = new ArrayList<String>();
        for (String id : sortOrder.split(",")) {
            AppDescriptor app = appMap.get(id);
            if (app != null) {
                ret.add(app);
                appMap.remove(id);
            }
        }

        // add all apps that weren't in the sort order for some reason
        ret.addAll(appMap.values());

        return ret;
    } else
        return new ArrayList<AppDescriptor>(appMap.values());

}

From source file:com.inspiresoftware.lib.dto.geda.interceptor.impl.TransferableUtils.java

private static void resolveConfigurationBefore(final Map<Occurrence, AdviceConfig> cfg, final String method,
        final Class[] args, final Class retArg, final Transferable ann) {

    if (args.length >= 2) {

        if (ann.before() == Direction.DTO_TO_ENTITY) {

            final boolean filtered = StringUtils.hasLength(ann.dtoFilterKey());
            final boolean firstArgIsCollection = argIsCollection(args[0]);
            final boolean secondArgIsCollection = argIsCollection(args[1]);

            if (filtered) {

                if (firstArgIsCollection && secondArgIsCollection) {
                    // public void toEntity(Class<DTO> dtoFilter, Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                    assertKey(method, ann.entityKey(), false);
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), ann.dtoFilterKey(),
                            "", ann.entityKey(), AdviceConfig.DTOSupportMode.DTOS_TO_ENTITIES_BY_FILTER, 0,
                            NO_INDEX, NO_INDEX, 1, ann.context());
                    return;
                } else if (!firstArgIsCollection && !secondArgIsCollection) {
                    // public void toEntity(Class<DTO> dtoFilter, DTO dto, Entity entity, ... )
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), ann.dtoFilterKey(),
                            "", "", AdviceConfig.DTOSupportMode.DTO_BY_FILTER_TO_ENTITY, 0, NO_INDEX, NO_INDEX,
                            1, ann.context());
                    return;
                }/*  ww  w .ja  v a  2s . com*/

            } else {

                if (firstArgIsCollection && secondArgIsCollection) {
                    // public void toEntity(Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                    assertKey(method, ann.entityKey(), false);
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), "", "",
                            ann.entityKey(), AdviceConfig.DTOSupportMode.DTOS_TO_ENTITIES, 0, NO_INDEX,
                            NO_INDEX, 1, ann.context());
                    return;
                } else if (!firstArgIsCollection && !secondArgIsCollection) {
                    // public void toEntity(DTO dto, Entity entity, ... )
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), "", "", "",
                            AdviceConfig.DTOSupportMode.DTO_TO_ENTITY, 0, NO_INDEX, NO_INDEX, 1, ann.context());
                    return;
                }

            }

        } else if (ann.before() == Direction.ENTITY_TO_DTO) {

            final boolean filtered = StringUtils.hasLength(ann.dtoFilterKey());
            final boolean firstArgIsCollection = argIsCollection(args[0]);
            final boolean secondArgIsCollection = argIsCollection(args[1]);

            if (filtered) {

                if (firstArgIsCollection && secondArgIsCollection) {
                    // public void toDto(Class<DTO> dtoFilter, Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                    assertKey(method, ann.dtoKey(), true);
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), ann.dtoFilterKey(),
                            ann.dtoKey(), "", AdviceConfig.DTOSupportMode.ENTITIES_TO_DTOS_BY_FILTER, NO_INDEX,
                            0, 1, NO_INDEX, ann.context());
                    return;
                } else if (!firstArgIsCollection && !secondArgIsCollection) {
                    // public void toDto(Class<DTO> dtoFilter, DTO dto, Entity entity, ... )
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), ann.dtoFilterKey(),
                            "", "", AdviceConfig.DTOSupportMode.ENTITY_TO_DTO_BY_FILTER, NO_INDEX, 0, 1,
                            NO_INDEX, ann.context());
                    return;
                }

            } else {

                if (firstArgIsCollection && secondArgIsCollection) {
                    // public void toDto(Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                    assertKey(method, ann.dtoKey(), true);
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), "", ann.dtoKey(),
                            "", AdviceConfig.DTOSupportMode.ENTITIES_TO_DTOS, NO_INDEX, 0, 1, NO_INDEX,
                            ann.context());
                    return;
                } else if (!firstArgIsCollection && !secondArgIsCollection) {
                    // public void toDto(DTO dto, Entity entity, ... )
                    addConfiguration(cfg, Occurrence.BEFORE_METHOD_INVOCATION, ann.before(), "", "", "",
                            AdviceConfig.DTOSupportMode.ENTITY_TO_DTO, NO_INDEX, 0, 1, NO_INDEX, ann.context());
                    return;
                }

            }

        }
    }

    throw new UnsupportedOperationException("Unsupported configuration see @Transferable.");

}

From source file:cn.bc.web.util.WebUtils.java

public static String wrapJSFunctionWithVar(String fnName, String varName) {
    if (!StringUtils.hasLength(varName))
        return "function(){return window['" + fnName + "'].apply(this,arguments);}";
    else/*from   w  ww .java 2 s  . c om*/
        return "function(){this.pvar='" + varName + "';return window['" + fnName + "'].apply(this,arguments);}";
}

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

/**
 * ?dataIdgroup??/*  ww  w . j  a  va2s .  c  o m*/
 * 
 * @param dataId
 * @param group
 * @return
 */
public ConfigInfo findConfigInfo(String dataId, String group) {
    if (!StringUtils.hasLength(dataId) || StringUtils.containsWhitespace(dataId))
        throw new IllegalArgumentException("dataId");

    if (!StringUtils.hasLength(group) || StringUtils.containsWhitespace(group))
        throw new IllegalArgumentException("group");
    return persistService.findConfigInfo(dataId, group);
}

From source file:ninja.eivind.hotsreplayuploader.window.nodes.BattleLobbyNode.java

private String getPlayerName(Player player) {
    String shortName = player.getShortName();
    if (!StringUtils.hasLength(shortName)) {
        return "AI Player";
    }/*w w w.j a v  a 2s  .c  om*/
    return shortName;
}