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:edu.wisc.my.portlets.bookmarks.web.EditFolderFormController.java

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

    //User edited bookmark
    final Folder commandFolder = (Folder) command;

    //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 + "'");
    }

    //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 + "'");
    }

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

    //Get the original bookmark & it's parent folder
    final IdPathInfo originalBookmarkPathInfo = FolderUtils.getEntryInfo(bs, targetEntryPath);
    if (targetParentPathInfo == null || originalBookmarkPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified Folder does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetEntryPath + "'");
    }

    final Folder originalParent = originalBookmarkPathInfo.getParent();
    final Folder orignalFolder = (Folder) originalBookmarkPathInfo.getTarget();

    //If moving the bookmark
    if (targetParent.getId() != originalParent.getId()) {
        final Map<Long, Entry> originalChildren = originalParent.getChildren();
        originalChildren.remove(orignalFolder.getId());

        commandFolder.setCreated(orignalFolder.getCreated());
        commandFolder.setModified(new Date());
        commandFolder.setChildren(orignalFolder.getChildren());

        //Hibernate doesn't let us move already persisted objects, need to clone the tree to allow for the object to be re-added
        final Folder clonedCommandFolder = FolderUtils.deepCloneFolder(commandFolder, false);

        targetChildren.put(clonedCommandFolder.getId(), clonedCommandFolder);
    }
    //If just updaing the bookmark
    //TODO should the formBackingObject be smarter on form submits for editBookmark and return the targeted bookmark?
    else {
        orignalFolder.setModified(new Date());
        orignalFolder.setName(commandFolder.getName());
        orignalFolder.setNote(commandFolder.getNote());
    }

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

From source file:ch.admin.suis.msghandler.checker.StatusCheckerConfiguration.java

/**
 * {@inheritDoc }//from ww w.  j  a  va 2 s .  co  m
 */
@Override
public String toString() {
    final StringBuilder boxes = new StringBuilder();
    for (Iterator<ReceiptsFolder> i = receiptsFolders.iterator(); i.hasNext();) {
        boxes.append("\n\t").append(i.next().toString());
    }

    return MessageFormat.format("cron expression: {0}, folders: {1}", getCron(),
            StringUtils.defaultIfEmpty(boxes.toString(), ClientCommons.NOT_SPECIFIED));
}

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

/**
 * @see org.springframework.web.portlet.mvc.SimpleFormController#onSubmitAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.Object, org.springframework.validation.BindException)
 *///from w w  w  .  ja v  a2s  .  co m
@Override
protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command,
        BindException errors) throws Exception {
    final String targetParentPath = StringUtils.defaultIfEmpty(request.getParameter("folderPath"), null);
    final String targetEntryPath = StringUtils.defaultIfEmpty(request.getParameter("idPath"), null);

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

    //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 + "'");
    }

    //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 + "'");
    }

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

    //Get the original bookmark & it's parent folder
    final IdPathInfo originalBookmarkPathInfo = FolderUtils.getEntryInfo(bs, targetEntryPath);
    if (targetParentPathInfo == null || originalBookmarkPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified Bookmark does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetEntryPath + "'");
    }

    final Folder originalParent = originalBookmarkPathInfo.getParent();
    final Bookmark originalBookmark = (Bookmark) originalBookmarkPathInfo.getTarget();

    //If moving the bookmark
    if (targetParent.getId() != originalParent.getId()) {
        final Map<Long, Entry> originalChildren = originalParent.getChildren();
        originalChildren.remove(originalBookmark.getId());

        commandBookmark.setCreated(originalBookmark.getCreated());
        commandBookmark.setModified(new Date());

        targetChildren.put(commandBookmark.getId(), commandBookmark);
    }
    //If just updaing the bookmark
    //TODO should the formBackingObject be smarter on form submits for editBookmark and return the targeted bookmark?
    else {
        originalBookmark.setModified(new Date());
        originalBookmark.setName(commandBookmark.getName());
        originalBookmark.setNote(commandBookmark.getNote());
        originalBookmark.setUrl(commandBookmark.getUrl());
        originalBookmark.setNewWindow(commandBookmark.isNewWindow());
    }

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

From source file:com.flexive.core.search.cmis.model.NumericValueFunction.java

public NumericValueFunction(String function, String alias) {
    super(resolveFunction(function), StringUtils.defaultIfEmpty(alias,
            Functions.SCORE.equals(resolveFunction(function)) ? "SEARCH_SCORE" : function));
}

