Example usage for org.apache.commons.lang3 StringUtils defaultString

List of usage examples for org.apache.commons.lang3 StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultString.

Prototype

public static String defaultString(final String str, final String defaultStr) 

Source Link

Document

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

 StringUtils.defaultString(null, "NULL")  = "NULL" StringUtils.defaultString("", "NULL")    = "" StringUtils.defaultString("bat", "NULL") = "bat" 

Usage

From source file:com.contentful.vault.Resource.java

@Override
public int hashCode() {
    return (StringUtils.defaultString(getIdPrefix(), "") + remoteId).hashCode();
}

From source file:com.threewks.thundr.view.velocity.VelocityViewResolver.java

@Override
public void resolve(Request req, Response resp, VelocityView viewResult) {
    String view = viewResult.getView();
    String characterEncoding = StringUtils.defaultString(viewResult.getCharacterEncoding(), "UTF-8");

    try {//from w w  w  . j  a  v a 2 s.  com
        Map<String, Object> model = mergeModels(req, viewResult);
        VelocityContext context = new VelocityContext(model);
        Writer stringWriter = new StringWriter();
        velocityEngine.mergeTemplate(view, StringPool.UTF_8, context, stringWriter);
        String content = stringWriter.toString();
        BaseView.applyToResponse(viewResult, resp);
        byte[] data = content.getBytes(characterEncoding);
        resp.withContentLength(data.length);
        resp.getOutputStream().write(data);
    } catch (Exception e) {
        throw new ViewResolutionException(e, "Failed to render velocity template '%s': %s", view,
                e.getMessage());
    }
}

From source file:ca.simplegames.micro.controllers.ControllerManager.java

public ControllerManager(SiteContext site, Map<String, Object> config) {
    this.site = site;
    if (site.isProduction()) {
        cachedScriptControllers = site.getCacheManager().getCacheWithDefault(StringUtils
                .defaultString((String) config.get("cache"), Globals.SCRIPT_CONTROLLERS_CACHE_NAME).trim());
    }/*from w  w w . j a  v a2  s  .co m*/
    pathsToControllers.add(new File(site.getWebInfPath(), "controllers"));
}

From source file:com.cognifide.aet.worker.listeners.AbstractTaskMessageListener.java

protected void doActivate(Map<String, String> properties) {
    setName(properties.get(LISTENER_NAME));
    this.prefetchSize = StringUtils.defaultString(properties.get(PREFETCH_SIZE_NAME),
            PREFETCH_SIZE_DEFAULT_VALUE);
    String consumerQueueName = properties.get(CONSUMER_QUEUE_NAME);
    setConsumerQueueName(consumerQueueName);
    String producerQueueName = properties.get(PRODUCER_QUEUE_NAME);
    setProducerQueueName(producerQueueName);

    String queueName = consumerQueueName + "?consumer.prefetchSize=" + prefetchSize;
    try {//w  w w  . ja va2s.  c o  m
        jmsSession = getJmsConnection().getJmsSession();
        consumer = jmsSession.createConsumer(jmsSession.createQueue(queueName));
        consumer.setMessageListener(this);
        feedbackQueue = new FeedbackQueue(jmsSession, producerQueueName);
    } catch (JMSException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:io.wcm.caravan.io.http.impl.HttpHystrixCommand.java

public HttpHystrixCommand(CaravanHttpRequest request, ExecutionIsolationStrategy isolationStrategy,
        Observable<CaravanHttpResponse> observable, Observable<CaravanHttpResponse> fallback) {

    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GROUP_KEY))
            .andCommandKey(HystrixCommandKey.Factory
                    .asKey(StringUtils.defaultString(request.getServiceId(), "UNKNOWN")))
            .andCommandPropertiesDefaults(
                    HystrixCommandProperties.Setter().withExecutionIsolationStrategy(isolationStrategy)));

    this.request = request;
    this.observable = observable;
    this.fallback = fallback;
}

From source file:cop.raml.utils.javadoc.MethodJavaDoc.java

