Java Code Examples for org.apache.commons.lang.StringUtils.trimToEmpty()

The following are Jave code examples for showing how to use trimToEmpty() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: instalint   File: Version.java   Source Code and License Vote up 8 votes
private Version(String version) {
  this.name = StringUtils.trimToEmpty(version);
  this.qualifier = StringUtils.substringAfter(this.name, "-");
  String numbers = StringUtils.substringBefore(this.name, "-");
  String[] split = StringUtils.split(numbers, '.');
  if (split.length >= 1) {
    major = split[0];
    normalizedMajor = normalizePart(major);
  }
  if (split.length >= 2) {
    minor = split[1];
    normalizedMinor = normalizePart(minor);
  }
  if (split.length >= 3) {
    patch = split[2];
    normalizedPatch = normalizePart(patch);
  }
  if (split.length >= 4) {
    patch2 = split[3];
    normalizedPatch2 = normalizePart(patch2);
  }
}
 
Example 2
Project: otter-G   File: RegexUtils.java   Source Code and License Vote up 7 votes
public static String findFirst(String originalStr, String regex) {
    if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) {
        return StringUtils.EMPTY;
    }

    PatternMatcher matcher = new Perl5Matcher();
    if (matcher.contains(originalStr, patterns.get(regex))) {
        return StringUtils.trimToEmpty(matcher.getMatch().group(0));
    }
    return StringUtils.EMPTY;
}
 
Example 3
Project: ymate-module-oauth   File: DefaultModuleCfg.java   Source Code and License Vote up 6 votes
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IOAuth.MODULE_NAME);
    //
    __accessTokenExpireIn = BlurObject.bind(_moduleCfgs.get("access_token_expire_in")).toIntValue();
    if (__accessTokenExpireIn <= 0) {
        __accessTokenExpireIn = 7200;
    }
    //
    __cacheNamePrefix = StringUtils.trimToEmpty(_moduleCfgs.get("cache_name_prefix"));
    //
    __snsEnabled = BlurObject.bind(_moduleCfgs.get("sns_enabled")).toBooleanValue();
    if (__snsEnabled) {
        __authorizationView = StringUtils.defaultIfBlank(_moduleCfgs.get("authorization_view"), "_views/oauth2/sns-authorization");
        __userInfoAdaptor = ClassUtils.impl(_moduleCfgs.get("userinfo_adapter_class"), IOAuthUserInfoAdapter.class, getClass());
    }
    //
    __tokenGenerator = ClassUtils.impl(_moduleCfgs.get("token_generator_class"), IOAuthTokenGenerator.class, getClass());
    if (__tokenGenerator == null) {
        __tokenGenerator = new DefaultTokenGenerator();
    }
    //
    __storageAdapter = ClassUtils.impl(_moduleCfgs.get("storage_adapter_class"), IOAuthStorageAdapter.class, getClass());
}
 
Example 4
Project: CPWR-CodeCoverage   File: CodeCoverageBuilder.java   Source Code and License Vote up 6 votes
/**
 * Validator for the 'Login credentials' field.
 * 
 * @param credentialsId
 *            login credentials passed from the config.jelly "credentialsId" field
 * 
 * @return validation message
 */
public FormValidation doCheckCredentialsId(@QueryParameter String credentialsId)
{
	String tempValue = StringUtils.trimToEmpty(credentialsId);
	if (tempValue.isEmpty())
	{
		return FormValidation.error(Messages.checkLoginCredentialsError());
	}

	return FormValidation.ok();
}
 
Example 5
Project: otter-G   File: AutoKeeperCollector.java   Source Code and License Vote up 6 votes
/**
 * <pre>
 * key=sessionId
 * value=pathList
 * </pre>
 */
