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:de.hasait.genesis.base.util.GenesisUtils.java

public static boolean writeIfNonWhitespaceChanged(final String pContent, final File pFile) throws IOException {
    final String currentContent = readFileToString(pFile);
    final String content = StringUtils.defaultString(pContent);
    if (currentContent != null) {
        if (reduceWhitespacesToSpace(content).equals(reduceWhitespacesToSpace(currentContent))) {
            return false;
        }/*from  www . j av a 2 s  . c  o  m*/
    }
    FileUtils.write(pFile, content);
    return true;
}

From source file:com.linkedin.urls.Url.java

public String getFragment() {
    if (_fragment == null) {
        _fragment = getPart(UrlPart.FRAGMENT);
    }
    return StringUtils.defaultString(_fragment);
}

From source file:com.netsteadfast.greenstep.action.SystemBpmnResourceSaveOrUpdateAction.java

private void fillResource(SysBpmnResourceVO resource) throws Exception {
    this.transformFields2ValueObject(resource, new String[] { "id", "name", "description" });
    if (StringUtils.defaultString(resource.getDescription()).length() > MAX_DESCRIPTION_LENGTH) {
        resource.setDescription(resource.getDescription().substring(0, MAX_DESCRIPTION_LENGTH));
    }/*from  w  w w . ja  va  2  s. com*/
}

From source file:com.netsteadfast.greenstep.base.interceptor.UserLoginInterceptor.java

/**
 * 1. admin//from  ww w .  j  av a2 s . com
 * 2. admin  tester
 *  gsbsc-web  http-session admin , ?core-webtestersession , ??CURRENT cookie ? gsbsc-web 
 * ??? http-session 
 *  
 * @param actionContext
 * @throws Exception
 */
private void invalidCurrentSessionForDifferentAccount(ActionContext actionContext) throws Exception {
    if (this.accountObj == null) {
        return;
    }
    Map<String, String> dataMap = UserCurrentCookie
            .getCurrentData((HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST));
    String account = StringUtils.defaultString(dataMap.get("account"));
    if (StringUtils.isBlank(account)) {
        return;
    }
    if (this.accountObj.getAccount().equals(account)) {
        return;
    }
    this.accountObj = null;
    UserAccountHttpSessionSupport.remove(actionContext.getSession());
    SecurityUtils.getSubject().logout();
}

From source file:de.micromata.genome.gwiki.controls.GWikiPageListActionBean.java

protected SearchQuery buildQuery() {
    String searchExpr = "";
    try {/*from ww w .  jav  a 2s  .  co  m*/
        // String reqDump = getReqDump();
        Iterable<GWikiElementInfo> webInfos = wikiContext.getWikiWeb().getElementInfos();
        List<SearchResult> sr = new ArrayList<SearchResult>(wikiContext.getWikiWeb().getElementInfoCount());
        for (GWikiElementInfo wi : webInfos) {
            if (filterBeforeQuery(wi) == true) {
                sr.add(new SearchResult(wi));
            }
        }
        searchExpr = getSearchExpression();
        SearchQuery query = new SearchQuery(StringUtils.defaultString(searchExpr), false, sr);
        query.setMaxCount(100000);
        return query;
    } catch (Exception ex) {
        wikiContext.append(ex.getMessage() + " for " + searchExpr);
        return null;
    }
}

From source file:ching.icecreaming.action.EditAction.java

@Action(value = "edit", results = { @Result(name = "login", location = "edit.jsp"),
        @Result(name = "success", location = "view.jsp"), @Result(name = "error", location = "error.jsp") })
