List of usage examples for org.apache.commons.lang StringUtils lowerCase
public static String lowerCase(String str)
Converts a String to lower case as per String#toLowerCase() .
From source file:net.sourceforge.subsonic.backend.controller.RedirectionManagementController.java
public void test(HttpServletRequest request, HttpServletResponse response) throws Exception { String redirectFrom = StringUtils .lowerCase(ServletRequestUtils.getRequiredStringParameter(request, "redirectFrom")); PrintWriter writer = response.getWriter(); Redirection redirection = redirectionDao.getRedirection(redirectFrom); String webAddress = redirectFrom + ".subsonic.org"; if (redirection == null) { writer.print("Web address " + webAddress + " not registered."); return;//from w w w . j a v a 2s. c om } if (redirection.getTrialExpires() != null && redirection.getTrialExpires().before(new Date())) { writer.print("Trial period expired. Please upgrade to Subsonic Premium to activate web address."); return; } String url = redirection.getRedirectTo(); if (!url.endsWith("/")) { url += "/"; } url += "index.html"; HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000); HttpConnectionParams.setSoTimeout(client.getParams(), 15000); HttpGet method = new HttpGet(url); try { HttpResponse resp = client.execute(method); StatusLine status = resp.getStatusLine(); if (status.getStatusCode() == HttpStatus.SC_OK) { String msg = webAddress + " responded successfully."; writer.print(msg); LOG.info(msg); } else { String msg = webAddress + " returned HTTP error code " + status.getStatusCode() + " " + status.getReasonPhrase(); writer.print(msg); LOG.info(msg); } } catch (SSLPeerUnverifiedException x) { String msg = webAddress + " responded successfully, but could not authenticate it."; writer.print(msg); LOG.info(msg); } catch (Throwable x) { String msg = webAddress + " is registered, but could not connect to it. (" + x.getClass().getSimpleName() + ")"; writer.print(msg); LOG.info(msg); } finally { client.getConnectionManager().shutdown(); } }
From source file:net.sourceforge.subsonic.controller.ImportPlaylistController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); try {//from w w w .j av a2 s . c o m if (ServletFileUpload.isMultipartContent(request)) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<?> items = upload.parseRequest(request); for (Object o : items) { FileItem item = (FileItem) o; if ("file".equals(item.getFieldName()) && !StringUtils.isBlank(item.getName())) { if (item.getSize() > MAX_PLAYLIST_SIZE_MB * 1024L * 1024L) { throw new Exception("The playlist file is too large. Max file size is " + MAX_PLAYLIST_SIZE_MB + " MB."); } String playlistName = FilenameUtils.getBaseName(item.getName()); String fileName = FilenameUtils.getName(item.getName()); String format = StringUtils.lowerCase(FilenameUtils.getExtension(item.getName())); String username = securityService.getCurrentUsername(request); Playlist playlist = playlistService.importPlaylist(username, playlistName, fileName, format, item.getInputStream()); map.put("playlist", playlist); } } } } catch (Exception e) { map.put("error", e.getMessage()); } ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
From source file:net.sourceforge.subsonic.controller.NetworkSettingsController.java
protected void doSubmitAction(Object cmd) throws Exception { NetworkSettingsCommand command = (NetworkSettingsCommand) cmd; settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled()); settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled()); settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); if (!settingsService.isLicenseValid() && settingsService.getUrlRedirectTrialExpires() == null) { Date expiryDate = new Date(System.currentTimeMillis() + TRIAL_DAYS * 24L * 3600L * 1000L); settingsService.setUrlRedirectTrialExpires(expiryDate); }//from ww w . ja va 2 s .c om if (settingsService.getServerId() == null) { Random rand = new Random(System.currentTimeMillis()); settingsService.setServerId(String.valueOf(Math.abs(rand.nextLong()))); } settingsService.setSubsonicUrl(StringUtils.lowerCase(command.getSubsonicUrl())); settingsService.save(); networkService.initPortForwarding(); networkService.initUrlRedirection(true); }
From source file:net.sourceforge.subsonic.service.MediaFileService.java
private MediaFile createMediaFile(File file) { MediaFile mediaFile = new MediaFile(); Date now = new Date(); mediaFile.setPath(file.getPath());/*from w w w . j a v a2s . c o m*/ mediaFile.setFolder(securityService.getRootFolderForFile(file)); mediaFile.setParentPath(file.getParent()); mediaFile.setLastModified(new Date(FileUtil.lastModified(file))); mediaFile.setLastScanned(now); mediaFile.setPlayCount(0); mediaFile.setChildrenLastUpdated(new Date(0)); mediaFile.setCreated(now); mediaFile.setMediaType(DIRECTORY); mediaFile.setPresent(true); if (file.isFile()) { String format = StringUtils .trimToNull(StringUtils.lowerCase(FilenameUtils.getExtension(mediaFile.getPath()))); mediaFile.setFormat(format); mediaFile.setFileSize(FileUtil.length(file)); mediaFile.setMediaType(isMusicFile(format) ? AUDIO : VIDEO); MetaDataParser parser = metaDataParserFactory.getParser(file); if (parser != null) { MetaData metaData = parser.getMetaData(file); mediaFile.setArtist(metaData.getArtist()); mediaFile.setAlbumName(metaData.getAlbumName()); mediaFile.setTitle(metaData.getTitle()); mediaFile.setDiscNumber(metaData.getDiscNumber()); mediaFile.setTrackNumber(metaData.getTrackNumber()); mediaFile.setGenre(metaData.getGenre()); mediaFile.setYear(metaData.getYear()); mediaFile.setDurationSeconds(metaData.getDurationSeconds()); mediaFile.setBitRate(metaData.getBitRate()); mediaFile.setVariableBitRate(metaData.getVariableBitRate()); mediaFile.setHeight(metaData.getHeight()); mediaFile.setWidth(metaData.getWidth()); } } else { // Is this an album? if (!isRoot(mediaFile)) { File[] children = FileUtil.listFiles(file); File firstChild = null; for (File child : filterMediaFiles(children)) { if (FileUtil.isFile(child)) { firstChild = child; break; } } if (firstChild != null) { mediaFile.setMediaType(ALBUM); // Guess artist/album name. MetaDataParser parser = metaDataParserFactory.getParser(firstChild); if (parser != null) { mediaFile.setArtist(parser.guessArtist(firstChild)); mediaFile.setAlbumName(parser.guessAlbum(firstChild, mediaFile.getArtist())); } // Look for cover art. try { File coverArt = findCoverArt(children); if (coverArt != null) { mediaFile.setCoverArtPath(coverArt.getPath()); } } catch (IOException x) { LOG.error("Failed to find cover art.", x); } } else { mediaFile.setArtist(file.getName()); } } } return mediaFile; }
From source file:net.ymate.module.oauth.client.base.OAuthAccount.java
public OAuthAccount(String id, String serviceUrl, String clientId, String clientSecret) { if (StringUtils.isBlank(id)) { throw new NullArgumentException("id"); }/*from w w w .ja v a 2s .com*/ if (StringUtils.isBlank(serviceUrl)) { throw new NullArgumentException("service_url"); } else if (!StringUtils.startsWithAny(StringUtils.lowerCase(serviceUrl), new String[] { "https://", "http://" })) { throw new IllegalArgumentException("service_url must be start with 'https://' or 'http://'."); } if (StringUtils.isBlank(clientId)) { throw new NullArgumentException("client_id"); } if (StringUtils.isBlank(clientSecret)) { throw new NullArgumentException("client_secret"); } this.id = id; this.serviceUrl = serviceUrl; this.clientId = clientId; this.clientSecret = clientSecret; }
From source file:net.ymate.module.oauth.client.base.OAuthAccount.java
public OAuthAccount(String id, String serviceUrl, String clientId, String clientSecret, String redirectUri) { this(id, serviceUrl, clientId, clientSecret); if (StringUtils.isNotBlank(redirectUri) && !StringUtils.startsWithAny(StringUtils.lowerCase(serviceUrl), new String[] { "https://", "http://" })) { throw new IllegalArgumentException("redirect_uri must be start with 'https://' or 'http://'."); }// w ww . j av a2s. co m this.redirectUri = redirectUri; }
From source file:net.ymate.module.webproxy.impl.DefaultModuleCfg.java
public DefaultModuleCfg(YMP owner) { Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IWebProxy.MODULE_NAME); ///*from w w w. ja va 2s.c om*/ __serviceBaseUrl = _moduleCfgs.get("service_base_url"); if (StringUtils.isBlank(__serviceBaseUrl)) { throw new NullArgumentException("service_base_url"); } if (!StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "http://") && !StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "https://")) { throw new IllegalArgumentException("Argument service_base_url must be start with http or https"); } else if (StringUtils.endsWith(__serviceBaseUrl, "/")) { __serviceBaseUrl = StringUtils.substringBeforeLast(__serviceBaseUrl, "/"); } // __serviceRequestPrefix = StringUtils.trimToEmpty(_moduleCfgs.get("service_request_prefix")); if (StringUtils.isNotBlank(__serviceRequestPrefix) && !StringUtils.startsWith(__serviceRequestPrefix, "/")) { __serviceRequestPrefix = "/" + __serviceRequestPrefix; } // __useProxy = BlurObject.bind(_moduleCfgs.get("use_proxy")).toBooleanValue(); if (__useProxy) { Proxy.Type _proxyType = Proxy.Type .valueOf(StringUtils.defaultIfBlank(_moduleCfgs.get("proxy_type"), "HTTP").toUpperCase()); int _proxyPrort = BlurObject.bind(StringUtils.defaultIfBlank(_moduleCfgs.get("proxy_port"), "80")) .toIntValue(); String _proxyHost = _moduleCfgs.get("proxy_host"); if (StringUtils.isBlank(_proxyHost)) { throw new NullArgumentException("proxy_host"); } __proxy = new Proxy(_proxyType, new InetSocketAddress(_proxyHost, _proxyPrort)); } // __useCaches = BlurObject.bind(_moduleCfgs.get("use_caches")).toBooleanValue(); __instanceFollowRedirects = BlurObject.bind(_moduleCfgs.get("instance_follow_redirects")).toBooleanValue(); // __connectTimeout = BlurObject.bind(_moduleCfgs.get("connect_timeout")).toIntValue(); __readTimeout = BlurObject.bind(_moduleCfgs.get("read_timeout")).toIntValue(); // __transferBlackList = Arrays .asList(StringUtils.split(StringUtils.trimToEmpty(_moduleCfgs.get("transfer_blacklist")), "|")); // __transferHeaderEnabled = BlurObject.bind(_moduleCfgs.get("transfer_header_enabled")).toBooleanValue(); // if (__transferHeaderEnabled) { String[] _filters = StringUtils .split(StringUtils.lowerCase(_moduleCfgs.get("transfer_header_whitelist")), "|"); if (_filters != null && _filters.length > 0) { __transferHeaderWhiteList = Arrays.asList(_filters); } else { __transferHeaderWhiteList = Collections.emptyList(); } // _filters = StringUtils.split(StringUtils.lowerCase(_moduleCfgs.get("transfer_header_blacklist")), "|"); if (_filters != null && _filters.length > 0) { __transferHeaderBlackList = Arrays.asList(_filters); } else { __transferHeaderBlackList = Collections.emptyList(); } // _filters = StringUtils.split(StringUtils.lowerCase(_moduleCfgs.get("response_header_whitelist")), "|"); if (_filters != null && _filters.length > 0) { __responseHeaderWhiteList = Arrays.asList(_filters); } else { __responseHeaderWhiteList = Collections.emptyList(); } } else { __transferHeaderWhiteList = Collections.emptyList(); __transferHeaderBlackList = Collections.emptyList(); // __responseHeaderWhiteList = Collections.emptyList(); } }
From source file:nl.nn.adapterframework.pipes.JsonPipe.java
public String getDirection() { return StringUtils.lowerCase(direction); }
From source file:nz.co.senanque.schemabuilder.NameHandler.java
private static String initialLowerCase(String str) { if (str == null) { return str; }/*from w w w . ja v a2 s . co m*/ if (str.length() < 2) { return StringUtils.lowerCase(str); } return Character.toLowerCase(str.charAt(0)) + str.substring(1); }
From source file:org.apache.ambari.server.api.services.ActiveWidgetLayoutService.java
private ResourceInstance createResource(String widgetLayoutId) { Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName)); return createResource(Resource.Type.ActiveWidgetLayout, mapIds); }