private Map<String, List<String>> groupSessionPath(String cmdresult) {
    String[] result = cmdresult.split(WRAP);

    Map<String, List<String>> pathMap = new HashMap<String, List<String>>();
    String sessionId = StringUtils.EMPTY;
    for (String line : result) {
        line = StringUtils.trimToEmpty(line);
        if (StringUtils.isBlank(line)) {
            continue;
        }
        if (line.startsWith("0x")) {
            sessionId = line.replace(COLON, StringUtils.EMPTY);
            pathMap.put(sessionId, new ArrayList<String>());
        } else if (line.startsWith("/")) {
            List<String> paths = pathMap.get(sessionId);
            paths.add(line);
        }
    }
    return pathMap;
}
 
Example 6
Project: ymate-module-oauth-connector   File: DefaultModuleCfg.java   Source Code and License Vote up 6 votes
public DefaultModuleCfg(YMP owner) {
    __moduleCfgs = owner.getConfig().getModuleConfigs(IOAuthConnector.MODULE_NAME);
    //
    __cacheNamePrefix = StringUtils.trimToEmpty(__moduleCfgs.get("cache_name_prefix"));
    //
    __callbackHandler = ClassUtils.impl(__moduleCfgs.get("callback_handler_class"), IOAuthConnectCallbackHandler.class, this.getClass());
    if (__callbackHandler == null) {
        __callbackHandler = new DefaultConnectCallbackHandler();
    }
    //
    __isPasswordEncrypted = BlurObject.bind(__moduleCfgs.get("password_encrypted")).toBooleanValue();
    //
    try {
        __password = ClassUtils.impl(__moduleCfgs.get("password_class"), IPasswordProcessor.class, this.getClass());
    } catch (Exception ignored) {
    }
}
 
Example 7
Project: ymate-module-sso   File: DefaultModuleCfg.java   Source Code and License Vote up 5 votes
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(ISSO.MODULE_NAME);
    //
    __tokenCookieName = StringUtils.defaultIfBlank(_moduleCfgs.get("token_cookie_name"), ISSO.MODULE_NAME + "_token");
    //
    __tokenHeaderName = StringUtils.defaultIfBlank(_moduleCfgs.get("token_header_name"), "X-ModuleSSO-Token");
    //
    __tokenParamName = StringUtils.defaultIfBlank(_moduleCfgs.get("token_param_name"), "token");
    //
    __tokenMaxage = BlurObject.bind(_moduleCfgs.get("token_maxage")).toIntValue();
    //
    __tokenValidateTimeInterval = BlurObject.bind(_moduleCfgs.get("token_validate_time_interval")).toIntValue();
    //
    __cacheNamePrefix = StringUtils.trimToEmpty(_moduleCfgs.get("cache_name_prefix"));
    //
    __multiSessionEnabled = BlurObject.bind(_moduleCfgs.get("multi_session_enabled")).toBooleanValue();
    //
    __ipCheckEnabled = BlurObject.bind(_moduleCfgs.get("ip_check_enabled")).toBooleanValue();
    //
    __isClientMode = BlurObject.bind(_moduleCfgs.get("client_mode")).toBooleanValue();
    //
    __serviceAuthKey = StringUtils.trimToEmpty(_moduleCfgs.get("service_auth_key"));
    //
    if (__isClientMode) {
        __serviceBaseUrl = StringUtils.trimToNull(_moduleCfgs.get("service_base_url"));
        if (__serviceBaseUrl != null) {
            if (!StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "http://") &&
                    !StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "https://")) {
                throw new IllegalArgumentException("The parameter service_base_url is invalid");
            } else if (!StringUtils.endsWith(__serviceBaseUrl, "/")) {
                __serviceBaseUrl = __serviceBaseUrl + "/";
            }
        }
    }
    //
    __tokenApater = ClassUtils.impl(_moduleCfgs.get("token_adapter_class"), ISSOTokenAdapter.class, getClass());
    if (__tokenApater == null) {
        __tokenApater = new DefaultSSOTokenAdapter();
    }
    //
    __tokenStorageAdapter = ClassUtils.impl(_moduleCfgs.get("storage_adapter_class"), ISSOTokenStorageAdapter.class, getClass());
    if (!__isClientMode && __tokenStorageAdapter == null) {
        throw new IllegalArgumentException("The parameter storage_adapter_class is invalid");
    }
    //
    if (!__isClientMode) {
        __tokenAttributeAdapter = ClassUtils.impl(_moduleCfgs.get("attribute_adapter_class"), ISSOTokenAttributeAdapter.class, getClass());
    }
}
 