@NotNull
private static Map<String, TagParam> getParams(List<String> doc) {
    if (CollectionUtils.isEmpty(doc))
        return Collections.emptyMap();

    Map<String, TagParam> params = new LinkedMap<>();
    String paramName = null;//from w  w  w . jav a 2s .c  o  m
    StringBuilder buf = null;
    Matcher matcher;

    for (String line : doc) {
        line = line.trim();

        if ((matcher = JavaDocTag.PARAM.getPattern().matcher(line)).find()) {
            if (paramName != null)
                addParameter(paramName, buf, params);

            paramName = matcher.group("name");
            buf = new StringBuilder(StringUtils.defaultString(matcher.group("text"), ""));
        } else if (paramName != null) {
            if (TAG.matcher(line).find()) {
                addParameter(paramName, buf, params);
                paramName = null;
            } else if (buf.length() > 0)
                buf.append('\n').append(line);
            else
                buf.append(line);
        }
    }

    if (paramName != null)
        addParameter(paramName, buf, params);

    return params.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(params);
}

From source file:com.jxt.web.vo.AgentActiveThreadCountList.java

public List<AgentActiveThreadCount> getAgentActiveThreadRepository() {
    // sort agentId
    Collections.sort(agentActiveThreadRepository, new Comparator<AgentActiveThreadCount>() {
        @Override/*from  w  w w. j  av  a 2  s.  co  m*/
        public int compare(AgentActiveThreadCount o1, AgentActiveThreadCount o2) {
            final String agentId1 = StringUtils.defaultString(o1.getAgentId(), "");
            final String agentId2 = StringUtils.defaultString(o2.getAgentId(), "");
            return agentId1.compareTo(agentId2);
        }
    });
    return agentActiveThreadRepository;
}

From source file:com.wxxr.nirvana.json.SerializationParams.java

public SerializationParams(HttpServletResponse response, String encoding, boolean wrapWithComments,
        String serializedJSON, boolean smd, boolean gzip, boolean noCache, int statusCode, int errorCode,
        boolean prefix, String contentType, String wrapPrefix, String wrapSuffix) {
    this.response = response;
    this.encoding = encoding;
    this.wrapWithComments = wrapWithComments;
    this.serializedJSON = serializedJSON;
    this.smd = smd;
    this.gzip = gzip;
    this.noCache = noCache;
    this.statusCode = statusCode;
    this.errorCode = errorCode;
    this.prefix = prefix;
    this.contentType = StringUtils.defaultString(contentType, DEFAULT_CONTENT_TYPE);
    this.wrapPrefix = wrapPrefix;
    this.wrapSuffix = wrapSuffix;
}

From source file:io.wcm.handler.media.spi.helpers.AbstractMediaSource.java

@Override
public boolean accepts(MediaRequest mediaRequest) {
    // if an explicit media request is set check this first
    if (StringUtils.isNotEmpty(mediaRequest.getMediaRef())) {
        return accepts(mediaRequest.getMediaRef());
    }/*from w w  w.  j a va  2 s. com*/
    // otherwise check resource which contains media request properties
    ValueMap props = mediaRequest.getResourceProperties();
    // check for matching media source ID in link resource
    String mediaSourceId = props.get(MediaNameConstants.PN_MEDIA_SOURCE, String.class);
    if (StringUtils.isNotEmpty(mediaSourceId)) {
        return StringUtils.equals(mediaSourceId, getId());
    }
    // if not link type is set at all check if link ref attribute contains a valid link
    else {
        String refProperty = StringUtils.defaultString(mediaRequest.getRefProperty(),
                getPrimaryMediaRefProperty());
        String mediaRef = props.get(refProperty, String.class);
        return accepts(mediaRef);
    }
}

From source file:de.blizzy.backup.BackupPlugin.java

boolean isHidden() {
    return Boolean
            .parseBoolean(StringUtils.defaultString(getApplicationArg(ARG_HIDDEN), Boolean.FALSE.toString()));
}