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:de.fhg.iais.asc.oai.strategy.AbstractHarvester.java

/**
 * @param uri The repository url.// ww w .j  a  va 2 s .  c o m
 * @param metadataPrefix The metadata prefix to harvest.
 * @param proxyHost
 * @param proxyPort
 * @param fromDateParameter
 * @param untilDateParameter
 * @param config The current ASC configuration, non-<code>null</code>.
 * @param ascState the state object to report the progress, non-<code>null</code>.
 * @param ingestEvent The ingest event in which the harvesting takes place, non-<code>null</code>.
 */
public AbstractHarvester(String uri, String metadataPrefix, String proxyHost, Integer proxyPort,
        String fromDateParameter, String untilDateParameter, AscConfiguration config, ASCState ascState,
        AscProviderIngest ingestEvent) {

    Check.notNull(config, "config must be non-null");
    Check.notNull(ascState, "ascState must be non-null");
    Check.notNull(ingestEvent, "ingestEvent must be non-null");

    this.uri = uri;
    this.metadataPrefix = metadataPrefix;

    this.fromDate = StringUtils.defaultIfEmpty(fromDateParameter, null);
    this.untilDate = StringUtils.defaultIfEmpty(untilDateParameter, null);

    int connectionTimeout = config.get(AscConfiguration.HARVESTING_CONNECTION_TIMEOUT, 600000);
    LOG.info("set connection and socket timeouts to approx. " + (connectionTimeout / 1000) + " seconds"); // request from a.schenk DDB-724

    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(httpParams, connectionTimeout);
    HttpClient client = new DefaultHttpClient(httpParams);

    // set some parameters that might help but will not harm
    // see: http://hc.apache.org/httpclient-legacy/preference-api.html

    // the user-agent:
    // tell them who we are (they see that from the IP anyway), thats a good habit,
    // shows that we are professional and not some script kiddies
    // and this is also a little bit of viral marketing :-)
    client.getParams().setParameter("http.useragent", "myCortex Harvester; http://www.iais.fraunhofer.de/");
    // the following option "can result in noticeable performance improvement" (see api docs)
    // it may switch on a keep-alive, may reduce load on server side (if they are smart)
    // and might reduce latency
    client.getParams().setParameter("http.protocol.expect-continue", true);

    // ignore all cookies because some OAI-PMH implementations don't know how to handle cookies
    client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);

    // setting of the proxy if needed
    if (proxyHost != null && !proxyHost.isEmpty()) {
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    this.server = new OaiPmhServer(client, this.uri);

    this.config = config;
    this.ascState = ascState;
    this.ingestEvent = ingestEvent;
}

From source file:info.magnolia.cms.gui.controlx.list.ListControl.java

/**
 * @see info.magnolia.cms.gui.controlx.list.ListModel#getGroupByOrder()
 */// ww  w. java  2 s  .c  o m
public String getGroupByOrder() {
    return StringUtils.defaultIfEmpty(this.model.getGroupByOrder(), "asc");
}

From source file:ch.admin.suis.msghandler.common.ReceiptsFolder.java

@Override
public String toString() {
    return MessageFormat.format(
            "name: {0}; types of the checked messages: {1}; sedex ID of the participant: {2};",
            //        StringUtils.defaultIfEmpty(getDirectory(), ClientCommons.NOT_SPECIFIED),
            getDirectory(),//from  w ww  .  j a v  a2  s .c  o m
            StringUtils.defaultIfEmpty(MessageType.collectionToString(messageTypes),
                    ClientCommons.NOT_SPECIFIED),
            StringUtils.defaultIfEmpty(getSedexId(), ClientCommons.NOT_SPECIFIED));
}

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

public final String getBucketType() {
    return StringUtils.defaultIfEmpty(this.bucketType, DEFAULT_BUCKET_TYPE);
}

From source file:info.magnolia.cms.filters.InstallFilter.java

@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    // this isn't the cleanest thing, but we're basically tricking FreemarkerHelper into using a Context, while avoiding using WebContextImpl and its depedencies on the repository
    final Context originalContext = MgnlContext.hasInstance() ? MgnlContext.getInstance() : null;
    final InstallWebContext ctx = new InstallWebContext();
    ctx.init(request, response, servletContext);
    MgnlContext.setInstance(ctx);/*  w w  w. ja v  a  2 s .  c o  m*/

    try {
        final String contextPath = request.getContextPath();
        // TODO : this will be invalid the day we allow other resources (css, images) to be served through the installer
        response.setContentType("text/html");
        final Writer out = response.getWriter();
        final String uri = request.getRequestURI();
        final ModuleManagerUI ui = moduleManager.getUI();

        final String prefix = contextPath + ModuleManagerWebUI.INSTALLER_PATH;
        if (uri.startsWith(prefix)) {
            final String command = StringUtils.defaultIfEmpty(StringUtils.substringAfter(uri, prefix + "/"),
                    null);
            final boolean installDone = ui.execute(out, command);
            if (installDone) {
                filterManager.startUsingConfiguredFilters();
                // invalidate session: MAGNOLIA-2611
                request.getSession().invalidate();
                // redirect to root
                response.sendRedirect(contextPath + "/");
            }
        } else {
            // redirect to /.magnolia/installer - even if it has no concrete effect, the change in the browser's url bar makes this more explicit
            response.sendRedirect(prefix);
        }
    } catch (ModuleManagementException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e); // TODO
    } finally {
        MgnlContext.release();
        MgnlContext.setInstance(originalContext);
    }
}

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

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

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

    final String collateralTypeIdParamName = COLLATERAL_JSON_INPUT_PARAMS.COLLATERAL_TYPE_ID.getValue();
    if (command.isChangeInLongParameterNamed(collateralTypeIdParamName, this.type.getId())) {
        final Long newValue = command.longValueOfParameterNamed(collateralTypeIdParamName);
        actualChanges.put(collateralTypeIdParamName, newValue);
    }/*w w  w  .j av  a 2 s  . co m*/

    final String descriptionParamName = COLLATERAL_JSON_INPUT_PARAMS.DESCRIPTION.getValue();
    if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) {
        final String newValue = command.stringValueOfParameterNamed(descriptionParamName);
        actualChanges.put(descriptionParamName, newValue);
        this.description = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String valueParamName = COLLATERAL_JSON_INPUT_PARAMS.VALUE.getValue();
    if (command.isChangeInBigDecimalParameterNamed(valueParamName, this.value)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(valueParamName);
        actualChanges.put(valueParamName, newValue);
        this.value = newValue;
    }

    return actualChanges;
}