Example 8
Project: airsonic   File: PlayQueue.java   Source Code and License Vote up 5 votes
/**
 * Sorts the playlist according to the given sort order.
 */
public synchronized void sort(final SortOrder sortOrder) {
    makeBackup();
    MediaFile currentFile = getCurrentFile();

    Comparator<MediaFile> comparator = new Comparator<MediaFile>() {
        public int compare(MediaFile a, MediaFile b) {
            switch (sortOrder) {
                case TRACK:
                    Integer trackA = a.getTrackNumber();
                    Integer trackB = b.getTrackNumber();
                    if (trackA == null) {
                        trackA = 0;
                    }
                    if (trackB == null) {
                        trackB = 0;
                    }
                    return trackA.compareTo(trackB);

                case ARTIST:
                    String artistA = StringUtils.trimToEmpty(a.getArtist());
                    String artistB = StringUtils.trimToEmpty(b.getArtist());
                    return artistA.compareTo(artistB);

                case ALBUM:
                    String albumA = StringUtils.trimToEmpty(a.getAlbumName());
                    String albumB = StringUtils.trimToEmpty(b.getAlbumName());
                    return albumA.compareTo(albumB);
                default:
                    return 0;
            }
        }
    };

    Collections.sort(files, comparator);
    if (currentFile != null) {
        index = files.indexOf(currentFile);
    }
}
 
Example 9
Project: dlock   File: DLockConfig.java   Source Code and License Vote up 5 votes
/**
 * Constructor with lockType & lockTarget & leaseTime & leaseTimeUnit
 */
public DLockConfig(String lockType, String lockTarget, int lease, TimeUnit leaseTimeUnit) {
    this.lockType = lockType;
    this.lockTarget = lockTarget;
    this.lockUniqueKey = UK_PRE + UK_SP + lockType + UK_SP + StringUtils.trimToEmpty(lockTarget);
    this.lease = lease;
    this.leaseTimeUnit = leaseTimeUnit;
}
 
Example 10
Project: otter-G   File: RegexUtils.java   Source Code and License Vote up 5 votes
public static String findFirst(String originalStr, String regex) {
    if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) {
        return StringUtils.EMPTY;
    }

    PatternMatcher matcher = new Perl5Matcher();
    if (matcher.contains(originalStr, patterns.get(regex))) {
        return StringUtils.trimToEmpty(matcher.getMatch().group(0));
    }
    return StringUtils.EMPTY;
}
 
Example 11
Project: monarch   File: GfshMethodTarget.java   Source Code and License Vote up 5 votes
/**
 * Constructor that allows all fields to be set
 * 
 * @param method the method to invoke (required)
 * @param target the object on which the method is to be invoked (required)
 * @param remainingBuffer can be blank
 * @param key can be blank
 */
public GfshMethodTarget(final Method method, final Object target, final String remainingBuffer,
    final String key) {
  Assert.notNull(method, "Method is required");
  Assert.notNull(target, "Target is required");
  this.key = StringUtils.trimToEmpty(key);
  this.method = method;
  this.remainingBuffer = remainingBuffer;
  this.target = target;
}
 
Example 12
Project: CPWR-CodeCoverage   File: CodeCoverageBuilder.java   Source Code and License Vote up 5 votes
/**
 * Validator for the 'Host connection' field.
 * 
 * @param connectionId
 *            unique identifier for the host connection passed from the config.jelly "connectionId" field
 * 
 * @return validation message
 */
