当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.trimToNull方法代码示例

本文整理汇总了Java中org.apache.commons.lang.StringUtils.trimToNull方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.trimToNull方法的具体用法?Java StringUtils.trimToNull怎么用?Java StringUtils.trimToNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.StringUtils的用法示例。


在下文中一共展示了StringUtils.trimToNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encrypt

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* 加密
* @param datasource byte[]
* @param password String
* @return byte[]
*/
public static String encrypt(String datasource, String password) {
	try {
		if(StringUtils.trimToNull(datasource) == null){
			return null;
		}
		SecureRandom random = new SecureRandom();
		DESKeySpec desKey = new DESKeySpec(password.getBytes());
		// 创建一个密匙工厂,然后用它把DESKeySpec转换成
		SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
		SecretKey securekey = keyFactory.generateSecret(desKey);
		// Cipher对象实际完成加密操作
		Cipher cipher = Cipher.getInstance("DES");
		// 用密匙初始化Cipher对象
		cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
		// 现在,获取数据并加密
		// 正式执行加密操作
		 return new BASE64Encoder().encode(cipher.doFinal(datasource.getBytes()));
		
	} catch (Throwable e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:30,代码来源:DES.java

示例2: valueOf

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * Parses the given string as a HTTP header byte range.  See chapter 14.36.1 in RFC 2068
 * for details.
 * <p/>
 * Only a subset of the allowed syntaxes are supported. Only ranges which specify first-byte-pos
 * are supported. The last-byte-pos is optional.
 *
 * @param range The range from the HTTP header, for instance "bytes=0-499" or "bytes=500-"
 * @return A range object (using inclusive values). If the last-byte-pos is not given, the end of
 *         the returned range is {@code null}. The method returns <code>null</code> if the syntax
 *         of the given range is not supported.
 */
public static HttpRange valueOf(String range) {
    if (range == null) {
        return null;
    }

    Matcher matcher = PATTERN.matcher(range);
    if (matcher.matches()) {
        String firstString = matcher.group(1);
        String lastString = StringUtils.trimToNull(matcher.group(2));

        Long first = Long.parseLong(firstString);
        Long last = lastString == null ? null : Long.parseLong(lastString);

        if (last != null && first > last) {
            return null;
        }
        return new HttpRange(first, last);
    }
    return null;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:33,代码来源:HttpRange.java

示例3: getITunesAttribute

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private String getITunesAttribute(Element element, String childName, String attributeName) {
    for (Namespace ns : ITUNES_NAMESPACES) {
        Element elem = element.getChild(childName, ns);
        if (elem != null) {
            return StringUtils.trimToNull(elem.getAttributeValue(attributeName));
        }
    }
    return null;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:10,代码来源:PodcastService.java

示例4: parseSearchResult

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();

    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song =  root.getChildText("LyricSong", ns);
    String artist =  root.getChildText("LyricArtist", ns);

    return new LyricsInfo(lyric, artist, song);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:14,代码来源:LyricsService.java

示例5: processWikiText

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private String processWikiText(String text) {
    /*
     System of a Down is an Armenian American <a href="http://www.last.fm/tag/alternative%20metal" class="bbcode_tag" rel="tag">alternative metal</a> band,
     formed in 1994 in Los Angeles, California, USA. All four members are of Armenian descent, and are widely known for their outspoken views expressed in
     many of their songs confronting the Armenian Genocide of 1915 by the Ottoman Empire and the ongoing War on Terror by the US government. The band
     consists of <a href="http://www.last.fm/music/Serj+Tankian" class="bbcode_artist">Serj Tankian</a> (vocals), Daron Malakian (vocals, guitar),
     Shavo Odadjian (bass, vocals) and John Dolmayan (drums).
     <a href="http://www.last.fm/music/System+of+a+Down">Read more about System of a Down on Last.fm</a>.
     User-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.
     */

    text = text.replaceAll("User-contributed text.*", "");
    text = text.replaceAll("<a ", "<a target='_blank' ");
    text = text.replace("\n", " ");
    text = StringUtils.trimToNull(text);

    if (text != null && text.startsWith("This is an incorrect tag")) {
        return null;
    }

    return text;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:23,代码来源:LastFmService.java

示例6: makeSafePlaylistName

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * creates a playlist name that is <= 150 characters and is unique
 * 
 * @param playlistName the name of the playlist
 * @return the safe playlist name
 * @throws IllegalArgumentException if playlist name is invalid
 */
@NoProfile
protected String makeSafePlaylistName(String playlistName) {
    playlistName = StringUtils.trimToNull(playlistName);
    if (playlistName == null) {
        throw new IllegalArgumentException("playlistName cannot be null");
    }
    if (playlistName.length() > PLAYLIST_MAX_LENGTH) {
        playlistName = StringUtils.abbreviate(playlistName, CATEGORY_MAX_LENGTH);
        playlistName = playlistName.substring(0, CATEGORY_MAX_LENGTH-3) + RandomStringUtils.randomAlphanumeric(3);
    }
    return playlistName;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:20,代码来源:KalturaAPIService.java

示例7: index

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public void index(Map<String, Object> context) {
    final String service = StringUtils.trimToNull((String) context.get("service"));
    
    List<LoadBalance> loadbalances;
    if (service != null && service.length() > 0) {
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findByService(service));
        
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findByService(service));
    } else {
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findAll());
    }
    context.put("loadbalances", loadbalances);
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:14,代码来源:Loadbalances.java

示例8: index

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public void index(Map<String, Object> context) {
    final String service = StringUtils.trimToNull((String) context.get("service"));
    String address = (String) context.get("address");
    address = Tool.getIP(address);
    List<Weight> weights;
    if (service != null && service.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
    } else if (address != null && address.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
    } else {
        weights = OverrideUtils.overridesToWeights(overrideService.findAll());
    }
    context.put("weights", weights);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:15,代码来源:Weights.java

示例9: __doJsApi

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * @param appId  微信公众号应用ID
 * @param openId 微信用户身份唯一标识
 * @param state  商品或订单ID
 * @param attach 附加信息
 * @return 微信支付 -- JS_API模式
 * @throws Exception 可能产生的任何异常
 */
@RequestMapping(value = "/jsapi/{app_id}", method = {Type.HttpMethod.GET, Type.HttpMethod.POST})
public IView __doJsApi(@PathVariable("app_id") String appId,
                       @VRequried @RequestParam("open_id") String openId,
                       @VRequried @RequestParam String state,
                       @RequestParam String attach,
                       @RequestParam boolean debug) throws Exception {
    IWxPayEventHandler _eventHandler = WxPay.get().getModuleCfg().getEventHandler();
    if (_eventHandler != null) {
        WxPayAccountMeta _meta = WxPay.get().getModuleCfg().getAccountProvider().getAccount(appId);
        if (_meta != null) {
            WxPayUnifiedOrder _request = _eventHandler.buildUnifiedOrderRequest(_meta, IWxPay.TradeType.JSAPI, state, attach).openId(openId);
            WxPayUnifiedOrder.Response _response = _request.execute();
            //
            if (_response.checkReturnCode() && _response.checkResultCode() && (WxPay.get().getModuleCfg().isSignCheckDisabled() || _response.checkSignature(_meta.getMchKey()))) {
                // 封装JSAPI初始化相关参数
                String _queryStr = StringUtils.trimToNull(WebContext.getRequest().getQueryString());
                String _currentURL = WebUtils.buildURL(WebContext.getRequest(), "payment/wxpay/jsapi/" + appId + (_queryStr == null ? "" : "?" + _queryStr), true);
                //
                String _timestamp = DateTimeUtils.currentTimeUTC() + "";
                String _nonceStr = WxPayBaseData.__doCreateNonceStr();
                String _config = __buildJsApiConfigStr(_meta.getAppId(), _eventHandler.getJsApiTicket(_meta.getAppId()), StringUtils.substringBefore(_currentURL, "#"), _timestamp, _nonceStr, debug);
                // 封装基于JSAPI的支付调用相关参数
                Map<String, Object> _paramMap = new HashMap<String, Object>();
                _paramMap.put("appId", _meta.getAppId());
                _paramMap.put("timeStamp", _timestamp);
                _paramMap.put("nonceStr", _nonceStr);
                _paramMap.put("package", "prepay_id=" + _response.prepayId());
                _paramMap.put("signType", IWxPay.Const.SIGN_TYPE_MD5);
                _paramMap.put("paySign", WxPayBaseData.__doCreateSignature(_paramMap, _meta.getMchKey()));
                //
                return View.jspView(WxPay.get().getModuleCfg().getJsApiView())
                        .addAttribute("_config", _config)
                        .addAttribute("_data", _paramMap)
                        .addAttribute("_trade_no", state);
            }
        }
    }
    return HttpStatusView.bind(HttpServletResponse.SC_BAD_REQUEST);
}
 
开发者ID:suninformation,项目名称:ymate-payment-v2,代码行数:48,代码来源:WxPayJsApiController.java

示例10: getPlayerIdFromCookie

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * Reads the player ID from the cookie in the HTTP request.
 *
 * @param request  The HTTP request.
 * @param username The name of the current user.
 * @return The player ID embedded in the cookie, or <code>null</code> if cookie is not present.
 */
private String getPlayerIdFromCookie(HttpServletRequest request, String username) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }
    String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username);
    for (Cookie cookie : cookies) {
        if (cookieName.equals(cookie.getName())) {
            return StringUtils.trimToNull(cookie.getValue());
        }
    }
    return null;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:21,代码来源:PlayerService.java

示例11: checkLong

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
    * @return long value of paramValue
    * @exception IllegalArgumentException
    *                - if (a) not set and is not optional or (b) not long
    */
   public static Long checkLong(String paramName, String paramValue, boolean isOptional)
    throws IllegalArgumentException {
try {
    if (!isOptional) {
	WebUtil.checkObject(paramName, paramValue);
    }
    String value = paramValue != null ? StringUtils.trimToNull(paramValue) : null;
    return value != null ? new Long(value) : null;

} catch (NumberFormatException e) {
    throw new IllegalArgumentException(paramName + " should be a long '" + paramValue + "'");
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:WebUtil.java

示例12: handleParameters

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private void handleParameters(HttpServletRequest request) {
    boolean dlnaEnabled = ServletRequestUtils.getBooleanParameter(request, "dlnaEnabled", false);
    String dlnaServerName = StringUtils.trimToNull(request.getParameter("dlnaServerName"));
    String dlnaBaseLANURL = StringUtils.trimToNull(request.getParameter("dlnaBaseLANURL"));
    if (dlnaServerName == null) {
        dlnaServerName = "Airsonic";
    }

    upnpService.setMediaServerEnabled(false);
    settingsService.setDlnaEnabled(dlnaEnabled);
    settingsService.setDlnaServerName(dlnaServerName);
    settingsService.setDlnaBaseLANURL(dlnaBaseLANURL);
    settingsService.save();
    upnpService.setMediaServerEnabled(dlnaEnabled);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:16,代码来源:DLNASettingsController.java

示例13: onSubmit

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
protected String onSubmit(HttpServletRequest request, HttpServletResponse response,@ModelAttribute("command") SearchCommand command, Model model)
        throws Exception {

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    command.setUser(user);
    command.setPartyModeEnabled(userSettings.isPartyModeEnabled());

    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    String query = StringUtils.trimToNull(command.getQuery());

    if (query != null) {

        SearchCriteria criteria = new SearchCriteria();
        criteria.setCount(MATCH_COUNT);
        criteria.setQuery(query);

        SearchResult artists = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST);
        command.setArtists(artists.getMediaFiles());

        SearchResult albums = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM);
        command.setAlbums(albums.getMediaFiles());

        SearchResult songs = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
        command.setSongs(songs.getMediaFiles());

        command.setPlayer(playerService.getPlayer(request, response));
    }

    return "search";
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:33,代码来源:SearchController.java

示例14: handleParameters

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private void handleParameters(HttpServletRequest request) {
    boolean sonosEnabled = ServletRequestUtils.getBooleanParameter(request, "sonosEnabled", false);
    String sonosServiceName = StringUtils.trimToNull(request.getParameter("sonosServiceName"));
    if (sonosServiceName == null) {
        sonosServiceName = "Airsonic";
    }

    settingsService.setSonosEnabled(sonosEnabled);
    settingsService.setSonosServiceName(sonosServiceName);
    settingsService.save();

    sonosService.setMusicServiceEnabled(false, NetworkService.getBaseUrl(request));
    sonosService.setMusicServiceEnabled(sonosEnabled, NetworkService.getBaseUrl(request));
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:15,代码来源:SonosSettingsController.java

示例15: DefaultModuleCfg

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IWxPay.MODULE_NAME);
    //
    __accountProvider = ClassUtils.impl(_moduleCfgs.get("account_provider_class"), IWxPayAccountProvider.class, getClass());
    if (__accountProvider == null) {
        __accountProvider = new DefaultWxPayAccountProvider();
        //
        WxPayAccountMeta _meta = new WxPayAccountMeta(_moduleCfgs.get("app_id"),
                _moduleCfgs.get(IWxPay.Const.MCH_ID),
                _moduleCfgs.get(IWxPay.Const.MCH_KEY),
                _moduleCfgs.get("cert_file_path"),
                _moduleCfgs.get(IWxPay.Const.NOTIFY_URL));
        _meta.setSandboxEnabled(BlurObject.bind(_moduleCfgs.get("sandbox_enabled")).toBooleanValue());
        _meta.setSandboxPrefix(StringUtils.defaultIfBlank(_moduleCfgs.get("sandbox_prefix"), "sandboxnew"));
        //
        __defaultAccountId = _meta.getAppId();
        __accountProvider.registerAccount(_meta);
    } else {
        __defaultAccountId = StringUtils.trimToNull(_moduleCfgs.get("default_account_id"));
    }
    //
    __eventHandler = ClassUtils.impl(_moduleCfgs.get("event_handler_class"), IWxPayEventHandler.class, getClass());
    if (__eventHandler == null) {
        throw new NullArgumentException("event_handler_class");
    }
    //
    __jsApiView = StringUtils.defaultIfBlank(_moduleCfgs.get("jsapi_view"), "wxpay_jsapi");
    __nativeView = StringUtils.defaultIfBlank(_moduleCfgs.get("native_view"), "wxpay_native");
    //
    __signCheckDisabled = BlurObject.bind(_moduleCfgs.get("sign_check_disabled")).toBooleanValue();
}
 
开发者ID:suninformation,项目名称:ymate-payment-v2,代码行数:32,代码来源:DefaultModuleCfg.java


注:本文中的org.apache.commons.lang.StringUtils.trimToNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。