From source file:com.gst.portfolio.loanaccount.guarantor.domain.Guarantor.java

private Guarantor(final Loan loan, final CodeValue clientRelationshipType, final Integer gurantorType,
        final Long entityId, final String firstname, final String lastname, final Date dateOfBirth,
        final String addressLine1, final String addressLine2, final String city, final String state,
        final String country, final String zip, final String housePhoneNumber, final String mobilePhoneNumber,
        final String comment, final boolean active, final List<GuarantorFundingDetails> guarantorFundDetails) {
    this.loan = loan;
    this.clientRelationshipType = clientRelationshipType;
    this.gurantorType = gurantorType;
    this.entityId = entityId;
    this.firstname = StringUtils.defaultIfEmpty(firstname, null);
    this.lastname = StringUtils.defaultIfEmpty(lastname, null);
    this.dateOfBirth = dateOfBirth;
    this.addressLine1 = StringUtils.defaultIfEmpty(addressLine1, null);
    this.addressLine2 = StringUtils.defaultIfEmpty(addressLine2, null);
    this.city = StringUtils.defaultIfEmpty(city, null);
    this.state = StringUtils.defaultIfEmpty(state, null);
    this.country = StringUtils.defaultIfEmpty(country, null);
    this.zip = StringUtils.defaultIfEmpty(zip, null);
    this.housePhoneNumber = StringUtils.defaultIfEmpty(housePhoneNumber, null);
    this.mobilePhoneNumber = StringUtils.defaultIfEmpty(mobilePhoneNumber, null);
    this.comment = StringUtils.defaultIfEmpty(comment, null);
    this.active = active;
    this.guarantorFundDetails.addAll(guarantorFundDetails);
}

From source file:com.opengamma.component.tool.AbstractDualComponentTool.java

/**
 * Initializes and runs the tool from standard command-line arguments.
 * <p>/*w  w  w .  j  a  v a  2  s . c  o  m*/
 * The base class defined three options:<br />
 * c/component server URI - the component server URI, mandatory<br />
 * l/logback - the logback configuration, default tool-logback.xml<br />
 * h/help - prints the help tool<br />
 * 
 * @param args the command-line arguments, not null
 * @param defaultLogbackResource the default logback resource, null to use tool-logback.xml as the default
 * @return true if successful, false otherwise
 */
public boolean initAndRun(String[] args, String defaultLogbackResource) {
    ArgumentChecker.notNull(args, "args");

    Options options = createOptions();
    CommandLineParser parser = new PosixParser();
    CommandLine line;
    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        return false;
    }
    _commandLine = line;
    if (line.hasOption(HELP_OPTION)) {
        usage(options);
        return true;
    }
    String logbackResource = line.getOptionValue(LOGBACK_RESOURCE_OPTION);
    logbackResource = StringUtils.defaultIfEmpty(logbackResource, TOOL_LOGBACK_XML);
    String srcComponentServerUri = line.getOptionValue(SRC_COMPONENT_SERVER_URI_OPTION);
    String destComponentServerUri = line.getOptionValue(DEST_COMPONENT_SERVER_URI_OPTION);
    return init(logbackResource) && run(srcComponentServerUri, destComponentServerUri);
}

From source file:com.gst.portfolio.client.domain.ClientIdentifier.java

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

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

    final String documentTypeIdParamName = "documentTypeId";
    if (command.isChangeInLongParameterNamed(documentTypeIdParamName, this.documentType.getId())) {
        final Long newValue = command.longValueOfParameterNamed(documentTypeIdParamName);
        actualChanges.put(documentTypeIdParamName, newValue);
    }/*from  www  . j av  a2  s  .  co  m*/

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

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

    final String statusParamName = "status";
    if (command.isChangeInStringParameterNamed(statusParamName,
            ClientIdentifierStatus.fromInt(this.status).getCode())) {
        final String newValue = command.stringValueOfParameterNamed(descriptionParamName);
        actualChanges.put(descriptionParamName, ClientIdentifierStatus.valueOf(newValue));
        this.status = ClientIdentifierStatus.valueOf(newValue).getValue();
    }

    return actualChanges;
}

From source file:hudson.plugins.ccm.CcmPublisher.java

/** {@inheritDoc} */
@Override//from ww  w.  java  2  s. com
public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger)
        throws InterruptedException, IOException {
    logger.log("Collecting CCM analysis files...");
    FilesParser pmdCollector = new FilesParser(PLUGIN_NAME,
            StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN), new CcmParser(getDefaultEncoding()),
            shouldDetectModules(), isMavenBuild(build));
    ParserResult project = build.getWorkspace().act(pmdCollector);
    logger.logLines(project.getLogMessages());

    CcmResult result = new CcmResult(build, getDefaultEncoding(), project);
    build.getActions().add(new CcmResultAction(build, this, result));

    return result;
}