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) 

Source Link

Document

Returns either the passed in String, or if the String is null , an empty String ("").

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

Usage

From source file:models.document.LexiconBuilderDocumentTokenModel.java

public LexiconBuilderDocumentTokenModel(LinguisticToken token) {
    if (token != null) {
        this.text = token.getText();
        this.lemma = token.getLemma();
        this.tag = token.getPosTag().getSimpleTag();
        this.trailing = " ".equals(token.getTrailingSeparator()) ? " "
                : (StringUtils.defaultString(token.getTrailingSeparator()).contains("\n") ? "<br/>"
                        : token.getTrailingSeparator());
    }/* w w  w.  j a va 2s  .com*/
}

From source file:ca.uhn.fhir.rest.gclient.TokenCriterion.java

private String toValue(String theSystem, String theCode) {
    String system = ParameterUtil.escape(theSystem);
    String code = ParameterUtil.escape(theCode);
    String value;/*from  ww  w  .  ja  v  a 2  s.c o m*/
    if (StringUtils.isNotBlank(system)) {
        value = system + "|" + StringUtils.defaultString(code);
    } else if (system == null) {
        value = StringUtils.defaultString(code);
    } else {
        value = "|" + StringUtils.defaultString(code);
    }
    return value;
}

From source file:org.meruvian.yama.webapi.service.commons.FileInfoService.java

@Transactional
public FileInfo saveFileInfo(String path, FileInfo fileInfo) throws IOException {
    FileInfo info = new FileInfo();
    info.setPath(StringUtils.join(uploadBasePath, path));
    info.setOriginalName(StringUtils.defaultString(fileInfo.getOriginalName()));

    File file = new File(info.getPath());
    if (!file.exists()) {
        file.mkdirs();//from ww  w .j  a  v a 2  s. com
    }

    info.setContentType(fileInfo.getContentType());
    info = fileInfoRepository.save(info);
    info.setPath(StringUtils.join(info.getPath(), "/", info.getId()));
    if (StringUtils.isBlank(fileInfo.getOriginalName())) {
        info.setOriginalName(info.getId());
    }

    InputStream inputStream = fileInfo.getDataBlob();
    OutputStream outputStream = new FileOutputStream(info.getPath());
    info.setSize(IOUtils.copy(inputStream, outputStream));
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(outputStream);

    return info;
}

From source file:com.wallissoftware.pushstate.client.PushStateHistorianImpl.java

/**
 * constructor./* ww  w .  ja v a 2s.  c  o  m*/
 *
 * @param prelativePath relative path to use
 */
PushStateHistorianImpl(final String prelativePath) {
    this.relativePath = StringUtils.endsWith(prelativePath, "/") ? prelativePath
            : StringUtils.defaultString(prelativePath) + "/";
    this.initToken();
    this.registerPopstateHandler();
}

From source file:de.micromata.mgc.jpa.hibernatesearch.bridges.TabAttrFieldBridge.java

public static void addToIndex(String prefix, Object value, Document document, LuceneOptions luceneOptions) {
    if ((value instanceof Map) == false) {
        return;//from  w  ww.  j  a v  a  2  s.  co  m
    }
    Map rawmap = (Map) value;
    if (rawmap.isEmpty() == true) {
        return;
    }

    Set<Map.Entry> mes = rawmap.entrySet();
    for (Map.Entry me : mes) {
        if ((me.getKey() instanceof String) == false || (me.getValue() instanceof JpaTabAttrBaseDO) == false) {
            LOG.error("Bridge to incompatible type: " + me.getKey() + "=" + me.getValue());
            continue;
        }
        String key = (String) me.getKey();
        JpaTabAttrBaseDO<?, ?> attr = (JpaTabAttrBaseDO<?, ?>) me.getValue();
        String svalue = attr.getStringData();
        svalue = StringUtils.defaultString(svalue);
        Field field = new StringField(key, svalue, DEFAULT_STORE);
        document.add(field);
        field = new StringField("ALL", svalue, DEFAULT_STORE);
        document.add(field);
        field = new StringField("propertyName", key, DEFAULT_STORE);
        document.add(field);

        field = new StringField("value", svalue, DEFAULT_STORE);
        document.add(field);

    }
}

From source file:controllers.base.SessionedAction.java

public static String getSessionKey(Context ctx) {
    if (ctx == null) {
        ctx = Validate.notNull(Context.current());
    }/*from  w w w  .  ja  v a 2s .c  o m*/

    String sessionId = null;

    // try to get the session id from the query string.
    String[] param = ctx.request().queryString().get("session");
    if (param != null && param.length > 0) {
        sessionId = param[0];
        WebSession session = getWebSession(sessionId);
        if (session == null || session.getStatus() != SessionStatus.IMMORTALIZED) {
            sessionId = null;
        }
    }

    // if not, try to get the session id from headers or cookies.
    if (StringUtils.isEmpty(sessionId)) {
        // decrypt it.
        sessionId = StringUtils.defaultString(StringUtils.defaultString(
                ctx.request().getHeader(SARE_SESSION_HEADER), ctx.session().get(SESSION_ID_KEY)));
        if (StringUtils.isNotEmpty(sessionId)) {
            try {
                sessionId = Crypto.decryptAES(sessionId);
            } catch (Throwable e) {
                sessionId = null;
            }
        }
    }

    return UuidUtils.isUuid(sessionId) ? sessionId : null;
}

