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:elaborate.editor.resources.orm.wrappers.UserInput.java

public User getUser() {
    User user = (id == NULL_ID) ? new User() : UserService.instance().getUser(id);
    user.setUsername(StringUtils.defaultIfEmpty(username, ""))//
            .setEmail(StringUtils.defaultIfEmpty(email, ""))//
            .setFirstName(StringUtils.defaultIfEmpty(firstName, ""))//
            .setLastName(StringUtils.defaultIfEmpty(lastName, ""));

    if (StringUtils.isNotBlank(role)) {
        user.setRoleString(ElaborateRoles.getRolestringFor(role));
    }/*from ww w. jav a2  s  .c  om*/

    if (StringUtils.isNotBlank(password)) {
        user.setEncodedPassword(PasswordUtil.encode(password));
    }

    if (StringUtils.isNotBlank(firstName) || StringUtils.isNotBlank(lastName)) {
        user.setTitle(
                Joiner.on(", ").skipNulls().join(new String[] { user.getLastName(), user.getFirstName() }));
    } else {
        user.setTitle(user.getUsername().replaceAll("_", " "));
    }
    return user;
}

From source file:com.adobe.adobemarketingcloud.github.maven.scq.di.MojoConfiguration.java

public String getStringValue(String name, String defaultValue) {
    // a small hack to enable a test via Mojo without altering the configs
    if ("enabled".equals(name)) {
        return "true";
    }/*from  w w w . ja  v  a  2 s .  com*/

    return StringUtils.defaultIfEmpty(xmlConfigReader.getValue(name), defaultValue);
}

From source file:com.adobe.acs.tools.csv.impl.Parameters.java

public Parameters(SlingHttpServletRequest request) throws IOException {

    final RequestParameter charsetParam = request.getRequestParameter("charset");
    final RequestParameter delimiterParam = request.getRequestParameter("delimiter");
    final RequestParameter fileParam = request.getRequestParameter("file");
    final RequestParameter multiDelimiterParam = request.getRequestParameter("multiDelimiter");
    final RequestParameter separatorParam = request.getRequestParameter("separator");

    this.charset = DEFAULT_CHARSET;
    if (charsetParam != null) {
        this.charset = StringUtils.defaultIfEmpty(charsetParam.toString(), DEFAULT_CHARSET);
    }/* w  w  w  .ja  v a  2  s  .c o  m*/

    this.delimiter = null;
    if (delimiterParam != null && StringUtils.isNotBlank(delimiterParam.toString())) {
        this.delimiter = delimiterParam.toString().charAt(0);
    }

    this.separator = null;
    if (separatorParam != null && StringUtils.isNotBlank(separatorParam.toString())) {
        this.separator = separatorParam.toString().charAt(0);
    }

    this.multiDelimiter = "|";
    if (multiDelimiterParam != null && StringUtils.isNotBlank(multiDelimiterParam.toString())) {
        this.multiDelimiter = multiDelimiterParam.toString();
    }

    if (fileParam != null && fileParam.getInputStream() != null) {
        this.file = fileParam.getInputStream();
    }
}

From source file:com.gantzgulch.sharing.service.impl.StorageManagerImpl.java