public FormValidation doCheckConnectionId(@QueryParameter String connectionId)
{
	String tempValue = StringUtils.trimToEmpty(connectionId);
	if (tempValue.isEmpty())
	{
		return FormValidation.error(Messages.checkHostConnectionError());
	}

	return FormValidation.ok();
}
 
Example 13
Project: otter-G   File: AutoKeeperCollector.java   Source Code and License Vote up 4 votes
public void collectorConnectionStat(String address) {
    List<String> netAddress = splitAddress(address);
    if (netAddress.isEmpty()) {
        return;
    }
    String ip = netAddress.get(0);
    String port = netAddress.get(1);
    String[] cmd = { "/bin/bash", "-c", String.format(CMD_CONS, ip, port) };
    String cmdresult = collector(cmd);
    String[] result = cmdresult.split(WRAP);
    List<AutoKeeperConnectionStat> summary = new ArrayList<AutoKeeperConnectionStat>();

    for (String line : result) {

        if (StringUtils.isBlank(line)) {
            continue;
        }

        String[] lineArray = line.split(":");
        if (2 != lineArray.length) {
            continue;
        }

        AutoKeeperConnectionStat autoKeeperConnectionStat = new AutoKeeperConnectionStat();
        autoKeeperConnectionStat.setOriginalContent(line);
        String clientIp = StringUtils.trimToEmpty(line.split(":")[0].replace("/", ""));
        String sessionId = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "sid=(?s).*?[,)]")).replace("sid=",
                                                                                                                        StringUtils.EMPTY).replace(COMMA,
                                                                                                                                                   StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                              StringUtils.EMPTY);
        String queued = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "queued=(?s).*?[,)]")).replace("queued=",
                                                                                                                        StringUtils.EMPTY).replace(COMMA,
                                                                                                                                                   StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                              StringUtils.EMPTY);
        String receive = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "recved=(?s).*?[,)]")).replace("recved=",
                                                                                                                         StringUtils.EMPTY).replace(COMMA,
                                                                                                                                                    StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                               StringUtils.EMPTY);
        String sent = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "sent=(?s).*?[,)]")).replace("sent=",
                                                                                                                    StringUtils.EMPTY).replace(COMMA,
                                                                                                                                               StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                          StringUtils.EMPTY);
        String minlat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "minlat=(?s).*?[,)]")).replace("minlat=",
                                                                                                                        StringUtils.EMPTY).replace(COMMA,
                                                                                                                                                   StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                              StringUtils.EMPTY);
        String avglat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "avglat=(?s).*?[,)]")).replace("avglat=",
                                                                                                                        StringUtils.EMPTY).replace(COMMA,
                                                                                                                                                   StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                              StringUtils.EMPTY);
        String maxlat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "maxlat=(?s).*?[,)]")).replace("maxlat=",
                                                                                                                        StringUtils.EMPTY).replace(COMMA,
                                                                                                                                                   StringUtils.EMPTY).replace(BRACKETS,
                                                                                                                                                                              StringUtils.EMPTY);
        autoKeeperConnectionStat.setServerAddress(ip);
        autoKeeperConnectionStat.setClientAddress(clientIp);
        autoKeeperConnectionStat.setSessionId(sessionId);
        if (StringUtils.isNotEmpty(queued)) {
            autoKeeperConnectionStat.setQueued(Long.parseLong(queued));
        }
        if (StringUtils.isNotEmpty(receive)) {
            autoKeeperConnectionStat.setRecved(Long.parseLong(receive));
        }
        if (StringUtils.isNotEmpty(sent)) {
            autoKeeperConnectionStat.setSent(Long.parseLong(sent));
        }
        if (StringUtils.isNotEmpty(minlat)) {
            autoKeeperConnectionStat.setMinLatency(Long.parseLong(minlat));
        }
        if (StringUtils.isNotEmpty(avglat)) {
            autoKeeperConnectionStat.setAvgLatency(Long.parseLong(avglat));
        }
        if (StringUtils.isNotEmpty(maxlat)) {
            autoKeeperConnectionStat.setMaxLatency(Long.parseLong(maxlat));
        }

        summary.add(autoKeeperConnectionStat);
    }
    autoKeeperData.joinConnection(address, summary);
}
 