public String execute() throws Exception {
    URL url1 = null;//from   ww w.j  a  va 2  s. c  o m
    URI uri1 = null;
    HttpGet httpGet1 = null;
    DefaultHttpClient httpClient1 = new DefaultHttpClient();
    HttpResponse httpResponse1 = null;
    int int1 = 0, int2 = 401;
    String[] array1 = null;
    String string1 = getText("Error") + " %d: %s", result1 = LOGIN;
    byte[] bytes1 = null;
    if (StringUtils.isBlank(timeZone1))
        timeZone1 = portletPreferences.getValue("timeZone", TimeZone.getDefault().getID());
    if (StringUtils.isNotBlank(sid) && StringUtils.isNotBlank(uid) && StringUtils.isNotBlank(pid)) {
        try {
            url1 = new URL(sid);
            URIBuilder uriBuilder = new URIBuilder(sid);
            uriBuilder.setParameter("j_username", uid);
            uriBuilder.setParameter("j_password", pid);
            uriBuilder.setPath(url1.getPath() + "/rest/login");
            uri1 = uriBuilder.build();
            httpGet1 = new HttpGet(uri1);
            httpResponse1 = httpClient1.execute(httpGet1);
            int2 = httpResponse1.getStatusLine().getStatusCode();
        } catch (IOException exception1) {
            exception1.printStackTrace();
        } catch (URISyntaxException exception1) {
            exception1.printStackTrace();
        } finally {
            httpClient1.getConnectionManager().shutdown();
            if (int2 == HttpStatus.SC_OK) {
                sid = new String(Base64.encodeBase64(sid.getBytes()));
                uid = new String(Base64.encodeBase64(uid.getBytes()));
                pid = new String(Base64.encodeBase64(pid.getBytes()));
                urlString = "/";
                wsType = "folder";
                array1 = new String[] { sid, uid, pid, StringUtils.defaultString(alias1) };
                portletPreferences.setValue("urlString", urlString);
                portletPreferences.setValue("wsType", wsType);
                portletPreferences.setValue("timeZone", timeZone1);
                portletPreferences.setValues("server", array1);
                portletPreferences.store();
                result1 = SUCCESS;
            } else {
                array1 = portletPreferences.getValues("server", null);
                if (array1 != null)
                    if (ArrayUtils.isNotEmpty(array1)) {
                        for (int1 = 0; int1 < array1.length; int1++) {
                            switch (int1) {
                            case 0:
                                sid = array1[int1];
                                break;
                            case 1:
                                uid = array1[int1];
                                break;
                            case 2:
                                pid = array1[int1];
                                break;
                            case 3:
                                alias1 = array1[int1];
                                break;
                            default:
                                break;
                            }
                        }
                        sid = new String(Base64.decodeBase64(sid.getBytes()));
                        uid = new String(Base64.decodeBase64(uid.getBytes()));
                        pid = new String(Base64.decodeBase64(pid.getBytes()));
                    }
                addActionError(String.format(string1, int2, getText(Integer.toString(int2))));
            }
        }
    } else {
        array1 = portletPreferences.getValues("server", null);
        if (StringUtils.isBlank(urlString) || StringUtils.isBlank(wsType)) {
            urlString = portletPreferences.getValue("urlString", "/");
            wsType = portletPreferences.getValue("wsType", "folder");
        }
        if (array1 != null) {
            if (ArrayUtils.isNotEmpty(array1)) {
                for (int1 = 0; int1 < array1.length; int1++) {
                    switch (int1) {
                    case 0:
                        sid = array1[int1];
                        break;
                    case 1:
                        uid = array1[int1];
                        break;
                    case 2:
                        pid = array1[int1];
                        break;
                    case 3:
                        alias1 = array1[int1];
                        break;
                    default:
                        break;
                    }
                }
                sid = new String(Base64.decodeBase64(sid.getBytes()));
                uid = new String(Base64.decodeBase64(uid.getBytes()));
                pid = new String(Base64.decodeBase64(pid.getBytes()));
            }
        }
    }
    return result1;
}

From source file:ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString.java

public void setValueExact(String theValueExact) {
    if (StringUtils.defaultString(theValueExact).length() > MAX_LENGTH) {
        throw new IllegalArgumentException("Value is too long: " + theValueExact.length());
    }/*from w w w  .  j a va2s . c  o  m*/
    myValueExact = theValueExact;
}

From source file:com.xpn.xwiki.stats.impl.VisitStats.java

/**
 * @param userAgent the user agent of the user.
 *///w w  w. j  a v a  2  s . co m
public void setUserAgent(String userAgent) {
    setStringValue(Property.userAgent.toString(), StringUtils.defaultString(userAgent));
}

From source file:com.sonicle.webtop.core.app.SettingsManager.java

/**
 * Gets the setting (user) value indicated by the specified key.
 * Returns a null value if the key is not found.
 * @param domainId The domain ID./*w  w w  .  j a  v  a2 s.c  om*/
 * @param userId The user ID.
 * @param serviceId The service ID.
 * @param key The name of the setting.
 * @return The string value of the setting.
 */
private String getSetting(String domainId, String userId, String serviceId, String key) {
    UserSettingDAO dao = UserSettingDAO.getInstance();
    Connection con = null;
    OUserSetting item = null;

    try {
        con = wta.getConnectionManager().getConnection(CoreManifest.ID);
        item = dao.selectByDomainUserServiceKey(con, domainId, userId, serviceId, key);
        return (item != null) ? StringUtils.defaultString(item.getValue()) : null;

    } catch (Exception ex) {
        WebTopApp.logger.error("Unable to read user setting [{}, {}, {}, {}]", domainId, userId, serviceId, key,
                ex);
        throw new RuntimeException(ex);
    } finally {
        DbUtils.closeQuietly(con);
    }
}

From source file:com.xpn.xwiki.objects.classes.DBListClass.java

/**
 * <p>//from  w  w  w .  j a  v  a2 s .  c om
 * Computes the query corresponding to the current XProperty. The query is either manually specified by the XClass
 * creator in the <tt>sql</tt> field, or, if the query field is blank, constructed using the <tt>classname</tt>,
 * <tt>idField</tt> and <tt>valueField</tt> properties. The query is constructed according to the following rules:
 * </p>
 * <ul>
 * <li>If no classname, id or value fields are selected, return a query that return no rows.</li>
 * <li>If only the classname is provided, select all document names which have an object of that type.</li>
 * <li>If only one of id and value is provided, select just one column.</li>
 * <li>If id = value, select just one column.</li>
 * <li>If no classname is provided, assume the fields are document properties.</li>
 * <li>If the document is not used at all, don't put it in the query.</li>
 * <li>If the object is not used at all, don't put it in the query.</li>
 * </ul>
 * <p>
 * If there are two columns selected, use the first one as the stored value and the second one as the displayed
 * value.
 * </p>
 * 
 * @param context The current {@link XWikiContext context}.
 * @return The HQL query corresponding to this property.
 */
