當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtils.defaultString方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.StringUtils.defaultString方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.defaultString方法的具體用法?Java StringUtils.defaultString怎麽用?Java StringUtils.defaultString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.StringUtils的用法示例。


在下文中一共展示了StringUtils.defaultString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: normalizeServerUrl

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
/**
 * Fix a serverUrl.
 *
 * @param serverUrl the server URL.
 * @return the normalized server URL.
 */
@NonNull
public static String normalizeServerUrl(@CheckForNull String serverUrl) {
    serverUrl = StringUtils.defaultString(serverUrl);
    try {
        URI uri = new URI(serverUrl).normalize();
        String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            // we only expect http / https, but also these are the only ones where we know the authority
            // is server based, i.e. [[email protected]]server[:port]
            // DNS names must be US-ASCII and are case insensitive, so we force all to lowercase

            String host = uri.getHost() == null ? null : uri.getHost().toLowerCase(Locale.ENGLISH);
            int port = uri.getPort();
            if ("http".equals(scheme) && port == 80) {
                port = -1;
            } else if ("https".equals(scheme) && port == 443) {
                port = -1;
            }
            serverUrl = new URI(
                    scheme,
                    uri.getUserInfo(),
                    host,
                    port,
                    uri.getPath(),
                    uri.getQuery(),
                    uri.getFragment()
            ).toASCIIString();
        }
    } catch (URISyntaxException e) {
        // ignore, this was a best effort tidy-up
    }
    return serverUrl.replaceAll("/$", "");
}
 
開發者ID:jenkinsci,項目名稱:gitea-plugin,代碼行數:40,代碼來源:GiteaServers.java

示例2: PullProcessorColumn

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
/**
 * Creates the column and buffers its meta data.
 */
public PullProcessorColumn() {
  super();
  columnName = xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.NAME_ATTRIBUTE);
  dataType = DataType.valueOf(xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.TYPE_ATTRIBUTE));
  defaultValue = StringUtils.defaultString(xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.DEFAULT_ATTRIBUTE));

  try {
    // not all datatypes need a width
    if (dataType.hasWidth()) {
      // The use of null indicates that although a scale should exist none
      // was provided.
      String widthString = xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.WIDTH_ATTRIBUTE);
      width = StringUtils.isEmpty(widthString) ? null : Integer.valueOf(widthString);
    } else {
      width = 0;
    }

    // not all datatypes need a scale
    if (dataType.hasScale()) {
      // The use of null indicates that although a scale should exist none
      // was provided.
      String scaleString = xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.SCALE_ATTRIBUTE);
      scale = StringUtils.isEmpty(scaleString) ? null : Integer.valueOf(scaleString);
    } else {
      scale = 0;
    }

    String nullableString = xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.NULLABLE_ATTRIBUTE);
    nullable = StringUtils.isEmpty(nullableString) ? null : Boolean.valueOf(nullableString);

    String primaryKeyString = xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.PRIMARYKEY_ATTRIBUTE);
    primaryKey = StringUtils.isEmpty(primaryKeyString) ? null : Boolean.valueOf(primaryKeyString);

    String autoNumString = xmlStreamReader.getAttributeValue(XmlDataSetNode.URI, XmlDataSetNode.AUTONUMBER_ATTRIBUTE);
    autonumbered = StringUtils.isNotEmpty(autoNumString);
    autonumberStart = autonumbered ? Integer.valueOf(autoNumString) : null;

  } catch (NumberFormatException nfe) {
    throw new RuntimeException("Error parsing metadata for column [" + columnName + "]", nfe);
  }

}
 
開發者ID:alfasoftware,項目名稱:morf,代碼行數:46,代碼來源:XmlDataSetProducer.java

示例3: getDefaultValue

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
/**
 * @see org.alfasoftware.morf.metadata.Column#getDefaultValue()
 */
@Override
public String getDefaultValue() {
  return StringUtils.defaultString(defaultValue);
}
 
開發者ID:alfasoftware,項目名稱:morf,代碼行數:8,代碼來源:ColumnBean.java

示例4: getMessage

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
/**
 * Gets a short message summarising the exception.
 * <p>
 * The message returned is of the form
 * {ClassNameWithoutPackage}: {ThrowableMessage}
 *
 * @param th  the throwable to get a message for, null returns empty string
 * @return the message, non-null
 * @since Commons Lang 2.2
 */
public static String getMessage(Throwable th) {
    if (th == null) {
        return "";
    }
    String clsName = ClassUtils.getShortClassName(th, null);
    String msg = th.getMessage();
    return clsName + ": " + StringUtils.defaultString(msg);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:ExceptionUtils.java


注:本文中的org.apache.commons.lang.StringUtils.defaultString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。