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

The following examples show how to use org.apache.commons.lang.StringUtils#trimToEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterceptAnnoHelper.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
public static void parseContextParamValue(YMP owner, ContextParam contextParam, Map<String, String> paramsMap) {
    if (contextParam != null) {
        for (ParamItem _item : contextParam.value()) {
            String _key = _item.key();
            String _value = _item.value();
            boolean _flag = _value.length() > 1 && _value.charAt(0) == '$';
            if (StringUtils.isBlank(_key)) {
                if (_flag) {
                    _key = _value.substring(1);
                    _value = StringUtils.trimToEmpty(owner.getConfig().getParam(_key));
                } else {
                    _key = _value;
                }
            } else if (_flag) {
                _value = StringUtils.trimToEmpty(owner.getConfig().getParam(_value.substring(1)));
            }
            paramsMap.put(_key, _value);
        }
    }
}
 
Example 2
Source File: ExtensionLoader.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public T getExtension(String name, String key) {
    if (name == null || name.length() == 0) throw new IllegalArgumentException("Extension name == null");
    if ("true".equals(name)) {
        return getDefaultExtension();
    }
    String extKey = name + "-" + StringUtils.trimToEmpty(key);
    Holder<Object> holder = cachedInstances.get(extKey);
    if (holder == null) {
        cachedInstances.putIfAbsent(extKey, new Holder<>());
        holder = cachedInstances.get(extKey);
    }
    Object instance = holder.get();
    if (instance == null) {
        synchronized (holder) {
            instance = holder.get();
            if (instance == null) {
                instance = createExtension(name, key);
                holder.set(instance);
            }
        }
    }
    return (T) instance;
}
 
Example 3
Source File: ExtensionLoader.java    From canal with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public T getExtension(String name, String key, String spiDir, String standbyDir) {
    if (name == null || name.length() == 0) throw new IllegalArgumentException("Extension name == null");
    if ("true".equals(name)) {
        return getDefaultExtension(spiDir, standbyDir);
    }
    String extKey = name + "-" + StringUtils.trimToEmpty(key);
    Holder<Object> holder = cachedInstances.get(extKey);
    if (holder == null) {
        cachedInstances.putIfAbsent(extKey, new Holder<>());
        holder = cachedInstances.get(extKey);
    }
    Object instance = holder.get();
    if (instance == null) {
        synchronized (holder) {
            instance = holder.get();
            if (instance == null) {
                instance = createExtension(name, key, spiDir, standbyDir);
                holder.set(instance);
            }
        }
    }
    return (T) instance;
}
 
Example 4
Source File: OdpsRegexEventSerializer.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(Context context) {
    String regex = context.getString(REGEX_CONFIG, REGEX_DEFAULT);
    regexIgnoreCase = context.getBoolean(IGNORE_CASE_CONFIG,
            INGORE_CASE_DEFAULT);
    inputPattern = Pattern.compile(regex, Pattern.DOTALL
            + (regexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0));
    charset = Charset.forName(context.getString(CHARSET_CONFIG,
            CHARSET_DEFAULT));

    String colNameStr = context.getString(FIELD_NAMES, FIELD_NAME_DEFAULT);
    if (colNameStr == null) {
        throw new InvalidParameterException("invalid fieldnames: " + colNameStr);
    }
    inputColNames = colNameStr.split(",", -1);
    for (int i = 0; i < inputColNames.length; i++) {
        inputColNames[i] = StringUtils.trimToEmpty(inputColNames[i]);
    }

    logger.info("RegexEventSerializer, regex: [{}], charset: {}, fieldnames, {} ", regex, charset, inputColNames);
}
 
Example 5
Source File: DefaultRequestMappingParser.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param partStr 参数段
 * @return 返回去掉首尾'/'字符的串
 */
private String __doFixMappingPart(String partStr) {
    partStr = StringUtils.trimToEmpty(partStr);
    if (StringUtils.startsWith(partStr, "/")) {
        partStr = StringUtils.substringAfter(partStr, "/");
    }
    if (StringUtils.endsWith(partStr, "/")) {
        partStr = StringUtils.substringBeforeLast(partStr, "/");
    }
    return partStr;
}
 