From source file:com.netsteadfast.greenstep.bsc.esb.router.KPIsRouteBuilder.java

@Override
public void configure() throws Exception {
    from("servlet:///kpis").process(new Processor() {

        @Override/*from  w w  w.j  a v  a2  s  . c om*/
        public void process(Exchange exchange) throws Exception {
            String format = StringUtils.defaultString(exchange.getIn().getHeader("format", String.class)).trim()
                    .toLowerCase();
            IKpiLogicService kpiLogicService = (IKpiLogicService) AppContext
                    .getBean("bsc.service.logic.KpiLogicService");
            exchange.getOut().setBody(kpiLogicService.findKpis(format));
        }

    }).to("stream:out");
}

From source file:io.github.robwin.swagger2markup.utils.ParameterUtils.java

public static String getType(Parameter parameter, MarkupLanguage markupLanguage) {
    Validate.notNull(parameter, "property must not be null!");
    String type = "NOT FOUND";
    if (parameter instanceof BodyParameter) {
        BodyParameter bodyParameter = (BodyParameter) parameter;
        Model model = bodyParameter.getSchema();
        type = ModelUtils.getType(model, markupLanguage);
    } else if (parameter instanceof AbstractSerializableParameter) {
        AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter) parameter;
        List enums = serializableParameter.getEnum();
        if (CollectionUtils.isNotEmpty(enums)) {
            type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
        } else {/*  w  w w.  ja va2s.  c om*/
            type = getTypeWithFormat(serializableParameter.getType(), serializableParameter.getFormat());
        }
        if (type.equals("array")) {
            String collectionFormat = serializableParameter.getCollectionFormat();
            type = collectionFormat + " "
                    + PropertyUtils.getType(serializableParameter.getItems(), markupLanguage) + " " + type;
        }
    } else if (parameter instanceof RefParameter) {
        RefParameter refParameter = (RefParameter) parameter;
        switch (markupLanguage) {
        case ASCIIDOC:
            return "<<" + refParameter.getSimpleRef() + ">>";
        default:
            return refParameter.getSimpleRef();
        }
    }
    return StringUtils.defaultString(type);
}

From source file:com.webbfontaine.valuewebb.utils.TTMailUtils.java

public void initTextVariables() {
    textVariables = new HashMap<String, String>();
    textVariables.put("$IDF_Number$", ttGen.getIdfNum());
    textVariables.put("$FCVR_Number$", ttGen.getFcvrNum());
    textVariables.put("$Importer_TIN$", ttGen.getImpTin());
    textVariables.put("$Importer_Name$", StringUtils.defaultString(ttGen.getImpNam()));
    textVariables.put("$Invoice_Number$", ttGen.getTtInvs().get(0).getdInvNum());
    textVariables.put("$contact_email$", StringUtils.defaultString(ApplicationProperties.getContactEmail()));
    textVariables.put("$service_tel$", ApplicationProperties.getCustomerServiceTel());
    textVariables.put("$idf_string$", Utils.getIdfStringDependsOnCountryVersion());
}

From source file:ch.qos.logback.decoder.CallerStackTraceParser.java

@Override
public void captureField(IStaticLoggingEvent event, String fieldAsStr, PatternInfo info) {

    List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
    Matcher m = PATTERN.matcher(fieldAsStr);
    while (m.find()) {
        String line = m.group(1);

        Matcher m2 = PATTERN2.matcher(line);
        if (!m2.find()) {
            continue;
        }/*from   w ww .  ja va  2  s  .  co m*/

        String className = StringUtils.defaultString(m2.group("class"));
        String fileName = StringUtils.defaultString(m2.group("file"));
        String lineNumberStr = StringUtils.defaultString(m2.group("line"));

        // parse line number from string
        int lineNumber = 0;
        if (lineNumberStr.length() > 0) {
            try {
                lineNumber = Integer.valueOf(lineNumberStr);
            } catch (NumberFormatException e) {
                // ignore
            }
        }

        // parse method name from classname field
        int pos = className.lastIndexOf('.');
        String methodName;
        if (pos > -1) {
            methodName = className.substring(className.lastIndexOf('.') + 1);
            className = className.substring(0, pos);
        } else {
            methodName = className;
            className = "";
        }

        stackTrace.add(new StackTraceElement(className, methodName, fileName, lineNumber));
    }

    event.setCallerStackData(stackTrace);
}