@Override
public void storeFile(SharedFile sharedFile, InputStream inputStream) throws IOException {

    String onDiskFilename = StringUtils.defaultIfEmpty(sharedFile.getOnDiskFilename(),
            "sf_" + System.currentTimeMillis() + ".dat");
    sharedFile.setOnDiskFilename(onDiskFilename);

    File file = new File(filesStorageLocation, onDiskFilename);
    OutputStream outputStream = null;
    try {/*w  w w  .j a v  a2  s.  c  o  m*/
        outputStream = new FileOutputStream(file);
        IOUtils.copyLarge(inputStream, outputStream);
    } finally {
        IOUtils.closeQuietly(outputStream);
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:de.thischwa.pmcms.model.domain.pojo.Image.java

@Override
public String getDecorationString() {
    String deco = StringUtils.defaultIfEmpty(title, fileName);
    if (InitializationManager.isAdmin())
        deco = String.format("%s#%d", deco, getId());
    return deco;//from w  w  w  .  j av a  2s. c  o  m
}

From source file:com.cognifide.slice.api.injector.InjectorConfig.java

InjectorConfig(final InjectorRunner runner) {
    // we don't allow to change the module list after creating the configuration
    modules = Collections.unmodifiableList(new ArrayList<Module>(runner.getModules()));
    name = runner.getInjectorName();/* w  w w. j a v a2 s .c  o m*/
    applicationPath = StringUtils.defaultIfEmpty(runner.getApplicationPath(), DEFAULT_INJECTOR_PATH + name);
    parentName = runner.getParentName();
    basePackage = runner.getBasePackage();
    bundleFilter = runner.getBundleNameFilter();
    listener = runner;
}

From source file:ee.pri.rl.blog.web.page.common.EntryListPanel.java

public EntryListPanel(String id, String title, IModel<List<Entry>> model) {
    super(id);//from   ww  w.j  a va  2  s . co  m
    add(new Label("title", StringUtils.defaultIfEmpty(title, "")).setVisible(StringUtils.isNotEmpty(title)));
    add(new EntryListView("entries", model));
}

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

/**
 * @see org.springframework.web.portlet.mvc.SimpleFormController#onSubmitAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.Object, org.springframework.validation.BindException)
 */// w ww .  j  a v a2  s.  c o  m
@Override
protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command,
        BindException errors) throws Exception {
    final String targetParentPath = StringUtils.defaultIfEmpty(request.getParameter("folderPath"), null);

    //User edited bookmark
    final CollectionFolder commandBookmark = (CollectionFolder) command;

    //Get the BookmarkSet from the store
    final BookmarkSet bs = this.bookmarkSetRequestResolver.getBookmarkSet(request);

    //Ensure the created & modified dates are set correctly
    commandBookmark.setCreated(new Date());
    commandBookmark.setModified(commandBookmark.getCreated());

    final Folder targetParent;
    if (targetParentPath != null) {
        //Get the target parent folder
        final IdPathInfo targetParentPathInfo = FolderUtils.getEntryInfo(bs, targetParentPath);
        if (targetParentPathInfo == null || targetParentPathInfo.getTarget() == null) {
            throw new IllegalArgumentException("The specified parent Folder does not exist. BaseFolder='" + bs
                    + "' and idPath='" + targetParentPath + "'");
        }

        targetParent = (Folder) targetParentPathInfo.getTarget();
    } else {
        targetParent = bs;
    }

    final Map<Long, Entry> targetChildren = targetParent.getChildren();

    //Add the new bookmark to the target parent
    targetChildren.put(commandBookmark.getId(), commandBookmark);

    //Persist the changes to the BookmarkSet 
    this.bookmarkStore.storeBookmarkSet(bs);
}

From source file:ch.admin.suis.msghandler.servlet.CommandInterfaceConfiguration.java

/**
 * {@inheritDoc }//from w w w  .  j  a  v a2s  .  co  m
 */
@Override
public String toString() {
    return MessageFormat.format("host name: {0}; port number: {1}",
            StringUtils.defaultIfEmpty(host, ClientCommons.NOT_SPECIFIED),
            port == 0 ? ClientCommons.NOT_SPECIFIED : port);
}

From source file:com.hangum.tadpole.rdb.core.viewers.object.sub.rdb.table.TableDragListener.java

@Override
public void dragSetData(DragSourceEvent event) {
    IStructuredSelection iss = (IStructuredSelection) viewer.getSelection();
    if (!iss.isEmpty()) {

        StringBuffer sbData = new StringBuffer();
        sbData.append(userDB.getSeq() + PublicTadpoleDefine.DELIMITER);

        for (Object objTable : iss.toList()) {
            TableDAO td = (TableDAO) objTable;//iss.getFirstElement();
            String strSchemaName = StringUtils.defaultIfEmpty(td.getSchema_name(), " ");
            String strCommnet = StringUtils.defaultIfEmpty(td.getComment(), " ");

            sbData.append(//from   www  . ja v  a2 s  .  co m
                    strSchemaName + PublicTadpoleDefine.DELIMITER + td.getName() + PublicTadpoleDefine.DELIMITER
                            + strCommnet + PublicTadpoleDefine.DELIMITER + PublicTadpoleDefine.DELIMITER_DBL);
        }

        event.data = sbData.toString();
    }
}