Example usage for org.apache.commons.lang StringUtils defaultString

List of usage examples for org.apache.commons.lang StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultString.

Prototype

public static String defaultString(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is null, the value of defaultStr.

Usage

From source file:org.carewebframework.shell.designer.AddComponent.java

private Treeitem addTreeitem(PluginDefinition def, Treeitem other) {
    String category = other != null ? favoritesCategory : def.getCategory();

    if (StringUtils.isEmpty(category)) {
        if (UIElementPlugin.class.isAssignableFrom(def.getClazz())) {
            category = Labels.getLabel("cwf.shell.plugin.category._default");
        } else {/*w  ww.  jav  a 2s  . c  om*/
            return null;
        }
    }

    String path = category + (category.endsWith("\\") ? "" : "\\") + def.getName();
    boolean isFavorite = other != null || (favorites != null && favorites.contains(path));
    boolean disabled = def.isDisabled() || def.isForbidden();
    Treeitem item = TreeUtil.findNode(tree, path, true);
    item.setValue(def);
    item.setTooltiptext(StringUtils.defaultString(def.getDescription(), noDescriptionHint));

    if (disabled) {
        item.setDisabled(true);
    } else {
        item.getTreerow().addForward(Events.ON_DOUBLE_CLICK, btnOK, Events.ON_CLICK);
    }

    if (favorites != null) {
        Span image = new Span();
        image.setZclass("glyphicon");
        image.setStyle("float:left");
        Component cell = item.getTreerow().getFirstChild();
        cell.insertBefore(image, cell.getFirstChild());
        image.addForward(Events.ON_CLICK, item, ON_FAVORITE);
        item.addEventListener(ON_FAVORITE, other == null ? favoriteListener1 : favoriteListener2);

        if (isFavorite && other == null) {
            other = addTreeitem(def, item);
        }

        item.setAttribute("other", other);
        item.setAttribute("path", path);
        item.setAttribute("image", image);
        setFavoriteStatus(item, isFavorite);
    }
    return item;
}

From source file:org.carrot2.util.attribute.AttributeInfo.java

public AttributeInfo(String key, String className, String fieldName, String javaDoc, String label, String title,
        String description, String group, AttributeLevel level, AttributeInfo inheritFrom) {
    this.fieldName = fieldName;
    this.className = className;

    this.key = key;
    if (inheritFrom == null) {
        this.javaDoc = javaDoc;
        this.label = label;
        this.title = title;
        this.description = description;

        this.group = group;
        this.level = level;
    } else {/*w  ww.  j a  va 2 s.  c om*/
        this.javaDoc = StringUtils.defaultString(javaDoc, inheritFrom.javaDoc);
        this.label = StringUtils.defaultString(label, inheritFrom.label);
        this.title = StringUtils.defaultString(title, inheritFrom.title);
        this.description = StringUtils.defaultString(description, inheritFrom.description);

        this.group = StringUtils.defaultString(group, inheritFrom.group);
        this.level = (AttributeLevel) ObjectUtils.defaultIfNull(level, inheritFrom.level);
    }
}

From source file:org.dspace.app.webui.cris.web.tag.ResearcherTagLibraryFunctions.java

public static List<AllMonthsStatsDTO> getAllMonthsStats(Object object) throws ParseException {

    String[][] temp = (String[][]) object;
    List<AllMonthsStatsDTO> result = new LinkedList<AllMonthsStatsDTO>();

    Map<String, List<String>> tempMap = new LinkedHashMap<String, List<String>>();
    boolean foundit = false;
    int countIntegrityMonth = 12;
    /*//  www. j  a  v a2  s .  c  o m
     * for (int i = 0; i < temp.length; i++) {
     * 
     * String tempKey = temp[i][0]; String key = tempKey.substring(0, 4); if
     * (!tempMap.containsKey(key)) { tempMap.put(key, new
     * LinkedList<String>()); if (countIntegrityMonth > 0 &&
     * countIntegrityMonth != 12 && i > 0) { while (countIntegrityMonth !=
     * 0) { String check = temp[i - 1][0].substring(0, 4); List<String>
     * array = tempMap.get(check); array.add(0, null);
     * countIntegrityMonth--; } countIntegrityMonth = 12; } }
     * countIntegrityMonth--; List<String> array = tempMap.get(key);
     * array.add(temp[i][1]);
     * 
     * if (countIntegrityMonth > 0 && i == temp.length - 1) { while
     * (countIntegrityMonth != 0) { array.add(null); countIntegrityMonth--;
     * } } if (countIntegrityMonth == 0) { countIntegrityMonth = 12; } }
     */
    for (int i = 0; i < temp.length; i++) {
        String tempKey = temp[i][0];
        String year = tempKey.substring(0, 4);
        String month = tempKey.substring(5, 7);
        String key = Integer.parseInt(month) < 7 ? String.valueOf(Integer.parseInt(year) - 1) + "/" + year
                : year + "/" + String.valueOf(Integer.parseInt(year) + 1);
        if (!tempMap.containsKey(key)) {
            final ArrayList<String> list = new ArrayList<String>();
            for (int j = 0; j < countIntegrityMonth; j++)
                list.add(null);
            tempMap.put(key, list);
        }
        tempMap.get(key).set(Integer.parseInt(month) - 1, temp[i][1]);
    }

    for (String key : tempMap.keySet()) {
        AllMonthsStatsDTO dto = new AllMonthsStatsDTO();
        dto.setYear(key);
        Integer total = 0;
        List<String> tempToken = tempMap.get(key);
        for (String token : tempToken) {
            if (token != null && !token.isEmpty()) {
                Integer addendum = Integer.parseInt(token);
                total += addendum;
                if (addendum > 0) {
                    foundit = true;
                }
            }
        }
        if (foundit == true) {
            dto.setJan(StringUtils.defaultString(tempToken.get(0), "0"));
            dto.setFeb(StringUtils.defaultString(tempToken.get(1), "0"));
            dto.setMar(StringUtils.defaultString(tempToken.get(2), "0"));
            dto.setApr(StringUtils.defaultString(tempToken.get(3), "0"));
            dto.setMay(StringUtils.defaultString(tempToken.get(4), "0"));
            dto.setJun(StringUtils.defaultString(tempToken.get(5), "0"));
            dto.setJul(StringUtils.defaultString(tempToken.get(6), "0"));
            dto.setAug(StringUtils.defaultString(tempToken.get(7), "0"));
            dto.setSep(StringUtils.defaultString(tempToken.get(8), "0"));
            dto.setOct(StringUtils.defaultString(tempToken.get(9), "0"));
            dto.setNov(StringUtils.defaultString(tempToken.get(10), "0"));
            dto.setDec(StringUtils.defaultString(tempToken.get(11), "0"));
            dto.setTotal(total);
            result.add(dto);
        }
    }
    // Collections.sort(result);
    return result;
}

From source file:org.dspace.search.QueryArgs.java

/**
 * Constructs a HashMap with the keys field{1,2,3}, query{1,2,3} and
 * conjunction{1,2} taking the values from the passed-in argument
 * defaulting to ""./* w  w  w  . j a  v  a2  s. c om*/
 *
 * @param request the request-describing object to take the values from
 *
 * @return the created HashMap
 */
public Map<String, String> buildQueryMap(HttpServletRequest request) {
    Map<String, String> queryMap = new HashMap<String, String>();
    String numFieldStr = request.getParameter("num_search_field");
    // for backward compatibility
    if (numFieldStr == null) {
        numFieldStr = "3";
    }
    int numField = Integer.parseInt(numFieldStr);
    for (int i = 1; i < numField; i++) {
        String queryStr = "query" + i;
        String fieldStr = "field" + i;
        String conjunctionStr = "conjunction" + i;

        queryMap.put(queryStr, StringUtils.defaultString(request.getParameter(queryStr), ""));
        queryMap.put(fieldStr, StringUtils.defaultString(request.getParameter(fieldStr), "ANY"));
        queryMap.put(conjunctionStr, StringUtils.defaultString(request.getParameter(conjunctionStr), "AND"));
    }

    String queryStr = "query" + numField;
    String fieldStr = "field" + numField;
    queryMap.put(queryStr, StringUtils.defaultString(request.getParameter(queryStr), ""));
    queryMap.put(fieldStr, StringUtils.defaultString(request.getParameter(fieldStr), "ANY"));

    return (queryMap);
}

From source file:org.eclipse.jubula.client.core.persistence.Persistor.java

/**
 * //  w ww.  j  a v  a  2 s. c  o m
 * @param connectionInfo The information to use in initializing the 
 *                       factory. Must not be <code>null</code>.
 * @param username The username to use in initializing the factory.
 * @param password The password to use in initializing the factory.
 * @param url The connection URL to use in initializing the factory.
 * @return the created factory.
 */
private static EntityManagerFactory createEntityManagerFactory(DatabaseConnectionInfo connectionInfo,
        String username, String password, String url) {

    Validate.notNull(connectionInfo);

    // use the classloader for this bundle when initializing 
    // the EntityManagerFactory
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PersistenceUnitProperties.CLASSLOADER, Persistor.class.getClassLoader());
    properties.put(PersistenceUnitProperties.JDBC_DRIVER, connectionInfo.getDriverClassName());
    properties.put(PersistenceUnitProperties.JDBC_USER, username);
    properties.put(PersistenceUnitProperties.JDBC_PASSWORD, password);
    properties.put(PersistenceUnitProperties.JDBC_URL,
            StringUtils.defaultString(url, connectionInfo.getConnectionUrl()));
    properties.put(PersistenceUnitProperties.BATCH_WRITING, connectionInfo.getBatchWriting());
    String batchWritingSize = connectionInfo.getBatchWritingSize();
    if (batchWritingSize != null) {
        properties.put(PersistenceUnitProperties.BATCH_WRITING_SIZE, batchWritingSize);
    }
    return new PersistenceProvider().createEntityManagerFactory(DEFAULT_PU_NAME, properties);
}

From source file:org.eclipse.jubula.client.ui.rcp.search.query.KeywordQuery.java

/**
 * Add the given node to the result, if it has the matching type and
 * the name contains the search string./*from   w w w.  j a  v  a  2 s  .  c om*/
 * {@inheritDoc}
 */
protected boolean operate(INodePO node) {
    FieldName[] searchableFieldNames = getSearchOptions().getSearchableFieldNames();
    if (matchingSearchType(node)) {
        for (FieldName field : searchableFieldNames) {
            if (field.isSelected()) {
                try {
                    String fieldValue = StringUtils.defaultString(BeanUtils.getProperty(node, field.getName()),
                            StringConstants.EMPTY);
                    if (matchSearchString(fieldValue)) {
                        // found node with keyword and correct type
                        add(node);
                    }
                } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                    // ignore and continue
                }
            }
        }
    }
    return true;
}