本文整理汇总了Java中org.apache.commons.lang.StringUtils.trim方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.trim方法的具体用法?Java StringUtils.trim怎么用?Java StringUtils.trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.StringUtils
的用法示例。
在下文中一共展示了StringUtils.trim方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logMessage
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
*
* log message
*
* @param message
*/
public void logMessage(String message){
for(AbstractJobLogger jobLogger: loggers){
if(StringUtils.isNotBlank(message)){
message = StringUtils.trim(message);
jobLogger.log(message);
}
logger.debug("Logged message {} on {}", message, jobLogger.getClass().getName());
}
}
示例2: prepareUIXML
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* Generate basic properties that are common in all components.
*/
public void prepareUIXML() {
componentId = StringUtils.trim(typeBaseComponent.getId());
componentName=StringUtils.trim(typeBaseComponent.getName());
if(StringUtils.isBlank(componentName)){
componentName=componentId;
}
name_suffix = uiComponent.getComponentName() + "_";
LOGGER.debug("Preparing basic properties for component Name:{} and Id{}", componentName,componentId);
propertyMap.put(NAME, componentName);
propertyMap.put(BATCH, typeBaseComponent.getBatch().toString());
uiComponent.setComponentLabel(componentName);
uiComponent.setParent(container);
uiComponent.setComponentId(componentId);
currentRepository.getComponentUiFactory().put(componentId, uiComponent);
}
示例3: loadPackagesFromPropertyFileSettingFolder
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public void loadPackagesFromPropertyFileSettingFolder() {
Properties properties = new Properties();
IFolder folder = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject().getFolder(
PathConstant.PROJECT_RESOURCES_FOLDER);
IFile file = folder.getFile(PathConstant.EXPRESSION_EDITOR_EXTERNAL_JARS_PROPERTIES_FILES);
try {
LOGGER.debug("Loading property file");
targetList.removeAll();
if (file.getLocation().toFile().exists()) {
FileInputStream inStream = new FileInputStream(file.getLocation().toString());
properties.load(inStream);
for (Object key : properties.keySet()) {
String jarFileName = StringUtils.trim(StringUtils.substringAfter((String) key, Constants.DASH));
if (BuildExpressionEditorDataSturcture.INSTANCE.getIPackageFragment(jarFileName) != null) {
targetList.add((String) key+SWT.SPACE+Constants.DASH+SWT.SPACE+properties.getProperty((String)key));
}
}
}
} catch (IOException | RuntimeException exception) {
LOGGER.error("Exception occurred while loading jar files from projects setting folder", exception);
}
}
示例4: checkIfDuplicateComponentExists
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private boolean checkIfDuplicateComponentExists(String newNameORComponentId, Component currentComponent,
boolean checkId) {
newNameORComponentId=StringUtils.trim(newNameORComponentId);
if (!getChildren().isEmpty()) {
for (Object object : getChildren()) {
if ( object instanceof Component && !object.equals(currentComponent)) {
Component component = (Component) object;
if (checkId && StringUtils.equalsIgnoreCase(StringUtils.trim(component.getComponentId()), newNameORComponentId)) {
LoggerUtil.getLoger(this.getClass()).trace("Duplicate component exists.");
return true;
}else if(!checkId && StringUtils.equalsIgnoreCase(StringUtils.trim(component.getComponentLabel().getLabelContents()), newNameORComponentId)) {
LoggerUtil.getLoger(this.getClass()).trace("Duplicate component exists.");
return true;
}
}
}
}
return false;
}
示例5: getServicePortPID
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* This function will be return process ID which running on defined port.
*
* @return the service port pid
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public String getServicePortPID(Properties properties) throws IOException {
int portNumber = Integer.parseInt(properties.getProperty(EXECUTION_TRACKING_PORT));
if (OSValidator.isWindows()) {
ProcessBuilder builder = new ProcessBuilder(new String[] { "cmd",
"/c", "netstat -a -o -n |findstr :" + portNumber });
Process process = builder.start();
InputStream inputStream = process.getInputStream();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream));
String str = bufferedReader.readLine();
str = StringUtils.substringAfter(str, "LISTENING");
str = StringUtils.trim(str);
return str;
}
return "";
}
示例6: getPrefix
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private String getPrefix(Object node) {
String currentName=((Component) node).getComponentLabel().getLabelContents();
String prefix=currentName;
StringBuffer buffer=new StringBuffer(currentName);
try {
if(buffer.lastIndexOf(UNDERSCORE)!=-1 && (buffer.lastIndexOf(UNDERSCORE)!=buffer.length())){
String substring = StringUtils.trim(buffer.substring(buffer.lastIndexOf(UNDERSCORE)+1,buffer.length()));
if(StringUtils.isNumeric(substring)){
prefix=buffer.substring(0,buffer.lastIndexOf(UNDERSCORE));
}
}}
catch (Exception exception) {
LOGGER.warn("Cannot process component name for detecting prefix : ",exception.getMessage());
}
return prefix;
}
示例7: template
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* Use file based template
* @param fileName path to template in resources
* @param data
* @return
*/
public String template(String fileName, Map<String, Object> data) {
org.apache.velocity.Template t = ve.getTemplate(fileName);
StringWriter writer = new StringWriter();
VelocityContext vc = new VelocityContext(data);
// vc.put("_nl", "\n");//иногда неоткуда взять перенос строки...
t.merge(vc, writer);
return StringUtils.trim(writer.toString());
}
示例8: evaluate
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* Use string as a template
* @param template string, contains template as is
* @param data
* @return
*/
public String evaluate(String template, Map<String, Object> data) {
StringWriter writer = new StringWriter();
VelocityContext vc = new VelocityContext(data);
ve.evaluate(vc, writer, "stub template name", template);
return StringUtils.trim(writer.toString());
}
示例9: handleRequestInternal
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET })
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Integer channelId = ServletRequestUtils.getIntParameter(request, "channelId");
if (request.getParameter("add") != null) {
String url = StringUtils.trim(request.getParameter("add"));
podcastService.createChannel(url);
return new ModelAndView(new RedirectView("podcastChannels.view"));
}
if (request.getParameter("downloadEpisode") != null) {
download(StringUtil.parseInts(request.getParameter("downloadEpisode")));
return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
}
if (request.getParameter("deleteChannel") != null) {
podcastService.deleteChannel(channelId);
return new ModelAndView(new RedirectView("podcastChannels.view"));
}
if (request.getParameter("deleteEpisode") != null) {
for (int episodeId : StringUtil.parseInts(request.getParameter("deleteEpisode"))) {
podcastService.deleteEpisode(episodeId, true);
}
return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
}
if (request.getParameter("refresh") != null) {
if (channelId != null) {
podcastService.refreshChannel(channelId, true);
return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
} else {
podcastService.refreshAllChannels(true);
return new ModelAndView(new RedirectView("podcastChannels.view"));
}
}
return new ModelAndView(new RedirectView("podcastChannels.view"));
}
示例10: firstToUpper
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String firstToUpper(String value){
if(StringUtils.isBlank(value))
return "";
value = StringUtils.trim(value);
String f = StringUtils.substring(value,0,1);
String s = "";
if(value.length() > 1){
s = StringUtils.substring(value,1);
}
return f.toUpperCase() + s;
}
示例11: convertTextToPatterns
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* 把字符串文本转换成一堆Pattern,用于匹配URL
*/
private List<URLPatternHolder> convertTextToPatterns(String text) {
List<URLPatternHolder> list = new ArrayList<URLPatternHolder>();
if (StringUtils.isNotEmpty(text)) {
BufferedReader br = new BufferedReader(new StringReader(text));
int counter = 0;
String line;
while (true) {
counter++;
try {
line = br.readLine();
} catch (IOException ioe) {
throw new IllegalArgumentException(ioe.getMessage());
}
if (line == null) {
break;
}
line = StringUtils.trim(line);
if (StringUtils.isBlank(line)) {
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("Line " + counter + ": " + line);
}
list.add(convertStringToPattern(line));
}
}
return list;
}
示例12: convertTextToPatterns
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* 把字符串文本转换成一堆Pattern,用于匹配URL
*/
private List<ActionPatternHolder> convertTextToPatterns(String text) {
List<ActionPatternHolder> list = new ArrayList<ActionPatternHolder>();
if (StringUtils.isNotEmpty(text)) {
BufferedReader br = new BufferedReader(new StringReader(text));
int counter = 0;
String line;
while (true) {
counter++;
try {
line = br.readLine();
} catch (IOException ioe) {
throw new IllegalArgumentException(ioe.getMessage());
}
if (line == null) {
break;
}
line = StringUtils.trim(line);
if (StringUtils.isBlank(line)) {
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("Line " + counter + ": " + line);
}
list.add(convertStringToPattern(line));
}
}
return list;
}
示例13: inPeriod
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
protected boolean inPeriod(AlarmRule alarmRule) {
String rule = alarmRule.getMatchValue();
if (StringUtils.isEmpty(rule)) {
log.info("rule is empty " + alarmRule);
return false;
}
String periods = StringUtils.substringAfterLast(rule, "@");
if (StringUtils.isEmpty(periods)) {
// 没有时间要求,则任务在报警时间段内
return isInPeriodWhenNoPeriod();
}
Calendar calendar = currentCalendar();
periods = StringUtils.trim(periods);
for (String period : StringUtils.split(periods, ",")) {
String[] startAndEnd = StringUtils.split(period, "-");
if (startAndEnd == null || startAndEnd.length != 2) {
log.error("error period time format in rule : " + alarmRule);
return isInPeriodWhenErrorFormat();
}
String start = startAndEnd[0];
String end = startAndEnd[1];
if (checkInPeriod(calendar, start, end)) {
log.info("rule is in period : " + alarmRule);
return true;
}
}
log.info("rule is not in period : " + alarmRule);
return false;
}
示例14: login
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@ApiOperation("登录")
@PostMapping("/sessions")
public Result login(@RequestBody User user, HttpSession session) {
//log记录信息
logger.debug("method login get param:" + user);
//通过session判断是否已登录
if (TRUE.equals(session.getAttribute(IS_LOGIN))) {
return new Result(false, "您已登录!");
}
//获取参数并trim必要的参数
String username = StringUtils.trim(user.getUsername());
String password = StringUtils.trim(user.getPassword());
//认证并返回结果
if(username == null || password == null) {
return new Result(false, "密码和用户名不能为空");
}
UserExample userExample = new UserExample();
userExample.createCriteria().andUsernameEqualTo(username);
List<User> users = userService.selectByExample(userExample);
User u = users.size() == 0 ? null : users.get(0);
if (u == null) {
return new Result(false, "用户名不存在");
}
if (!u.getPassword().equals(password)) {
return new Result(false, "密码和用户名不匹配");
}
//session记录登录信息
session.setAttribute(IS_LOGIN, TRUE);
session.setAttribute(USER, u);
return new Result(true, u);
}
示例15: add
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@ApiOperation("添加类别")
@PostMapping("/categories")
public Result add(@RequestBody Category category) {
//log记录信息
logger.debug("method add get param:" + category);
//判断空
if(StringUtils.isBlank(category.getName())) {
return new Result(false, "类别名称不能为空");
}
//trim参数
String name = StringUtils.trim(category.getName());
//判断已有
CategoryExample categoryExample = new CategoryExample();
categoryExample.createCriteria().andNameEqualTo(name);
List<Category> categories = categoryService.selectByExample(categoryExample);
if(!categories.isEmpty()) {
return new Result(false, "该类别已存在");
}
//插入DB
category.setName(name);
categoryService.insert(category);
//返回添加的对象
CategoryExample categoryExample1 = new CategoryExample();
categoryExample1.createCriteria().andNameEqualTo(name);
Category c = categoryService.selectByExample(categoryExample1).get(0);
return new Result(true, c);
}