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.seitenbau.jenkins.plugins.dynamicparameter.config.DynamicParameterManagement.java

/**
 * Upload a script file to the class path directory.
 * @param request HTTP request/*  ww w .j a  va  2 s  .c o m*/
 * @return redirect to {@code index}
 * @throws Exception
 */
public HttpResponse doUploadFile(StaplerRequest request) throws Exception {
    checkWritePermission();

    String classPathDirectory = request.getSubmittedForm().getString("classPathDirectory");
    lastDirectory = classPathDirectory;

    classPathDirectory = StringUtils.defaultIfEmpty(classPathDirectory, DEFAULT_NAME);
    File directory = getRebasedFile(classPathDirectory);

    if (!directory.exists()) {
        directory.mkdirs();
    }

    FileItem fileItem = request.getFileItem("file");
    String fileName = Util.getFileName(fileItem.getName());
    if (!StringUtils.isEmpty(fileName)) {
        fileItem.write(new File(directory, fileName));
    }

    return redirectToIndex();
}

From source file:info.magnolia.templating.elements.ComponentElement.java

@Override
public void begin(Appendable out) throws IOException, RenderException {

    content = getPassedContent();/*from w ww  .j a  va  2 s  . c  om*/

    if (content == null) {
        throw new RenderException(
                "The 'content' or 'workspace' and 'path' attribute have to be set to render a component.");
    }

    if (isAdmin() && hasPermission(content)) {

        try {
            this.componentDefinition = templateDefinitionAssignment.getAssignedTemplateDefinition(content);
        } catch (RegistrationException e) {
            throw new RenderException("No template definition found for the current content", e);
        }

        final Messages messages = MessagesManager.getMessages(componentDefinition.getI18nBasename());

        if (isRenderEditbar()) {
            MarkupHelper helper = new MarkupHelper(out);

            helper.openComment("cms:component");

            helper.attribute(AreaDirective.CONTENT_ATTRIBUTE, getNodePath(content));

            if (content instanceof InheritanceNodeWrapper) {
                if (((InheritanceNodeWrapper) content).isInherited()) {
                    helper.attribute("inherited", "true");
                }
            }

            this.editable = resolveEditable();
            if (this.editable != null) {
                helper.attribute("editable", String.valueOf(this.editable));
            }

            if (StringUtils.isEmpty(dialog)) {
                dialog = resolveDialog();
            }
            helper.attribute("dialog", dialog);

            String label = StringUtils.defaultIfEmpty(componentDefinition.getTitle(),
                    componentDefinition.getName());
            helper.attribute("label", messages.getWithDefault(label, label));

            if (StringUtils.isNotEmpty(componentDefinition.getDescription())) {
                helper.attribute("description", componentDefinition.getDescription());
            }
            helper.append(" -->\n");
        }
    }

    // TODO not sure how to pass editable

    WebContext webContext = MgnlContext.getWebContext();
    webContext.push(webContext.getRequest(), webContext.getResponse());
    setAttributesInWebContext(contextAttributes, WebContext.LOCAL_SCOPE);

    try {
        if (componentDefinition != null) {
            renderingEngine.render(content, componentDefinition, new HashMap<String, Object>(),
                    new AppendableOnlyOutputProvider(out));
        } else {
            renderingEngine.render(content, new AppendableOnlyOutputProvider(out));
        }
    } finally {
        webContext.pop();
        webContext.setPageContext(null);
        restoreAttributesInWebContext(contextAttributes, WebContext.LOCAL_SCOPE);
    }
}

From source file:com.ning.maven.plugins.duplicatefinder.Exception.java

