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

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

Introduction

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

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

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

Usage

From source file:com.manydesigns.portofino.actions.admin.database.forms.ConnectionProviderForm.java

public void setTrueString(String trueString) {
    database.setTrueString(StringUtils.defaultIfEmpty(trueString, null));
}

From source file:com.autentia.tnt.tracking.TrackChanges.java

public EntityChange getEntityChange(String field, String oldValue, String newValue, String keyAux) {
    if (this.isTrackingActive()) {
        if (!StringUtils.equals(oldValue, newValue)) {
            final EntityChange change = new EntityChange();
            change.setField(field);//from  w  w w .ja  v  a  2  s .  c  o  m
            change.setOldValue(oldValue);
            change.setNewValue(newValue);
            change.setEntityName(dto.getClass().getCanonicalName());
            change.setEntityId(dto.getId());
            change.setUser(AuthenticationManager.getDefault().getCurrentPrincipal().getUser());
            change.setInsertDate(new Date());
            change.setAuxKey(StringUtils.defaultIfEmpty(keyAux, ""));
            return change;
        }
    }
    return null;
}

From source file:com.chenq.aspose.generator.BaseGenerator.java

protected Document replaceDocTem(Map<String, Object> datas, Document doc) {
    try {/*from   ww  w  . j a v a 2 s.  c  om*/
        if (doc == null) {
            doc = new Document(getTemplatePath());
        }
        // ????
        Iterator<String> keys = datas.keySet().iterator();
        while (keys.hasNext()) {
            String key = keys.next();
            String value = String.valueOf(datas.get(key));
            value = StringUtils.defaultIfEmpty(value, "").replaceAll("\n\n", "" + (char) 11);//??
            // ????
            doc.getRange().replace(wrap(key), value, true, false);
        }
    } catch (Exception e) {
        logger.warn("??", e);
    }

    return doc;
}

From source file:edu.wisc.my.portlets.bookmarks.web.DeleteEntryFormController.java

/**
 * @see org.springframework.web.portlet.mvc.AbstractController#handleActionRequestInternal(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
 *///www. jav a 2 s. c  o  m
@Override
protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
    final String entryIndex = StringUtils.defaultIfEmpty(request.getParameter("entryIndex"), null);

    //Get the BookmarkSet from the store
    final BookmarkSet bs = this.bookmarkSetRequestResolver.getBookmarkSet(request, false);
    if (bs == null) {
        throw new IllegalArgumentException("No BookmarkSet exists for request='" + request + "'");
    }

    final IdPathInfo targetEntryPathInfo = FolderUtils.getEntryInfo(bs, entryIndex);
    if (targetEntryPathInfo != null && targetEntryPathInfo.getTarget() != null) {
        final Folder parentFolder = targetEntryPathInfo.getParent();
        if (parentFolder != null) {
            final Map<Long, Entry> children = parentFolder.getChildren();
            final Entry target = targetEntryPathInfo.getTarget();
            children.remove(target.getId());

            //Persist the changes to the BookmarkSet 
            this.bookmarkStore.storeBookmarkSet(bs);
        } else {
            //Deleting the root bookmark
            this.bookmarkStore.removeBookmarkSet(bs.getOwner(), bs.getName());
        }
    } else {
        this.logger.warn("No IdPathInfo found for BaseFolder='" + bs + "' and idPath='" + entryIndex + "'");
    }

    //Go back to view bookmarks
    response.setRenderParameter("action", "viewBookmarks");
}

From source file:com.adaptris.core.services.EmbeddedScriptingService.java

@Override
protected Reader createReader() {
    return new StringReader(StringUtils.defaultIfEmpty(getScript(), ""));
}

From source file:com.adobe.acs.commons.users.impl.ServiceUser.java

public ServiceUser(Map<String, Object> config) throws EnsureServiceUserException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, PATH_SYSTEM_USERS);
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(PATH_SYSTEM_USERS,
                StringUtils.removeEnd(tmp, this.principalName));
    } else {// w ww.j  a va2  s.c om
        this.principalName = tmp;
        this.intermediatePath = "/home/users/system";
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureServiceUserException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedSystemUsers.isProtected(this.principalName)) {
        throw new EnsureServiceUserException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        try {
            aces.add(new Ace(entry));
        } catch (EnsureServiceUserException e) {
            log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                    + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
        }
    }
}

From source file:com.cognifide.aemrules.extensions.RulesLoader.java

private RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo,
        Class<? extends JavaCheck> clazz, Rule ruleAnnotation) {
    String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
    String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
    String description = StringUtils.defaultIfEmpty(getDescriptionFromResources(ruleKey),
            "No description yet.");

    RulesDefinition.NewRule rule = repo.createRule(ruleKey);
    rule.setName(ruleName).setMarkdownDescription(description);
    rule.setSeverity(ruleAnnotation.priority().name());
    rule.setStatus(RuleStatus.valueOf(ruleAnnotation.status()));
    rule.setTags(ruleAnnotation.tags());

    List<Field> fields = FieldUtils2.getFields(clazz, true);
    for (Field field : fields) {
        loadParameters(rule, field);//from ww w  .jav a  2 s .c o m
    }

    return rule;
}

From source file:com.flexive.faces.beans.BrowseReferencesBean.java

/**
 * {@inheritDoc}//from  www. j ava2s .c o m
 */
@Override
public String getParseRequestParameters() {
    setXPath(StringUtils.defaultIfEmpty(FxJsfUtils.getParameter("xPath"), xPath));
    setInputName(StringUtils.defaultIfEmpty(FxJsfUtils.getParameter("inputName"), inputName));
    setFormName(StringUtils.defaultIfEmpty(FxJsfUtils.getParameter("formName"), formName));
    return null;
}

From source file:com.gst.infrastructure.codes.domain.Code.java

public Map<String, Object> update(final JsonCommand command) {

    if (this.systemDefined) {
        throw new SystemDefinedCodeCannotBeChangedException();
    }//from   w  w w  .j a v a  2s .c  o  m

    final Map<String, Object> actualChanges = new LinkedHashMap<>(1);

    final String firstnameParamName = "name";
    if (command.isChangeInStringParameterNamed(firstnameParamName, this.name)) {
        final String newValue = command.stringValueOfParameterNamed(firstnameParamName);
        actualChanges.put(firstnameParamName, newValue);
        this.name = StringUtils.defaultIfEmpty(newValue, null);
    }

    return actualChanges;
}

From source file:com.adaptris.core.MetadataDestination.java

/**
 * <p>//  w  ww .  j  a v  a2 s .c  o m
 * Creates a new <code>ProduceDestination</code> by concatenating
 * the values of configurable metadata from the <code>AdaptrisMessage</code>.
 * </p>
 * @param msg the message to process
 * @return the <code>String</code> destination name
 * @throws CoreException wrapping any underlying <code>Exception</code>s
 */
public String getDestination(AdaptrisMessage msg) throws CoreException {

    String destinationName = "";
    for (String key : keys) {
        destinationName += StringUtils.defaultIfEmpty(msg.getMetadataValue(key), "");
    }
    destinationName = StringUtils.defaultIfEmpty(destinationName, null);
    log.debug("dynamic destination [{}]", destinationName);
    return destinationName;
}