下面列出了org.apache.commons.lang3.StringUtils#isNotBlank ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void writeMainMethodAnnotations(TextOutputStream stream, AMLTestCase testCase) throws IOException {
String id = testCase.getId();
String description = testCase.getDescription();
String reference = StringUtils.defaultString(testCase.getReference());
if (StringUtils.isNotBlank(id)) {
stream.writeLine(1, "@%s(\"%s\")", Id.class.getSimpleName(), StringUtil.toJavaString(id));
}
if (StringUtils.isNotBlank(description)) {
stream.writeLine(1, "@%s(\"%s\")", Description.class.getSimpleName(), StringUtil.toJavaString(description));
}
stream.writeLine(1, "@%s(order = %s, matrixOrder = %s)", ExecutionSequence.class.getSimpleName(), testCase.getExecOrder(), testCase.getMatrixOrder());
stream.writeLine(1, "@%s(%s)", Hash.class.getSimpleName(), testCase.getHash());
stream.writeLine(1, "@%s(%s.%s)", Type.class.getSimpleName(), AMLBlockType.class.getSimpleName(), testCase.getBlockType().name());
stream.writeLine(1, "@%s(%s)", AddToReport.class.getSimpleName(), testCase.isAddToReport());
stream.writeLine(1, "@%s(%s)", Tags.class.getSimpleName(), testCase.getTagsAsString());
stream.writeLine(1, "@%s(\"%s\")", Reference.class.getSimpleName(), StringUtil.toJavaString(reference));
}
/***
* 获取字段值
* @param cellData
* @return
*/
// protected Object getFieldValue(Object root, FieldModel field, Object defValue)
protected Object getFieldValue(CellContextData cellData){
FieldModel field = cellData.getFieldModel();
Object fieldValue = null;
if(StringUtils.isNotBlank(field.getVar())){
fieldValue = cellData.parseValue(field.getVar());
}else if(field.getValue()!=null){
fieldValue = field.getValue();
}else if(StringUtils.isNotBlank(field.getDefaultValue())){
fieldValue = cellData.parseValue(field.getDefaultValue());
}
if(fieldValue==null){
fieldValue = cellData.getDefFieldValue();
}
fieldValue = formatValue(fieldValue, field.getDataFormat());
return fieldValue;
}
public void setCompanyOfficeListJson(String jsonString) {
List<String> list = JsonMapper.fromJson(jsonString, List.class);
if (list != null){
for (String val : list){
if (StringUtils.isNotBlank(val)){
CompanyOffice e = new CompanyOffice();
e.setCompanyCode(this.companyCode);
e.setOfficeCode(val);
e.setIsNewRecord(true);
this.companyOfficeList.add(e);
}
}
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (ACTION.equals(localName)) {
action = ActionVerb.NONE;
actionAttributes = null;
return;
}
if (action.doDelete() && ReferenceConverter.isReferenceType(originalType) && originalType.equals(localName)) {
return;
}
if (complexTypeStack.isEmpty()) {
return;
}
String expectedLocalName = complexTypeStack.peek().getLeft().getName();
if (localName.equals(expectedLocalName)) {
if (elementValue.length() > 0) {
String text = StringUtils.trimToEmpty(elementValue.toString());
if (StringUtils.isNotBlank(text)) {
parseCharacters(text);
}
}
if (complexTypeStack.size() > 1) {
complexTypeStack.pop();
} else if (complexTypeStack.size() == 1) {
recordParsingComplete();
}
}
elementValue.setLength(0);
}
private static Path determineOutputDirectory(final CommandLine cmd) {
final String value = cmd.getOptionValue(OUTPUT.getOpt());
final Path fir;
if (StringUtils.isNotBlank(value)) {
fir = Paths.get(value);
if ((!Files.exists(fir) && !fir.toFile().mkdirs()) || !Files.isDirectory(fir)) {
throw new IllegalStateException(String.format("Invalid target directory %s specified", value));
}
} else {
fir = Paths.get(""/* cwd */);
}
return fir;
}
/**
* Helper to get the link to access the current-site signup tool page in a site. Added to events.
*/
private String getSiteAccessUrl(String siteId) {
if (StringUtils.isNotBlank(siteId)) {
return sakaiFacade.getServerConfigurationService().getPortalUrl() + "/site/" + siteId + "/page/" + sakaiFacade.getCurrentPageId();
}
return null;
}
/**
*
* @param url
* @return
*/
public boolean isProxySet(String url) {
for (String excludedUrl : proxyExclusionUrlList) {
if (url.contains(excludedUrl) && StringUtils.isNotBlank(excludedUrl)) {
LOGGER.debug("Proxy Not Set due to exclusion with : " + excludedUrl);
return false;
}
}
LOGGER.debug("isProxySet: " + (StringUtils.isNotEmpty(proxyHost) && StringUtils.isNotEmpty(proxyPort)));
return StringUtils.isNotEmpty(proxyHost) && StringUtils.isNotEmpty(proxyPort);
}
private static String parseSql(String fileName,XNode node,Map<String, String> includeContents) {
StringBuilder sql = new StringBuilder();
NodeList children = node.getNode().getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
XNode child = node.newXNode(children.item(i));
String data = null;
if("#text".equals(child.getName())){
data = child.getStringBody("");
}else if("include".equals(child.getName())){
String refId = child.getStringAttribute("refid");
data = child.toString();
if(includeContents.containsKey(refId)){
data = data.replaceAll("<\\s?include.*("+refId+").*>", includeContents.get(refId));
}else{
log.error(String.format(">>>>>Parse SQL from mapper[%s-%s] error,not found include key:%s", fileName,node.getStringAttribute("id"),refId));
}
}else{
data = child.toString();
// if(child.getStringBody().contains(">") || child.getStringBody().contains("<")){
// data = data.replace(child.getStringBody(), "<![CDATA["+child.getStringBody()+"]]");
// }
}
data = data.replaceAll("\\n+|\\t+", "");
if(StringUtils.isNotBlank(data)){
sql.append(data).append("\t").append("\n");
}
}
// return sql.toString().replaceAll("\\s{2,}", " ");
return sql.toString();
}
/**
* Determine default authentication method.
*
* @return the default authn method if one is specified, or null.
*/
protected String determineDefaultAuthenticationMethod() {
if (StringUtils.isNotBlank(this.defaultAuthenticationMethod)) {
logger.debug("{} is configured to use the default authentication method [{}]. ",
this.getClass().getSimpleName(),
this.defaultAuthenticationMethod);
return this.defaultAuthenticationMethod;
}
logger.debug("No default authentication method is defined. Returning null...");
return null;
}
@Override /* PojoSwap */
public String swap(BeanSession session, DateTime o) {
DateTimeFormatter dateFormatter = this.dateFormatter;
if( StringUtils.isNotBlank(session.getProperty("format", String.class, RFC3339Utils.UTC_STANDARD_FMT.toString()))) {
dateFormatter = DateTimeFormat.forPattern(session.getProperty("format", String.class, RFC3339Utils.UTC_STANDARD_FMT.toString()));
}
return dateFormatter.print(o);
}
public HiveConf getConfigurationFromFiles(final String configFiles) {
final HiveConf hiveConfig = new HiveConf();
if (StringUtils.isNotBlank(configFiles)) {
for (final String configFile : configFiles.split(",")) {
hiveConfig.addResource(new Path(configFile.trim()));
}
}
return hiveConfig;
}
public void add(String clientKey, ClientNode node) {
//1.添加客户端
clientDao.add(clientKey, node);
if (node.getStatus() != CommonConstant.ClientStatus.ONLINE) {
return;
}
//2.开始为客户端绑定服务端口
//绑定客户端服务端口
Map<Object, ProxyRealServer> keyToNode = node.getServerPort2RealServer();
for (Map.Entry<Object, ProxyRealServer> keyToProxyRealServer : keyToNode.entrySet()) {
ProxyRealServer proxyRealServer = keyToProxyRealServer.getValue();
/**
* 如果是HTTP代理,并且设置了通过域名访问,则不需要单独绑定端口
*/
if (proxyRealServer.getProxyType() == CommonConstant.ProxyType.HTTP && StringUtils.isNotBlank(proxyRealServer.getDomain())) {
ServerBeanManager.getProxyChannelService().addByServerdomain(proxyRealServer.getDomain(), proxyRealServer);
proxyRealServer.setStatus(CommonConstant.ProxyStatus.ONLINE);
continue;
}
if (proxyRealServer.getProxyType() == CommonConstant.ProxyType.HTTP) {
//http 端口代理绑定
HttpProxy(keyToProxyRealServer.getKey(), proxyRealServer);
} else if (proxyRealServer.getProxyType() == CommonConstant.ProxyType.TCP) {
//tcp 端口代理绑定
TCPProxy(keyToProxyRealServer.getKey(), proxyRealServer);
}
}
}
private void updateVertexProperty(AtlasVertex vertex, String propertyName, String newValue) {
if (StringUtils.isNotBlank(newValue)) {
String currValue = vertex.getProperty(propertyName, String.class);
if (!StringUtils.equals(currValue, newValue)) {
vertex.setProperty(propertyName, newValue);
}
}
}
public void saveOrUpdate(Dict dict) {
if (StringUtils.isNotBlank(dict.getId())){
Dict tempDict = dictDao.findById(dict.getId()).orElseThrow(ResourceNotFoundException::new);
BeanUtil.copyProperties(tempDict, dict);
}
dictDao.save(dict);
}
/**
* Splits the offset in the form of (<column1>=<value1>::<column2>=<value2>::<column3>=<value3>) into a map of columns and values
* @param lastOffset the last offset for the current table.
* @return Map of columns to values
*/
public static Map<String, String> getColumnsToOffsetMapFromOffsetFormat(String lastOffset) {
Map<String, String> offsetColumnsToOffsetMap = new HashMap<>();
if (StringUtils.isNotBlank(lastOffset)) {
Iterator<String> offsetColumnsAndOffsetIterator = OFFSET_COLUMN_SPLITTER.split(lastOffset).iterator();
while (offsetColumnsAndOffsetIterator.hasNext()) {
String offsetColumnAndOffset = unescapeOffsetValue(offsetColumnsAndOffsetIterator.next());
String[] offsetColumnOffsetSplit = offsetColumnAndOffset.split("=", 2);
String offsetColumn = offsetColumnOffsetSplit[0];
String offset = offsetColumnOffsetSplit[1];
offsetColumnsToOffsetMap.put(offsetColumn, offset);
}
}
return offsetColumnsToOffsetMap;
}
@Override
public void create(ModelControllerClient client, CLIWrapper cli) throws Exception {
// /subsystem=elytron/server-ssl-context=twoWaySSC:add(key-manager=twoWayKM,protocols=["TLSv1.2"],
// trust-manager=twoWayTM,security-domain=test,need-client-auth=true)
StringBuilder sb = new StringBuilder("/subsystem=elytron/server-ssl-context=").append(name).append(":add(");
if (StringUtils.isNotBlank(keyManager)) {
sb.append("key-manager=\"").append(keyManager).append("\", ");
}
if (protocols != null) {
StringJoiner joiner = new StringJoiner(", ");
for (String s : protocols) {
String s1 = "\"" + s + "\"";
joiner.add(s1);
}
sb.append("protocols=[")
.append(joiner.toString()).append("], ");
}
if (StringUtils.isNotBlank(trustManager)) {
sb.append("trust-manager=\"").append(trustManager).append("\", ");
}
if (StringUtils.isNotBlank(securityDomain)) {
sb.append("security-domain=\"").append(securityDomain).append("\", ");
}
if (authenticationOptional != null) {
sb.append("authentication-optional=").append(authenticationOptional).append(", ");
}
sb.append("need-client-auth=").append(needClientAuth).append(")");
cli.sendLine(sb.toString());
}
private void execProcess(IActionReport report, long timeout, String... cmdarray) throws Exception {
timeout = timeout > 0 ? timeout : DEFAULT_EXEC_TIMEOUT;
File stdOutFile = File.createTempFile("stdout", ".txt");
File stdErrFile = File.createTempFile("stderr", ".txt");
Process process = new ProcessBuilder(cmdarray)
.redirectOutput(stdOutFile)
.redirectError(stdErrFile)
.start();
try (AutoCloseable stdOutFileDeleter = stdOutFile::delete;
AutoCloseable stdErrFileDeleter = stdErrFile::delete) {
boolean finished = process.waitFor(timeout, MILLISECONDS);
if (!finished) {
process.destroyForcibly();
}
int exitCode = finished ? process.exitValue() : -1;
String stdOut = readFileToString(stdOutFile, defaultCharset());
String stdErr = readFileToString(stdErrFile, defaultCharset());
logger.debug("Script run stdout: {}", stdOut);
logger.debug("Script run stderr: {}", stdErr);
StatusType status = exitCode != 0 ? StatusType.FAILED : StatusType.PASSED;
report.createMessage(status, MessageLevel.INFO, "Script run stdout: " + stdOut);
if(StringUtils.isNotBlank(stdErr)) {
report.createMessage(StatusType.FAILED, MessageLevel.ERROR, "Script run stderr: " + stdErr);
}
if (!finished) {
throw new Exception(format("Did not finish in specified timeout: %d ms", timeout));
}
if(exitCode != 0) {
throw new Exception("Exit code: " + exitCode);
}
}
}
/**
* Parses the entries contained in an RSS feed, extracts the enclosures, converts them to an {@link Attachment}
* adds them to the map with the entry uri as key.
* <p>The RSS spec says there is only one enclosure per item so this is what we work with. We don't actually check this so it's possible
* that if you have more than one enclosure attached to an item that only the latest one will be presented in the end.
*
* @param feed
* @return
*/
public static Map<String, Attachment> parseFeedEnclosures(SyndFeed feed) {
Map<String,Attachment> attachments = new HashMap<String,Attachment>();
// image mime types that are ok to be rendered as an image
List<String> imageTypes = new ArrayList<String>();
imageTypes.add("image/jpeg");
imageTypes.add("image/gif");
imageTypes.add("image/png");
imageTypes.add("image/jpg");
List<SyndEntry> entries = feed.getEntries();
for(SyndEntry entry: entries) {
//get entry uri, but it could be blank so if so, skip this item
if(StringUtils.isBlank(entry.getUri())) {
continue;
}
//for each enclosure attached to an entry get the first one and use that.
List<SyndEnclosure> enclosures = entry.getEnclosures();
for(SyndEnclosure e: enclosures) {
//convert to an Attachment
Attachment a = new Attachment();
a.setUrl(e.getUrl());
a.setDisplayLength(formatLength(e.getLength()));
a.setType(e.getType());
//process the url into a displayname (get just the filename from the full URL)
String displayName = StringUtils.substringAfterLast(e.getUrl(), "/");
if(StringUtils.isNotBlank(displayName)){
a.setDisplayName(displayName);
} else {
a.setDisplayName(Messages.getString("view.attachment.default"));
}
//check if its an iamge we are able to display as the thumbnail for the entry
if(imageTypes.contains(e.getType())){
a.setImage(true);
}
attachments.put(entry.getUri(), a);
}
}
return attachments;
}
/**
* Build a {@link TimeRange} from the supplied request parameters. If the parameters are supplied but invalid, an
* {@link IllegalArgumentException} will be thrown.
*
* @param params the request params
* @return {@link TimeRange} if valid or null if not
*/
@SuppressWarnings("deprecation")
private TimeRange buildTimeRangeFromRequest(final Map<String, Object> params) {
// OPTIONAL params
String firstDate = null;
String lastDate = null;
if (params.containsKey("firstDate")) {
firstDate = (String) params.get("firstDate");
}
if (params.containsKey("lastDate")) {
lastDate = (String) params.get("lastDate");
}
// check date params are correct (length is ok)
if (StringUtils.isNotBlank(firstDate) && StringUtils.length(firstDate) != 10) {
throw new IllegalArgumentException(
"firstDate must be in the format yyyy-MM-dd");
}
if (StringUtils.isNotBlank(lastDate) && StringUtils.length(lastDate) != 10) {
throw new IllegalArgumentException(
"lastDate must be in the format yyyy-MM-dd");
}
// if we have dates, create a range for filtering
// these need to be converted to Time and then a TimeRange created. This is what the CalendarService uses to filter :(
// note that our firstDate is always the beginning of the day and the lastDate is always the end
// this is to ensure we get full days
TimeRange range = null;
if (StringUtils.isNotBlank(firstDate) && StringUtils.isNotBlank(lastDate)) {
final Time start = this.timeService.newTimeLocal(
Integer.valueOf(StringUtils.substring(firstDate, 0, 4)),
Integer.valueOf(StringUtils.substring(firstDate, 5, 7)),
Integer.valueOf(StringUtils.substring(firstDate, 8, 10)),
0, 0, 0, 0);
final Time end = this.timeService.newTimeLocal(
Integer.valueOf(StringUtils.substring(lastDate, 0, 4)),
Integer.valueOf(StringUtils.substring(lastDate, 5, 7)),
Integer.valueOf(StringUtils.substring(lastDate, 8, 10)),
23, 59, 59, 999);
range = this.timeService.newTimeRange(start, end, true, true);
}
return range;
}
private User fromUser(User from, final String tenantId) {
User user = null;
if (from != null && StringUtils.isNotBlank(tenantId)) {
Map<String, String> extensions = new HashMap<>();
extensions.put(Vocabulary.TENANT, tenantId);
Map<String, String> metadata = from.getMetadata();
if (metadata != null && !metadata.isEmpty())
extensions.putAll(metadata);
String sourcedId = from.getSourcedId();
if (StringUtils.isBlank(sourcedId))
sourcedId = UUID.randomUUID().toString();
user = new User.Builder()
.withEmail(from.getEmail())
.withDateLastModified(Instant.now())
.withFamilyName(from.getFamilyName())
.withGivenName(from.getMiddleName())
.withGivenName(from.getGivenName())
.withIdentifier(from.getIdentifier())
.withUserIds(from.getUserIds())
.withPassword(from.getPassword())
.withMetadata(metadata)
.withPhone(from.getPhone())
.withRole(from.getRole())
.withSms(from.getSms())
.withSourcedId(sourcedId)
.withStatus(from.getStatus())
.withUserIds(from.getUserIds())
.withUsername(from.getUsername())
.withEnabledUser(from.isEnabledUser())
.build();
}
return user;
}