private boolean currentProjectDependencyMatches(Artifact artifact, Artifact projectArtifact) {
    VersionRange versionRange = projectArtifact.getVersionRange();
    ArtifactVersion version;/*w  w  w . j  a v a  2 s. co m*/

    try {
        if (artifact.getVersionRange() != null) {
            version = artifact.getSelectedVersion();
        } else {
            version = new DefaultArtifactVersion(artifact.getVersion());
        }
    } catch (OverConstrainedVersionException ex) {
        return false;
    }

    return StringUtils.equals(projectArtifact.getGroupId(), artifact.getGroupId())
            && StringUtils.equals(projectArtifact.getArtifactId(), artifact.getArtifactId())
            && StringUtils.equals(StringUtils.defaultIfEmpty(projectArtifact.getType(), "jar"),
                    StringUtils.defaultIfEmpty(artifact.getType(), "jar"))
            && StringUtils.equals(projectArtifact.getClassifier(), artifact.getClassifier())
            && ((versionRange != null && versionRange.containsVersion(version))
                    || artifact.getVersion().equals(projectArtifact.getVersion()));
}

From source file:com.gst.portfolio.note.domain.Note.java

public Map<String, Object> update(final JsonCommand command) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>(7);

    final String noteParamName = "note";
    if (command.isChangeInStringParameterNamed(noteParamName, this.note)) {
        final String newValue = command.stringValueOfParameterNamed(noteParamName);
        actualChanges.put(noteParamName, newValue);
        this.note = StringUtils.defaultIfEmpty(newValue, null);
    }//from  w  ww. jav  a2 s  .c o  m
    return actualChanges;
}

From source file:gtu._work.ui.LogAppendStartEndUI.java

