當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。