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:com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy.java

String computeReplacementValue(final String replacement, final String originalString, final Matcher matcher) {

    int lastIndex = 0;
    final StringBuilder result = new StringBuilder();
    int i;/*from   ww  w. j av  a 2s . c  om*/
    while ((i = replacement.indexOf('$', lastIndex)) > -1) {
        if (i > 0) {
            result.append(replacement, lastIndex, i);
        }
        String ss = null;
        if (i < replacement.length() - 1 && (i == lastIndex || replacement.charAt(i - 1) != '$')) {
            final char next = replacement.charAt(i + 1);
            // only valid back reference are "evaluated"
            if (next >= '1' && next <= '9') {
                final int num1digit = next - '0';
                final char next2 = (i + 2 < replacement.length()) ? replacement.charAt(i + 2) : 'x';
                final int num2digits;
                // if there are 2 digits, the second one is considered as part of the group number
                // only if there is such a group
                if (next2 >= '1' && next2 <= '9') {
                    num2digits = num1digit * 10 + (next2 - '0');
                } else {
                    num2digits = Integer.MAX_VALUE;
                }
                if (num2digits <= matcher.groupCount()) {
                    ss = matcher.group(num2digits);
                    i++;
                } else if (num1digit <= matcher.groupCount()) {
                    ss = StringUtils.defaultString(matcher.group(num1digit));
                }
            } else {
                switch (next) {
                case '&':
                    ss = matcher.group();
                    break;
                case '0':
                    if (browserVersion_.hasFeature(JS_REGEXP_GROUP0_RETURNS_WHOLE_MATCH)) {
                        ss = matcher.group();
                    }
                    break;
                case '`':
                    ss = originalString.substring(0, matcher.start());
                    break;
                case '\'':
                    ss = originalString.substring(matcher.end());
                    break;
                case '$':
                    ss = "$";
                    break;
                default:
                }
            }
        }
        if (ss == null) {
            result.append('$');
            lastIndex = i + 1;
        } else {
            result.append(ss);
            lastIndex = i + 2;
        }
    }

    result.append(replacement, lastIndex, replacement.length());

    return result.toString();
}

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

/**
 * ?core-web cookie, cookie account  current-id
 *  TB_SYS_USESS core-web?//  w  ww.ja  va  2  s .c o  m
 * core-web,  AccountVO  true
 * 
 * @param actionContext
 * @return
 * @throws Exception
 */
private boolean getUserCurrentCookie(ActionContext actionContext) throws Exception {
    Map<String, String> dataMap = UserCurrentCookie
            .getCurrentData((HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST));
    String account = StringUtils.defaultString(dataMap.get("account"));
    String currentId = StringUtils.defaultString(dataMap.get("currentId"));
    //String sessionId = StringUtils.defaultString( dataMap.get("sessionId") );
    if (StringUtils.isBlank(account) || currentId.length() != 36 /*|| StringUtils.isBlank(sessionId)*/ ) {
        return false;
    }
    // ? UserCurrentCookie  sessionId ? sessionId ?
    if (this.uSessLogHelper.countByCurrent(account, currentId) > 0) { // this.uSessLogHelper.countByCurrent(account, currentId, sessionId) >0           
        accountObj = new AccountVO();
        ((AccountVO) accountObj).setAccount(account);
        DefaultResult<AccountVO> result = this.accountService.findByUK(((AccountVO) accountObj));
        if (result.getValue() == null) {
            accountObj = null;
        } else {
            accountObj = result.getValue();
        }
    }
    return (accountObj != null && !StringUtils.isBlank(accountObj.getAccount()));
}

From source file:com.netsteadfast.greenstep.publish.impl.SystemMessagePublishServiceImpl.java

@Override
public String getId() throws Exception {
    return StringUtils.defaultString(this.request.getParameter("id")).trim();
}

From source file:de.blizzy.documentr.web.Functions.java

public static String getSystemSetting(String key) {
    return StringUtils.defaultString(systemSettingsStore.getSetting(key));
}

From source file:edu.sabanciuniv.sentilab.sare.models.base.PersistentObject.java

/**
 * Sets any other data attached to this object.
 * @param otherData the {@link String} object containing other data (should be a valid stringified JSON object).
 * @return the {@code this} object./* ww  w  . j a  v  a 2 s .com*/
 * @throws IllegalArgumentException when the passed string cannot be parsed to a valid JSON object.
 */
public PersistentObject setOtherData(String otherData) {
    if (otherData != null) {
        JsonElement tmpJsonData = new JsonParser().parse(StringUtils.defaultString(otherData));
        if (tmpJsonData.isJsonObject()) {
            this.setOtherData(tmpJsonData.getAsJsonObject());
        } else {
            throw new IllegalArgumentException(
                    "the argument 'otherData' must be a valid stringified JSON object");
        }
    } else {
        this.setOtherData((JsonObject) null);
    }

    return this;
}

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