private void executeBtnActionPerformed(ActionEvent evt) {
    try {//from w w  w  .j  a v  a2 s  .com
        String methodStart = StringUtils.defaultIfEmpty(methodStartText.getText(), "xxxxxxxxxxxxxxxxx");
        String methodEnd = StringUtils.defaultIfEmpty(methodEndText.getText(), "xxxxxxxxxxxxxxxxx");
        File file = JCommonUtil.filePathCheck(javaSrcFileText.getText(), "java", "java");
        boolean onOffControl = Boolean.parseBoolean((String) onOffDebugSwitchComboBox.getSelectedItem());
        LogAppendStartEnd test = new LogAppendStartEnd(methodStart, methodEnd, onOffControl);
        test.execute(file);
        JCommonUtil._jOptionPane_showMessageDialog_info("?:\n" + file);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:com.gst.portfolio.calendar.domain.Calendar.java

public Calendar(final String title, final String description, final String location, final LocalDate startDate,
        final LocalDate endDate, final Integer duration, final Integer typeId, final boolean repeating,
        final String recurrence, final Integer remindById, final Integer firstReminder,
        final Integer secondReminder, final Date meetingtime) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(CALENDAR_RESOURCE_NAME);

    final CalendarType calendarType = CalendarType.fromInt(typeId);
    if (calendarType.isCollection() && !repeating) {
        baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue())
                .failWithCodeNoParameterAddedToErrorCode("must.repeat.for.collection.calendar");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*  w w w.  j a va  2  s  . c  o m*/
    }

    this.title = StringUtils.defaultIfEmpty(title, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
    this.location = StringUtils.defaultIfEmpty(location, null);

    if (null != startDate) {
        this.startDate = startDate.toDateTimeAtStartOfDay().toDate();
    } else {
        this.startDate = null;
    }

    if (null != endDate) {
        this.endDate = endDate.toDateTimeAtStartOfDay().toDate();
    } else {
        this.endDate = null;
    }

    this.duration = duration;
    this.typeId = typeId;
    this.repeating = repeating;
    this.recurrence = StringUtils.defaultIfEmpty(recurrence, null);
    this.remindById = remindById;
    this.firstReminder = firstReminder;
    this.secondReminder = secondReminder;
    this.meetingtime = meetingtime;
}

From source file:com.gst.infrastructure.dataqueries.domain.Report.java

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

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

    String paramName = "reportName";
    if (command.isChangeInStringParameterNamed(paramName, this.reportName)) {
        final String newValue = command.stringValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.reportName = StringUtils.defaultIfEmpty(newValue, null);
    }//from   w ww.  ja va 2s.c o  m
    paramName = "reportType";
    if (command.isChangeInStringParameterNamed(paramName, this.reportType)) {
        final String newValue = command.stringValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.reportType = StringUtils.defaultIfEmpty(newValue, null);
    }
    paramName = "reportSubType";
    if (command.isChangeInStringParameterNamed(paramName, this.reportSubType)) {
        final String newValue = command.stringValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.reportSubType = StringUtils.defaultIfEmpty(newValue, null);
    }
    paramName = "reportCategory";
    if (command.isChangeInStringParameterNamed(paramName, this.reportCategory)) {
        final String newValue = command.stringValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.reportCategory = StringUtils.defaultIfEmpty(newValue, null);
    }
    paramName = "description";
    if (command.isChangeInStringParameterNamed(paramName, this.description)) {
        final String newValue = command.stringValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.description = StringUtils.defaultIfEmpty(newValue, null);
    }
    paramName = "useReport";
    if (command.isChangeInBooleanParameterNamed(paramName, this.useReport)) {
        final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.useReport = newValue;
    }
    paramName = "reportSql";
    if (command.isChangeInStringParameterNamed(paramName, this.reportSql)) {
        final String newValue = command.stringValueOfParameterNamed(paramName);
        actualChanges.put(paramName, newValue);
        this.reportSql = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String reportParametersParamName = "reportParameters";
    if (command.hasParameter(reportParametersParamName)) {
        final JsonArray jsonArray = command.arrayOfParameterNamed(reportParametersParamName);
        if (jsonArray != null) {
            actualChanges.put(reportParametersParamName, command.jsonFragment(reportParametersParamName));
        }
    }

    validate(reportTypes);

    if (!actualChanges.isEmpty()) {
        if (isCoreReport()) {
            for (final String key : actualChanges.keySet()) {
                if (!(key.equals("useReport"))) {
                    throw new PlatformDataIntegrityException(
                            "error.msg.only.use.report.can.be.updated.for.core.report",
                            "Only the Use Report field can be updated for Core Reports", key);
                }
            }
        }
    }

    return actualChanges;
}

From source file:com.jayway.maven.plugins.android.phase04processclasses.DexMojo.java

/**
 * Makes sure the string ends with "/"/*from www.j  av a 2  s. c o  m*/
 * @param prefix any string, or null.
 * @return the prefix with a "/" at the end, never null.
 */
protected String endWithSlash(String prefix) {
    prefix = StringUtils.defaultIfEmpty(prefix, "/");
    if (!prefix.endsWith("/")) {
        prefix = prefix + "/";
    }
    return prefix;
}

From source file:com.adobe.acs.commons.http.injectors.AbstractHtmlRequestInjector.java

@SuppressWarnings("squid:S1149")
protected final void registerAsFilter(ComponentContext ctx, int ranking, String pattern) {
    Dictionary<String, String> filterProps = new Hashtable<String, String>();

    filterProps.put("service.ranking", String.valueOf(ranking));
    filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX,
            StringUtils.defaultIfEmpty(pattern, ".*"));
    filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
            "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)");
    filterRegistration = ctx.getBundleContext().registerService(Filter.class.getName(), this, filterProps);
}

From source file:com.gst.accounting.journalentry.domain.JournalEntry.java

public JournalEntry(final Office office, final PaymentDetail paymentDetail, final GLAccount glAccount,
        final String currencyCode, final String transactionId, final boolean manualEntry,
        final Date transactionDate, final Integer type, final BigDecimal amount, final String description,
        final Integer entityType, final Long entityId, final String referenceNumber,
        final LoanTransaction loanTransaction, final SavingsAccountTransaction savingsTransaction,
        final ClientTransaction clientTransaction, final Long shareTransactionId) {
    this.office = office;
    this.glAccount = glAccount;
    this.reversalJournalEntry = null;
    this.transactionId = transactionId;
    this.reversed = false;
    this.manualEntry = manualEntry;
    this.transactionDate = transactionDate;
    this.type = type;
    this.amount = amount;
    this.description = StringUtils.defaultIfEmpty(description, null);
    this.entityType = entityType;
    this.entityId = entityId;
    this.referenceNumber = referenceNumber;
    this.currencyCode = currencyCode;
    this.loanTransaction = loanTransaction;
    this.savingsTransaction = savingsTransaction;
    this.clientTransaction = clientTransaction;
    this.paymentDetail = paymentDetail;
    this.shareTransactionId = shareTransactionId;
}