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:cc.sion.core.utils.Exceptions.java

/**
 *  ??: ? <-- RootCause??: ?/*  ww  w.  ja va  2 s  . c  om*/
 */
public static String toStringWithRootCause(@Nullable Throwable t) {
    if (t == null) {
        return StringUtils.EMPTY;
    }

    final String clsName = ClassUtils.getShortClassName(t, null);
    final String message = StringUtils.defaultString(t.getMessage());
    Throwable cause = getRootCause(t);

    StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message);
    if (cause != t) {
        sb.append("; <---").append(toStringWithShortName(cause));
    }

    return sb.toString();
}

From source file:dtu.ds.warnme.model.impl.UserEntity.java

@Override
public void merge(UserEntity user) {
    setUsername(StringUtils.defaultString(user.getUsername()));
    setPassword(StringUtils.defaultString(user.getPassword()));
    setEmail(StringUtils.defaultString(user.getEmail()));
    setComment(StringUtils.defaultIfBlank(user.getComment(), null));
    setLocked(user.isLocked());/*from  w ww  .j a va 2s .  com*/
    setDeleted(user.isDeleted());
}

From source file:com.netsteadfast.greenstep.bsc.util.BscReportSupportUtils.java

public static String getUrlIcon(KpiVO kpi, float score) throws Exception {
    String icon = "";
    SysExpressionVO sysExpression = exprThreadLocal01.get();
    if (null == sysExpression) {
        return icon;
    }/*from w ww  .ja  v  a  2s . com*/
    Map<String, Object> parameters = new HashMap<String, Object>();
    Map<String, Object> results = new HashMap<String, Object>();
    parameters.put("kpi", kpi);
    parameters.put("score", score);
    results.put("icon", " ");
    ScriptExpressionUtils.execute(sysExpression.getType(), sysExpression.getContent(), results, parameters);
    icon = (String) results.get("icon");
    return StringUtils.defaultString(icon);
}

From source file:com.sonicle.webtop.core.util.NotificationHelper.java

/**
 * Creates strings map for notification (simple body) template
 * @param locale//from  w  w w . jav a 2 s. c  om
 * @param source
 * @param recipientEmail
 * @param bodyHeader
 * @param bodyMessage
 * @param becauseString
 * @return 
 */
public static Map<String, String> createDefaultBodyTplStrings(Locale locale, String source,
        String recipientEmail, String bodyHeader, String bodyMessage, String becauseString) {
    HashMap<String, String> map = new HashMap<>();
    map.put("bodyHeader", StringUtils.defaultString(bodyHeader));
    map.put("bodyMessage", StringUtils.defaultString(bodyMessage));
    map.put("footerHeader", MessageFormat.format(
            WT.lookupResource(CoreManifest.ID, locale, CoreLocaleKey.TPL_NOTIFICATION_FOOTER_HEADER), source));
    map.put("footerMessage",
            MessageFormat.format(
                    WT.lookupResource(CoreManifest.ID, locale, CoreLocaleKey.TPL_NOTIFICATION_FOOTER_MESSAGE),
                    recipientEmail, becauseString));
    return map;
}

From source file:com.netsteadfast.greenstep.bsc.action.SwotSaveOrUpdateAction.java

private List<SwotVO> fillDatas() throws Exception {
    String headParam = "BSC_PROG002D0008Q" + BscConstants.SWOT_TEXT_INPUT_ID_SEPARATE;
    List<SwotVO> datas = new ArrayList<SwotVO>();
    Enumeration<String> names = this.getHttpServletRequest().getParameterNames();
    while (names.hasMoreElements()) {
        String paramName = names.nextElement();
        if (!paramName.startsWith(headParam)) {
            continue;
        }//from  w  w w.j  av a  2s  .c  o m
        // BSC_PROG002D0008Q:TYPE:VIS_ID:PER_ID:ORG_ID
        String tmpId[] = paramName.split(BscConstants.SWOT_TEXT_INPUT_ID_SEPARATE);
        if (tmpId.length != 5) {
            continue;
        }
        SwotVO obj = new SwotVO();
        obj.setType(tmpId[1]);
        obj.setVisId(tmpId[2]);
        obj.setPerId(tmpId[3]);
        obj.setOrgId(tmpId[4]);
        obj.setIssues(StringUtils.defaultString(this.getHttpServletRequest().getParameter(paramName)));
        datas.add(obj);
    }
    return datas;
}

From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.artefakt.FileStatsDO.java

