本文整理汇总了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("/$", "");
}
示例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);
}
}
示例3: getDefaultValue
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* @see org.alfasoftware.morf.metadata.Column#getDefaultValue()
*/
@Override
public String getDefaultValue() {
return StringUtils.defaultString(defaultValue);
}
示例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);
}