Example 14
Project: otter-G   File: AbstractSubscribeManager.java   Source Code and License Vote up 4 votes
protected static String generateKey(String dataId, String groupId) {
    return StringUtils.trimToEmpty(dataId) + "_" + StringUtils.trimToEmpty(groupId);
}
 
Example 15
Project: matrix-appservice-email   File: AEmailClientFormatter.java   Source Code and License Vote up 4 votes
protected String formatPlain(String content) {
    // TODO do a proper algorithm

    try {
        int maxLine = 0;


        List<String> linesIn = IOUtils.readLines(new StringReader(content));
        for (int i = 0; i < linesIn.size(); i++) {
            if (linesIn.get(i).startsWith(">")) {
                maxLine = i - (StringUtils.isBlank(linesIn.get(i - 1)) ? 2 : 1);
                break;
            }
        }

        List<String> linesOut = new ArrayList<>();
        boolean prevLineBlank = false;
        for (int i = 0; i < maxLine; i++) {
            String line = StringUtils.trimToEmpty(linesIn.get(i));
            if (StringUtils.isBlank(line)) {
                if (prevLineBlank) {
                    continue;
                }

                prevLineBlank = true;
            } else {
                prevLineBlank = false;
            }
            linesOut.add(line);
        }

        if (prevLineBlank) {
            linesOut.remove(linesOut.size() - 1);
        }

        return StringUtils.join(linesOut, System.lineSeparator());
    } catch (IOException e) {
        // This should never happen, we can't deal with it here
        throw new RuntimeException(e);
    }
}
 
Example 16
Project: CPWR-CodeCoverage   File: CodeCoverageBuilder.java   Source Code and License Vote up 3 votes
/**
 * Constructor.
 * 
 * @param connectionId
			  a unique host connection identifier
 * @param credentialsId
 *            unique id of the selected credential
 * @param analysisPropertiesPath
 *            the path of Code Coverage analysis properties file
 * @param analysisProperties
 *            the Code Coverage analysis properties
 */
@DataBoundConstructor
public CodeCoverageBuilder(String connectionId, String credentialsId, String analysisPropertiesPath,
		String analysisProperties)
{
	m_connectionId = StringUtils.trimToEmpty(connectionId);
	m_credentialsId = StringUtils.trimToEmpty(credentialsId);
	m_analysisPropertiesPath = StringUtils.trimToEmpty(analysisPropertiesPath);
	m_analysisProperties = StringUtils.trimToEmpty(analysisProperties);
}
 
Example 17
Project: lams   File: PasswordChangeActionForm.java   Source Code and License Vote up 2 votes
/**
    * Sets the login.
    *
    * @param login
    *            The login to set
    */
   public void setLogin(String login) {
this.login = StringUtils.trimToEmpty(login);
   }
 
Example 18
Project: lams   File: PasswordChangeActionForm.java   Source Code and License Vote up 2 votes
/**
    * Sets the password.
    *
    * @param password
    *            The password to set
    */
   public void setPassword(String password) {
this.password = StringUtils.trimToEmpty(password);
   }
 
Example 19
Project: lams   File: PasswordChangeActionForm.java   Source Code and License Vote up 2 votes
/**
    * Sets the passwordConfirm.
    *
    * @param passwordConfirm
    *            The passwordConfirm to set
    */
   public void setPasswordConfirm(String passwordConfirm) {
this.passwordConfirm = StringUtils.trimToEmpty(passwordConfirm);
   }
 
Example 20
Project: lams   File: PasswordChangeActionForm.java   Source Code and License Vote up 2 votes
/**
    * @param oldPassword
    *            The oldPassword to set.
    */
   public void setOldPassword(String oldPassword) {
this.oldPassword = StringUtils.trimToEmpty(oldPassword);
   }