From source file:net.ageto.gyrex.impex.common.steps.impl.filename.FirstFilenameInAlphabeticalOrder.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w.  j a  va2s.  c  om
protected StatusStep process() {

    // file path
    String filepath = (String) getInputParam(
            FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_FILEPATH.name());

    // file extensions
    ArrayList<String> fileExtension = (ArrayList<String>) getInputParam(
            FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_FILE_EXTENSION_FILTER.name());

    String[] fileExtensionsArray = fileExtension == null ? null : (String[]) fileExtension.toArray();

    // recursive, include subdirectories
    Boolean recursive = (Boolean) getInputParam(
            FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_INCLUDE_SUBDIRECTORIES.name());

    // all files from the given file path
    Collection<File> listFiles = FileUtils.listFiles(new File(filepath), fileExtensionsArray,
            BooleanUtils.toBoolean(recursive));

    if (listFiles.size() == 0) {
        processWarn("No file was found in folder \"{0}\" with file extension \"{1}\".", filepath,
                StringUtils.defaultIfEmpty(StringUtils.join(fileExtensionsArray, " "), "*"));
        // cancel process
        return StatusStep.CANCEL;
    }

    // fetch first file (alphabetical order)
    for (File file : listFiles) {
        setOutputParam(FirstFilenameInAlphabeticalOrderDefinition.OutputParamNames.OUTPUT_FILENAME.name(),
                file.getAbsolutePath());
        processInfo("File \"{0}\" was found in folder \"{1}\" with file extension \"{2}\".",
                file.getAbsolutePath(), filepath,
                StringUtils.defaultIfEmpty(StringUtils.join(fileExtensionsArray, " "), "*"));
        break;
    }

    processInfo("{0} has been completed successfully.", ID);

    return StatusStep.OK;
}

From source file:com.bstek.dorado.view.output.ClientEventListenersOutputter.java

protected void outputListener(ClientEvent listener, OutputContext context) throws IOException {
    JsonBuilder json = context.getJsonBuilder();
    Writer writer = context.getWriter();
    String signature;//from   w  w  w.ja  v a  2s  .  c  o  m
    if (listener instanceof DynaSignatureClientEvent) {
        signature = StringUtils.defaultIfEmpty(((DynaSignatureClientEvent) listener).getSignature(),
                DEFAULT_SIGNATURE);
    } else {
        signature = DEFAULT_SIGNATURE;
    }

    if (DEFAULT_SIGNATURE.equals(signature)) {
        json.beginValue();
        writer.append("function(").append(signature).append("){\n").append(listener.getScript()).append("\n}");
        json.endValue();
    } else {
        json.object().key("fn").beginValue();
        writer.append("function(").append(signature).append("){\n").append(listener.getScript()).append("\n}");
        json.endValue();
        json.key("options").object().key("autowire").value(true).endObject();
        json.endObject();
    }
}

From source file:com.manydesigns.portofino.actions.admin.tables.forms.TableForm.java

@Insertable(false)
@Updatable(false)
public String getHqlQuery() {
    return "from " + StringUtils.defaultIfEmpty(entityName, actualEntityName);
}

From source file:com.gst.portfolio.collateral.domain.LoanCollateral.java

private LoanCollateral(final Loan loan, final CodeValue collateralType, final BigDecimal value,
        final String description) {
    this.loan = loan;
    this.type = collateralType;
    this.value = value;
    this.description = StringUtils.defaultIfEmpty(description, null);
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.SessionManager.java

public void init(Router router) {
    cookieName = StringUtils.defaultIfEmpty(cookieName, "SESSIONID");
    timeout = timeout == 0 ? 300000 : timeout;
}

From source file:com.gst.portfolio.paymenttype.domain.PaymentType.java

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

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

    if (command.isChangeInStringParameterNamed(PaymentTypeApiResourceConstants.NAME, this.name)) {
        final String newValue = command.stringValueOfParameterNamed(PaymentTypeApiResourceConstants.NAME);
        actualChanges.put(PaymentTypeApiResourceConstants.NAME, newValue);
        this.name = StringUtils.defaultIfEmpty(newValue, null);
    }/*from  w  w w  .  java 2s.c  om*/

    if (command.isChangeInStringParameterNamed(PaymentTypeApiResourceConstants.DESCRIPTION, this.description)) {
        final String newDescription = command
                .stringValueOfParameterNamed(PaymentTypeApiResourceConstants.DESCRIPTION);
        actualChanges.put(PaymentTypeApiResourceConstants.DESCRIPTION, newDescription);
        this.description = StringUtils.defaultIfEmpty(newDescription, null);
    }

    if (command.isChangeInBooleanParameterNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT,
            this.isCashPayment)) {
        final Boolean newCashPaymentType = command
                .booleanObjectValueOfParameterNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT);
        actualChanges.put(PaymentTypeApiResourceConstants.ISCASHPAYMENT, newCashPaymentType);
        this.isCashPayment = newCashPaymentType.booleanValue();
    }

    if (command.isChangeInLongParameterNamed(PaymentTypeApiResourceConstants.POSITION, this.position)) {
        final Long newPosition = command.longValueOfParameterNamed(PaymentTypeApiResourceConstants.POSITION);
        actualChanges.put(PaymentTypeApiResourceConstants.POSITION, newPosition);
        this.position = newPosition;
    }

    return actualChanges;
}