当前位置: 首页>>代码示例>>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;未经允许,请勿转载。