@Action(value = "resource-descriptors", results = { @Result(name = "success", location = "json.jsp") })
public String execute() throws Exception {
    int int1 = 401, int0 = 0;
    String string1 = null;//ww  w  .ja  v  a 2 s . c  om
    URL url1 = null;
    URI uri1 = null;
    HttpGet httpGet1 = null;
    HttpResponse httpResponse1 = null;
    HttpEntity httpEntity1 = null;
    HttpPost httpPost1 = null;
    HttpHost httpHost1 = null;
    DefaultHttpClient httpClient1 = null;
    File file1 = null;
    InputStream inputStream1 = null;
    OutputStream outputStream1 = null;
    BeanComparator beanComparator1 = null;
    List<Map<String, Object>> list1 = null, list2 = null;
    Map<String, Object> map1 = null;
    Object object1 = null;
    int toIndex = rows * page;
    int fromIndex = toIndex - rows;
    GridModel1 jsonObject1 = null;
    Gson gson = null;
    Long long1 = -1L;
    java.util.Date date1 = null;
    URIBuilder uriBuilder1 = null;
    Node node1 = null;
    Element element1 = null;
    NodeList nodeList1 = null;
    Document document1 = null;
    DocumentBuilder documentBuilder1 = null;
    DocumentBuilderFactory documentBuilderFactory1 = null;
    org.joda.time.DateTime dateTime1 = null, dateTime2 = null;

    try {
        if (StringUtils.isNotEmpty(sid) && StringUtils.isNotEmpty(uid) && StringUtils.isNotEmpty(pid)) {
            sid = new String(Base64.decodeBase64(sid.getBytes()));
            uid = new String(Base64.decodeBase64(uid.getBytes()));
            pid = new String(Base64.decodeBase64(pid.getBytes()));
            httpClient1 = new DefaultHttpClient();
            url1 = new URL(sid);
            uriBuilder1 = new URIBuilder(sid);
            uriBuilder1.setParameter("j_username", uid);
            uriBuilder1.setParameter("j_password", pid);
            uriBuilder1.setPath(url1.getPath() + "/rest/resources" + urlString);
            uriBuilder1.setUserInfo(uid, pid);
            uri1 = uriBuilder1.build();
            httpGet1 = new HttpGet(uri1);
            httpResponse1 = httpClient1.execute(httpGet1);
            int1 = httpResponse1.getStatusLine().getStatusCode();
            if (int1 == HttpStatus.SC_OK) {
                httpEntity1 = httpResponse1.getEntity();
                inputStream1 = httpResponse1.getEntity().getContent();
                if (inputStream1 != null) {
                    documentBuilderFactory1 = DocumentBuilderFactory.newInstance();
                    documentBuilder1 = documentBuilderFactory1.newDocumentBuilder();
                    document1 = documentBuilder1.parse(inputStream1);
                    document1.getDocumentElement().normalize();
                    nodeList1 = document1.getElementsByTagName("resourceDescriptor");
                    int1 = nodeList1.getLength();
                    list1 = new ArrayList<Map<String, Object>>();
                    for (int0 = 0; int0 < int1; int0++) {
                        node1 = nodeList1.item(int0);
                        if (node1.getNodeType() == Node.ELEMENT_NODE) {
                            element1 = (Element) node1;
                            map1 = new HashMap<String, Object>();
                            map1.put("wsType", element1.getAttribute("wsType"));
                            map1.put("uriString", element1.getAttribute("uriString"));
                            string1 = getTagValue("label", element1);
                            map1.put("label1", StringUtils.defaultString(string1));
                            string1 = getTagValue("description", element1);
                            map1.put("description", StringUtils.defaultString(string1));
                            string1 = getTagValue("creationDate", element1);
                            long1 = (string1 == null) ? -1L
                                    : NumberUtils.toLong(StringUtils.trim(string1), -1L);
                            if (long1 > 0) {
                                if (StringUtils.isNotBlank(timeZone1)) {
                                    dateTime1 = new org.joda.time.DateTime(long1);
                                    dateTime2 = dateTime1.withZone(DateTimeZone.forID(timeZone1));
                                    date1 = dateTime2.toLocalDateTime().toDate();
                                } else {
                                    date1 = new java.util.Date(long1);
                                }
                            } else {
                                date1 = null;
                            }
                            map1.put("creationDate", date1);
                            map1.put("type1", getText(element1.getAttribute("wsType")));
                            list1.add(map1);
                        }
                    }
                }
                EntityUtils.consume(httpEntity1);
            }
        }
    } catch (UnsupportedEncodingException | URISyntaxException | ParserConfigurationException
            | SAXException exception1) {
        exception1.printStackTrace();
        return ERROR;
    } catch (org.apache.http.conn.HttpHostConnectException | java.net.NoRouteToHostException
            | java.net.MalformedURLException | java.net.UnknownHostException exception1) {
        exception1.printStackTrace();
        return ERROR;
    } catch (IOException exception1) {
        httpGet1.abort();
        exception1.printStackTrace();
        return ERROR;
    } finally {
        if (httpClient1 != null)
            httpClient1.getConnectionManager().shutdown();
        if (list1 != null) {
            records = list1.size();
            if (list1.size() > 0) {
                if (StringUtils.isNotEmpty(sidx)) {
                    if (StringUtils.equals(sord, "desc")) {
                        beanComparator1 = new BeanComparator(sidx,
                                new ReverseComparator(new ComparableComparator()));
                    } else {
                        beanComparator1 = new BeanComparator(sidx);
                    }
                    Collections.sort(list1, beanComparator1);
                }
                if (StringUtils.isNotBlank(searchField) && StringUtils.isNotEmpty(searchOper)) {
                    Iterator iterator1 = list1.iterator();
                    while (iterator1.hasNext()) {
                        map1 = (Map<String, Object>) iterator1.next();
                        for (Map.Entry<String, Object> entry1 : map1.entrySet()) {
                            if (StringUtils.equals(entry1.getKey(), searchField)) {
                                object1 = entry1.getValue();
                                if (searchFilter(searchField, searchOper, searchString, object1))
                                    iterator1.remove();
                                break;
                            }
                        }
                    }
                    records = list1.size();
                }
                if (toIndex > records)
                    toIndex = records;
                if (fromIndex > toIndex) {
                    fromIndex = toIndex - rows;
                    if (fromIndex < 0)
                        fromIndex = 0;
                }
                if (list1.size() > 0 && fromIndex >= 0 && toIndex <= list1.size() && fromIndex <= toIndex)
                    list2 = list1.subList(fromIndex, toIndex);

            }
            total = (int) Math.ceil((double) records / (double) rows);
            if (page > total)
                page = total;
            jsonObject1 = new GridModel1(rows, page, sord, sidx, searchField, searchString, searchOper, total,
                    records, id, list2);
            gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss.SSS").create();
            jsonData = gson.toJson(jsonObject1);
        }
        IOUtils.closeQuietly(inputStream1);
    }
    return SUCCESS;
}