public String getQuery(XWikiContext context) {
    // First, get the hql query entered by the user.
    String sql = getSql();
    // If the query field is blank, construct a query using the classname, idField and
    // valueField properties.
    if (StringUtils.isBlank(sql)) {
        if (context.getWiki().getHibernateStore() != null) {
            // Extract the 3 properties in non-null variables.
            String classname = StringUtils.defaultString(getClassname());
            String idField = StringUtils.defaultString(getIdField());
            String valueField = StringUtils.defaultString(getValueField());

            // Check if the properties are specified or not.
            boolean hasClassname = !StringUtils.isBlank(classname);
            boolean hasIdField = !StringUtils.isBlank(idField);
            boolean hasValueField = !StringUtils.isBlank(valueField);

            if (!(hasIdField || hasValueField)) {
                // If only the classname is specified, return a query that selects all the
                // document names which have an object of that type.
                if (hasClassname) {
                    sql = "select distinct doc.fullName from XWikiDocument as doc, BaseObject as obj"
                            + " where doc.fullName=obj.name and obj.className='" + classname + "'";
                } else {
                    // If none of the 3 properties is specified, return a query that always
                    // returns no rows.
                    sql = DEFAULT_QUERY;
                }
                return sql;
            }

            // If the value field is specified, but the id isn't, swap them.
            if (!hasIdField && hasValueField) {
                idField = valueField;
                valueField = "";
                hasValueField = false;
            } else if (idField.equals(valueField)) {
                // If the value field is the same as the id field, ignore it.
                hasValueField = false;
            }

            // Check if the document and object are needed or not.
            // The object is needed if there is a classname, or if at least one of the selected
            // columns is an object property.
            boolean usesObj = hasClassname || idField.startsWith("obj.") || valueField.startsWith("obj.");
            // The document is needed if one of the selected columns is a document property, or
            // if there is no classname specified and at least one of the selected columns is
            // not an object property.
            boolean usesDoc = idField.startsWith("doc.") || valueField.startsWith("doc.");
            if ((!idField.startsWith("obj.") || (hasValueField && !valueField.startsWith("obj.")))
                    && !hasClassname) {
                usesDoc = true;
            }

            // Build the query in this variable.
            StringBuffer select = new StringBuffer("select distinct ");
            // These will hold the components of the from and where parts of the query.
            List<String> fromStatements = new ArrayList<String>();
            List<String> whereStatements = new ArrayList<String>();

            // Add the document to the query only if it is needed.
            if (usesDoc) {
                fromStatements.add("XWikiDocument as doc");
                if (usesObj) {
                    whereStatements.add("doc.fullName=obj.name");
                }
            }
            // Add the object to the query only if it is needed.
            if (usesObj) {
                fromStatements.add("BaseObject as obj");
                if (hasClassname) {
                    whereStatements.add("obj.className='" + classname + "'");
                }
            }

            // Add the first column to the query.
            if (idField.startsWith("doc.") || idField.startsWith("obj.")) {
                select.append(idField);
            } else if (!hasClassname) {
                select.append("doc." + idField);
            } else {
                select.append("idprop.value");
                fromStatements.add("StringProperty as idprop");
                whereStatements.add("obj.id=idprop.id.id and idprop.id.name='" + idField + "'");
            }

            // If specified, add the second column to the query.
            if (hasValueField) {
                if (valueField.startsWith("doc.") || valueField.startsWith("obj.")) {
                    select.append(", ").append(valueField);
                } else if (!hasClassname) {
                    select.append(", doc." + valueField);
                } else {
                    select.append(", valueprop.value");
                    fromStatements.add("StringProperty as valueprop");
                    whereStatements.add("obj.id=valueprop.id.id and valueprop.id.name='" + valueField + "'");
                }
            }
            // Let's create the complete query
            select.append(" from ");
            select.append(StringUtils.join(fromStatements.iterator(), ", "));
            if (whereStatements.size() > 0) {
                select.append(" where ");
                select.append(StringUtils.join(whereStatements.iterator(), " and "));
            }
            sql = select.toString();
        } else {
            // TODO: query plugin impl.
            // We need to generate the right query for the query plugin
        }
    }
    // Parse the query, so that it can contain velocity scripts, for example to use the
    // current document name, or the current username.
    try {
        sql = context.getWiki().parseContent(sql, context);
    } catch (Exception e) {
        LOGGER.error("Failed to parse SQL script [" + sql + "]. Continuing with non-rendered script.", e);
    }

    return sql;
}