Example 6
Source File: Site.java    From jira-steps-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(final @AncestorInPath Item item,
    @QueryParameter String credentialsId,
    final @QueryParameter String url) {

  StandardListBoxModel result = new StandardListBoxModel();

  credentialsId = StringUtils.trimToEmpty(credentialsId);
  if (item == null) {
    if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
      return result.includeCurrentValue(credentialsId);
    }
  } else {
    if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
      return result.includeCurrentValue(credentialsId);
    }
  }

  Authentication authentication = getAuthentication(item);
  List<DomainRequirement> domainRequirements = URIRequirementBuilder.fromUri(url).build();
  CredentialsMatcher always = CredentialsMatchers.always();
  Class<? extends StandardUsernameCredentials> type = UsernamePasswordCredentialsImpl.class;

  result.includeEmptyValue();
  if (item != null) {
    result.includeMatchingAs(authentication, item, type, domainRequirements, always);
  } else {
    result.includeMatchingAs(authentication, Jenkins.get(), type, domainRequirements, always);
  }
  return result;
}
 
Example 7
Source File: ConfigBuilder.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
private static InputStream __doLoadResourceStream(String prefix) {
    prefix = "ymp-conf" + StringUtils.trimToEmpty(prefix);
    ClassLoader _classLoader = ConfigBuilder.class.getClassLoader();
    InputStream _in = _classLoader.getResourceAsStream(prefix + ".properties");
    if (_in == null) {
        if (RuntimeUtils.isWindows()) {
            _in = _classLoader.getResourceAsStream(prefix + "_WIN.properties");
        } else if (RuntimeUtils.isUnixOrLinux()) {
            _in = _classLoader.getResourceAsStream(prefix + "_UNIX.properties");
        }
    }
    return _in;
}
 
Example 8
Source File: PlayQueue.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
Source File: DataTypeUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static String computeTupleTypeName(List<String> slotNames, List<Type> slotTypes) {
    List<String> components = new ArrayList<String>();
    for (int i = 0; i < slotNames.size(); i++) {
        String componentName = StringUtils.trimToEmpty(slotNames.get(i)) + " : "
                + slotTypes.get(i).getQualifiedName();
        components.add(componentName);
    }
    return ANONYMOUS_PREFIX + "[" + StringUtils.join(components, ", ") + "]";
}
 
Example 10
Source File: CompareValidator.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
private String getParamValue(Object paramValue) {
    String _pValue = null;
    if (paramValue != null) {
        if (paramValue.getClass().isArray()) {
            Object[] _objArr = (Object[]) paramValue;
            if (_objArr.length > 0) {
                _pValue = BlurObject.bind(_objArr[0]).toStringValue();
            }
        } else {
            _pValue = BlurObject.bind(paramValue).toStringValue();
        }
    }
    return StringUtils.trimToEmpty(_pValue);
}
 
Example 11
Source File: GCalEventDownloader.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <p>
 * Extracts start, end and modified by-commands from <code>content</code>.
 * Start-Commands will be executed at start-time and End-Commands will be
 * executed at end-time of the calendar-event. The modified-by command defines
 * the name of special event which disables the created Job temporarily.
 * </p>
 * <p>
 * If the RegExp <code>EXTRACT_STARTEND_CONTENT</code> doen't match the
 * complete content is taken as set of Start-Commands.
 * </p>
 *
 * @param content the set of Start- and End-Commands
 * @return the parsed event content
 */
protected CalendarEventContent parseEventContent(String content, boolean presenceSimulation) {
    CalendarEventContent eventContent = new CalendarEventContent();
    String commandContent;

    Matcher modifiedByMatcher = EXTRACT_MODIFIEDBY_CONTENT.matcher(content);
    if (modifiedByMatcher.find()) {
        commandContent = modifiedByMatcher.group(1);
        eventContent.modifiedByEvent = StringUtils.trimToEmpty(modifiedByMatcher.group(2));
    } else {
        commandContent = content;
    }

    Matcher startEndMatcher = EXTRACT_STARTEND_CONTENT.matcher(commandContent);
    if (startEndMatcher.find()) {
        eventContent.startCommands = StringUtils.trimToEmpty(startEndMatcher.group(1));
        eventContent.endCommands = StringUtils.trimToEmpty(startEndMatcher.group(2));
    } else {
        if (presenceSimulation) {
            eventContent.startCommands = StringUtils.trimToEmpty("[PresenceSimulation]" + "\n" + commandContent);
        } else {
            eventContent.startCommands = StringUtils.trimToEmpty(commandContent);
        }
        logger.debug(
                "given event content doesn't match regular expression to extract start-, end commands - using whole content as startCommand ({})",
                commandContent);
    }

    return eventContent;
}
 
Example 12
Source File: IntegerPercentConverter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Integer convertToObject(String value, final Locale locale)
{
  value = StringUtils.trimToEmpty(value);
  if (value.endsWith("%") == true) {
    value = value.substring(0, value.length() - 1).trim();
  }
  return super.convertToObject(value, locale);
}
 