/**
 * Returns map to ease serialize with {@link PipeValueList}
 * /*w  w  w .java2 s .c  o  m*/
 * @return
 */
public Map<String, String> getAsMap() {
    Map<String, String> contentMap = new HashMap<String, String>();

    contentMap.put(PAGE_ID, pageId);
    contentMap.put(FILE_STATE, fileState.name());
    contentMap.put(ASSIGNED_TO, assignedTo);
    contentMap.put(CREATED_AT, createdAt);
    contentMap.put(CREATED_BY, createdBy);
    contentMap.put(MODIFIED_AT, StringUtils.defaultString(lastModifiedAt));
    contentMap.put(MODIFIED_BY, StringUtils.defaultString(lastModifiedBy));
    contentMap.put(OPERATORS, StringUtils.defaultString(StringUtils.join(operators, ",")));
    contentMap.put(START_AT, StringUtils.defaultString(startAt));
    contentMap.put(END_AT, StringUtils.defaultString(endAt));
    contentMap.put(PREVIOUS_ASSIGNEE, StringUtils.defaultString(previousAssignee));

    return contentMap;
}

From source file:com.github.achatain.nopasswordauthentication.utils.FakeHttpServletRequest.java

public BufferedReader getReader() {
    return new BufferedReader(new StringReader(StringUtils.defaultString(body)));
}

From source file:de.micromata.genome.gwiki.page.search.GlobalIndexFile.java

/**
 * Update segments.//  w  w  w  .  ja  va 2  s  . c o m
 *
 * @param storage the storage
 * @param elmL the elm l
 */
public static void updateSegments(GWikiStorage storage, List<Pair<GWikiElement, String>> elmL) {
    final GWikiContext ctx = GWikiContext.getCurrent();
    GWikiElement el = ctx.getWikiWeb().findElement(GLOBAL_INDEX_PAGEID);
    if (el == null) {
        el = createElement(ctx);
    }
    GlobalWordIndexTextArtefakt art = (GlobalWordIndexTextArtefakt) el.getMainPart();

    String cont = StringUtils.defaultString(art.getStorageData());
    for (Pair<GWikiElement, String> elmp : elmL) {
        GWikiElement elm = elmp.getFirst();
        String pageId = elm.getElementInfo().getId();
        String startTag = "<" + pageId + "\n";
        String endTag = ">" + pageId + "\n";

        int idx = cont.indexOf(startTag);
        String ncont;
        if (idx == -1) {
            ncont = cont + startTag + elmp.getSecond() + endTag;
        } else {
            int eidx = cont.indexOf(endTag);
            if (eidx == -1) {
                // oops
                ncont = cont + startTag + elmp.getSecond() + endTag;
            } else {
                ncont = cont.substring(0, idx) + startTag + elmp.getSecond() + endTag
                        + cont.substring(eidx + endTag.length());
            }
        }
        cont = ncont;
        if (art.getIndexFileMap() != null) {
            art.getIndexFileMap().put(pageId, elmp.getSecond());
        }
    }
    art.setStorageData(cont);

    final GWikiElement fel = el;
    ctx.getWikiWeb().getAuthorization().runAsSu(ctx, new CallableX<Void, RuntimeException>() {

        @Override
        public Void call() throws RuntimeException {
            ctx.getWikiWeb().getStorage().storeElement(ctx, fel, false);
            return null;
        }
    });
}

From source file:com.netsteadfast.greenstep.aspect.HessianServiceProxyAspect.java