From source file:io.github.robwin.swagger2markup.builder.document.PathsDocument.java

private String parameterDescription(Operation operation, Parameter parameter) throws IOException {
    String description;//from  ww  w.  ja v  a 2  s . co  m
    if (handWrittenDescriptionsEnabled) {
        String summary = operation.getSummary();
        String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
        String parameterName = parameter.getName();
        if (StringUtils.isNotBlank(operationFolder) && StringUtils.isNotBlank(parameterName)) {
            description = handWrittenPathDescription(operationFolder + "/" + parameterName,
                    DESCRIPTION_FILE_NAME);
            if (StringUtils.isBlank(description)) {
                if (logger.isInfoEnabled()) {
                    logger.info(
                            "Hand-written description file cannot be read. Trying to use description from Swagger source.");
                }
                description = StringUtils.defaultString(parameter.getDescription());
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info(
                        "Hand-written description file cannot be read, because summary of operation or name of parameter is empty. Trying to use description from Swagger source.");
            }
            description = StringUtils.defaultString(parameter.getDescription());
        }
    } else {
        description = StringUtils.defaultString(parameter.getDescription());
    }
    return description;
}

From source file:ext.usercenter.UserAuthURLFilter.java

/**
 * ???URI// www .j  a  v  a 2 s  .  c o  m
 */
private static String getRedirectURI(String uri, String referer, String... param) {
    StringBuilder uriBuilder = new StringBuilder(uri);
    uriBuilder.append(getURIQueryStringPrefix(uri));
    String encodeReferer = null;
    try {
        encodeReferer = URLEncoder.encode(StringUtils.defaultString(referer), "utf-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    uriBuilder.append("referer=").append(encodeReferer);
    if (ArrayUtils.isNotEmpty(param)) {
        for (String p : param) {
            uriBuilder.append("&").append(p);
        }
    }
    return uriBuilder.toString();
}

From source file:com.xpn.xwiki.objects.BaseObject.java

private Element exportProperty(String propertyName, String propertyValue) {
    Element propertyElement = new DOMElement(propertyName);
    propertyElement.addText(StringUtils.defaultString(propertyValue));
    return propertyElement;
}

From source file:com.pidoco.juri.JURI.java

/**
 * BEWARE, this cannot be used to escape many http scheme specific parts, as possibly other scheme's specific parts.
 * Problem is the different escaping of some characters depending on the (semantic) location.
 *
 * <p>If no scheme is currently set the scheme will become 'unspecified'.</p>
 *
 * @param schemeSpecificPart null or "" not allowed.
 *///from w  w w. j  av a  2 s.c  o  m
public JURI setSchemeSpecificPart(String schemeSpecificPart) {
    schemeSpecificPart = StringUtils.defaultString(schemeSpecificPart);

    setRawSchemeSpecificPart(UrlEscapers.urlFragmentEscaper().escape(schemeSpecificPart));
    return this;
}