Example 13
Source File: PlayQueue.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sorts the playlist according to the given sort order.
 */
public synchronized void sort(final SortOrder sortOrder) {
    makeBackup();
    MediaFile currentFile = getCurrentFile();

    Comparator<MediaFile> comparator = (a, 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;
        }
    };

    files.sort(comparator);
    if (currentFile != null) {
        index = files.indexOf(currentFile);
    }
}
 
Example 14
Source File: ConfigProperty.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
/**
 * 获取数据库中保存的config信息
 *
 * @param configKeyEnum
 * @return
 */
public static String getConfigValue(ConfigKeyEnum configKeyEnum) {

    if(configProperty != null) {
        ConfigPO configPO = configProperty.configService.getConfigByEnum(configKeyEnum);
        if (configPO != null) {
            return StringUtils.trimToEmpty(configPO.getConfigValue());
        }
    }
    return "";
}
 
Example 15
Source File: RegexUtils.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public static String findFirst(String originalStr, String regex) {
    if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) {
        return StringUtils.EMPTY;
    }

    PatternMatcher matcher = new Perl5Matcher();
    try {
        if (matcher.contains(originalStr, patterns.get(regex))) {
            return StringUtils.trimToEmpty(matcher.getMatch().group(0));
        }
    } catch (ExecutionException e) {
        throw new RuntimeException(e);
    }
    return StringUtils.EMPTY;
}
 
Example 16
Source File: CurrencyConverter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If total amount is given also a percentage value is supported.
 * @see org.apache.wicket.util.convert.converters.BigDecimalConverter#convertToObject(java.lang.String, java.util.Locale)
 */
@Override
public BigDecimal convertToObject(String value, final Locale locale)
{
  value = StringUtils.trimToEmpty(value);
  if (value.endsWith(currency) == true) {
    value = value.substring(0, value.length() - 1).trim();
  } else if (totalAmount != null && value.endsWith("%") == true) {
    value = value.substring(0, value.length() - 1).trim();
    final BigDecimal percentage = super.convertToObject(value, locale);
    return totalAmount.multiply(percentage).divide(NumberHelper.HUNDRED, RoundingMode.HALF_UP);
  }
  return super.convertToObject(value, locale);
}
 
Example 17
Source File: FileUtils.java    From Aooms with Apache License 2.0 5 votes vote down vote up
/** 
 * 获取扩展名 
 *  
 * @param fileName 
 * @return 
 */  
public static String getExtension(String fileName) {  
    if (StringUtils.INDEX_NOT_FOUND == StringUtils.indexOf(fileName, DOT))  
        return StringUtils.EMPTY;  
    String ext = StringUtils.substring(fileName,  
            StringUtils.lastIndexOf(fileName, DOT));  
    return StringUtils.trimToEmpty(ext);  
}
 
Example 18
Source File: VendorCreditMemoDocument.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a custom document title based on the workflow document title.
 * Depending on the document status, the PO, vendor, amount, etc may be added to the documents title.
 *
 * @return - Customized document title text dependent upon route level.
 */
protected String getCustomDocumentTitle() {
    String popreq = "";
    if (this.isSourceDocumentPurchaseOrder() || this.isSourceDocumentPaymentRequest()) {
        String poNumber = getPurchaseOrderIdentifier().toString();
        popreq = new StringBuffer("PO: ").append(poNumber).toString();
    }

    String vendorName = StringUtils.trimToEmpty(getVendorName());
    String cmAmount = getGrandTotal().toString();
    String indicator = getTitleIndicator();
    String documentTitle = new StringBuffer(popreq).append(" Vendor: ").append(vendorName).append(" Amount: ").append(cmAmount).append(" ").append(indicator).toString();
    return documentTitle;
}
 
Example 19
Source File: FaultyDataSummary.java    From rapidminer-studio with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Creates a {@link FaultyDataSummary} with the base message "No summary available for file" and the given file's path.
 * An additional message might be appended with a semicolon if not {@code null} or empty.
 *
 * @param file
 * 		the file that caused the problem
 * @param addition
 * 		an optional additional message
 * @return a faulty data summary
 */
public static FaultyDataSummary additionalInfo(GeneralFile<?> file, String addition) {
	addition = StringUtils.trimToEmpty(addition);
	if (!addition.isEmpty()) {
		addition = "; " + addition;
	}
	return new FaultyDataSummary("No summary available for file " + file.getPath() + addition);
}
 
Example 20
Source File: PasswordChangeActionForm.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
    * Sets the login.
    *
    * @param login
    *            The login to set
    */
   public void setLogin(String login) {
this.login = StringUtils.trimToEmpty(login);
   }