private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = AspectConstants.getServiceId(annotations);

    /**//from   www .j  ava2 s.c  o m
     * ???? service-bean
     */
    if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
        //logger.info( "reject proxy service: " + serviceId );
        return pjp.proceed();
    }

    String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());

    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
        /**
         * ???? service-bean
         */
        if (StringUtils.isBlank(userId)) {
            logger.warn("no userId");
            pjp.proceed();
        }

        /**
         * ???? service-bean
         */
        if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
            logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
            return pjp.proceed();
        }
    }

    String serviceInterfacesName = "";
    Class<?> serviceInterfaces[] = pjp.getTarget().getClass().getInterfaces();
    for (Class<?> clazz : serviceInterfaces) {
        if (clazz.getName().indexOf(".service.") > -1) {
            serviceInterfacesName = clazz.getName();
        }
    }
    if (StringUtils.isBlank(serviceInterfacesName)) {
        logger.error("error no service interface: " + serviceId);
        throw new Exception("error no service interface: " + serviceId);
    }

    String url = GreenStepHessianUtils.getServiceUrl(serviceId);
    String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/"
            + ApplicationSiteUtils.getContextPath(Constants.getSystem());

    /**
     * ?????, ? HessianServiceProxyAspect ? (server-remote???)
     *  http://127.0.0.1:8080/
     *  hessian.enable=Y ???, ?url hessian.serverUrl=http://127.0.0.1:8080/
     * 
     */
    if (url.indexOf(theSystemPath) > -1) {
        logger.error("cannot open same-server. now system contextPath = " + theSystemPath
                + " , but proxy url = " + url);
        throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath
                + " , but proxy url = " + url);
    }

    logger.info("proxy url = " + url);
    HessianProxyFactory factory = null;
    Object proxyServiceObject = null;
    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) { // ?checkValue?
        factory = new GreenStepHessianProxyFactory();
        ((GreenStepHessianProxyFactory) factory)
                .setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
        proxyServiceObject = ((GreenStepHessianProxyFactory) factory)
                .createForHeaderMode(Class.forName(serviceInterfacesName), url);
    } else { // ?checkValue?
        factory = new HessianProxyFactory();
        proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
    }
    Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
    Method proxyObjectMethod = null;
    if (null == proxyObjectMethods) {
        logger.error("error no find proxy method: " + serviceId);
        throw new Exception("error no find proxy method: " + serviceId);
    }
    for (Method m : proxyObjectMethods) {
        if (m.getName().equals(signature.getMethod().getName())
                && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
            proxyObjectMethod = m;
        }
    }

    if (null == proxyObjectMethod) {
        logger.error("error no execute proxy method: " + serviceId);
        throw new Exception("error no execute proxy method: " + serviceId);
    }

    Object resultObj = null;
    try {
        resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
        this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
    } catch (InvocationTargetException e) {
        if (e.getMessage() != null) {
            throw new ServiceException(e.getMessage().toString());
        }
        if (e.getTargetException().getMessage() != null) {
            throw new ServiceException(e.getTargetException().getMessage().toString());
        }
        throw e;
    } catch (Exception e) {
        logger.error(e.getMessage().toString());
        throw e;
    }
    logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
    return resultObj;
}

From source file:com.netsteadfast.greenstep.bsc.command.KpiReportBodyCommand.java

@Override
public boolean execute(Context context) throws Exception {
    if (this.getResult(context) == null || !(this.getResult(context) instanceof BscStructTreeObj)) {
        return false;
    }//from  w ww.j  a v a 2s  .  co m
    String frequency = (String) context.get("frequency");
    String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim();
    String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim();
    String startDate = StringUtils.defaultString((String) context.get("startDate")).trim();
    String endDate = StringUtils.defaultString((String) context.get("endDate")).trim();
    String date1 = startDate;
    String date2 = endDate;
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        date1 = startYearDate + "/01/01";
        date2 = endYearDate + "/12/" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12);
    }
    BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context);
    Map<String, Object> parameter = new HashMap<String, Object>();
    parameter.put("treeObj", treeObj);
    parameter.put("date1", date1);
    parameter.put("date2", date2);
    parameter.put("frequency", BscMeasureDataFrequency.getFrequencyMap(false).get(frequency));
    parameter.put("headContent", "");
    this.fillHeadContent(context, parameter);
    this.fillReportProperty(parameter);
    String templateResourceSrc = templateResource;
    if (YesNo.YES.equals((String) context.get("ngVer"))) { //  javascript click 
        templateResourceSrc = templateResource_NG;
    }
    String nextType = (String) context.get("nextType");
    String nextId = (String) context.get("nextId");
    if (BscConstants.HEAD_FOR_PER_ID.equals(nextType) && !StringUtils.isBlank(nextId)) {
        templateResourceSrc = templateResource_NG_PER;
    }
    if (BscConstants.HEAD_FOR_OBJ_ID.equals(nextType) && !StringUtils.isBlank(nextId)) {
        templateResourceSrc = templateResource_NG_OBJ;
    }
    if (BscConstants.HEAD_FOR_KPI_ID.equals(nextType) && !StringUtils.isBlank(nextId)) {
        templateResourceSrc = templateResource_NG_KPI;
    }
    this.setImgIconBaseAndKpiInfo(treeObj);
    String content = TemplateUtils.processTemplate("resourceTemplate",
            KpiReportBodyCommand.class.getClassLoader(), templateResourceSrc, parameter);
    this.setResult(context, content);
    return false;
}