List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:io.wcm.handler.url.impl.UrlHandlerImpl.java
String buildUrl(String path, String selector, String extension, String suffix) { //NOPMD if (StringUtils.isBlank(path)) { return null; }// www. jav a2 s .c om // Extension url part StringBuilder extensionPart = new StringBuilder(); if (StringUtils.isNotBlank(extension)) { extensionPart.append('.').append(extension); } // Selector url part StringBuilder selectorPart = new StringBuilder(); if (StringUtils.isNotBlank(selector)) { // prepend delimiter to selector if required if (!StringUtils.startsWith(selector, ".")) { selectorPart.append('.'); } selectorPart.append(selector); } // Suffix part StringBuilder suffixPart = new StringBuilder(); if (StringUtils.isNotBlank(suffix)) { // prepend delimiter to suffix if required and add extension if (!StringUtils.startsWith(suffix, "/")) { suffixPart = suffixPart.append("/"); } suffixPart.append(suffix); // if suffix does not contain a file extension add main file extension if (!StringUtils.contains(suffix, ".")) { suffixPart.append(extensionPart); } // add a ".suffix" selector to avoid overlapping of filenames between suffixed and non-suffixed versions of the same page in the dispatcher cache selectorPart.append('.').append(UrlHandler.SELECTOR_SUFFIX); } // build externalized url return path + selectorPart.toString() + extensionPart.toString() + suffixPart.toString(); }
From source file:com.nhncorp.lucy.security.xss.listener.SecurityUtils.java
/** * @param type/*from www . ja va2s . c o m*/ * @return */ public static boolean isAllowedType(String type) { // embed ? type ?? text/* ?? if (StringUtils.isEmpty(type)) { return false; } else if (StringUtils.startsWith(type, "text/")) { return false; // TODO: MIME TYPES ? ?? ? ??? . ? ? ?. } else if (StringUtils.isNotEmpty(type) && !Constants.mimeTypes.values().contains(type)) { return false; } else { return true; } }
From source file:ch.cyberduck.core.preferences.UserDefaultsPreferences.java
@Override protected void setDefaults() { // Parent defaults super.setDefaults(); defaults.put("tmp.dir", FoundationKitFunctionsLibrary.NSTemporaryDirectory()); final NSBundle bundle = this.bundle; if (null != bundle) { if (bundle.objectForInfoDictionaryKey("CFBundleName") != null) { defaults.put("application.name", bundle.objectForInfoDictionaryKey("CFBundleName").toString()); }// w w w .j ava2 s. c o m if (bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright") != null) { defaults.put("application.copyright", bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright").toString()); } if (bundle.objectForInfoDictionaryKey("CFBundleIdentifier") != null) { defaults.put("application.identifier", bundle.objectForInfoDictionaryKey("CFBundleIdentifier").toString()); } if (bundle.objectForInfoDictionaryKey("CFBundleShortVersionString") != null) { defaults.put("application.version", bundle.objectForInfoDictionaryKey("CFBundleShortVersionString").toString()); } if (bundle.objectForInfoDictionaryKey("CFBundleVersion") != null) { defaults.put("application.revision", bundle.objectForInfoDictionaryKey("CFBundleVersion").toString()); } defaults.put("application.receipt.path", String.format("%s/Contents/_MASReceipt", bundle.bundlePath())); } final Local resources = ApplicationResourcesFinderFactory.get().find(); defaults.put("application.bookmarks.path", String.format("%s/Bookmarks", resources.getAbsolute())); defaults.put("application.profiles.path", String.format("%s/Profiles", resources.getAbsolute())); defaults.put("update.feed.release", "https://version.cyberduck.io/changelog.rss"); defaults.put("update.feed.beta", "https://version.cyberduck.io/beta/changelog.rss"); defaults.put("update.feed.nightly", "https://version.cyberduck.io/nightly/changelog.rss"); // Fix #9395 if (!StringUtils.startsWith(this.getProperty(Updater.PROPERTY_FEED_URL), Scheme.https.name())) { this.deleteProperty(Updater.PROPERTY_FEED_URL); this.save(); } defaults.put("bookmark.import.filezilla.location", "~/.config/filezilla/sitemanager.xml"); defaults.put("bookmark.import.fetch.location", "~/Library/Preferences/com.fetchsoftworks.Fetch.Shortcuts.plist"); defaults.put("bookmark.import.flow.location", "~/Library/Application Support/Flow/Bookmarks.plist"); defaults.put("bookmark.import.interarchy.location", "~/Library/Application Support/Interarchy/Bookmarks.plist"); defaults.put("bookmark.import.transmit.location", "~/Library/Preferences/com.panic.Transmit.plist"); defaults.put("bookmark.import.transmit4.location", "~/Library/Application Support/Transmit/Favorites/Favorites.xml"); defaults.put("bookmark.import.crossftp.location", "~/.crossftp/sites.xml"); defaults.put("bookmark.import.fireftp.location", "~/Library/Application Support/Firefox/Profiles"); defaults.put("bookmark.import.expandrive3.location", "~/Library/Application Support/ExpanDrive/favorites.js"); defaults.put("bookmark.import.expandrive4.location", "~/Library/Application Support/ExpanDrive/expandrive4.favorites.js"); defaults.put("bookmark.import.expandrive5.location", "~/Library/Application Support/ExpanDrive/expandrive5.favorites.js"); if (LocalFactory.get("~/Downloads").exists()) { // For 10.5+ this usually exists and should be preferrred defaults.put("queue.download.folder", "~/Downloads"); } else { defaults.put("queue.download.folder", "~/Desktop"); } defaults.put("browser.filesize.decimal", String.valueOf(!Factory.Platform.osversion.matches("10\\.5.*"))); // SSL Keystore defaults.put("connection.ssl.keystore.type", "KeychainStore"); defaults.put("connection.ssl.keystore.provider", "Apple"); defaults.put("network.interface.blacklist", "awdl0 utun0"); defaults.put("browser.window.tabbing.identifier", "browser.window.tabbing.identifier"); // Allow to show transfers in browser window as tab defaults.put("queue.window.tabbing.identifier", "browser.window.tabbing.identifier"); }
From source file:io.wcm.maven.plugins.contentpackage.InstallMojo.java
/** * Deploy file via package manager// www . ja v a 2s .c o m */ private void installFile(File file) throws MojoExecutionException { try (CloseableHttpClient httpClient = getHttpClient()) { // if bundles are still stopping/starting, wait for completion waitForBundlesActivation(httpClient); if (this.install) { getLog().info("Upload and install " + file.getName() + " to " + getCrxPackageManagerUrl()); } else { getLog().info("Upload " + file.getName() + " to " + getCrxPackageManagerUrl()); } // prepare post method HttpPost post = new HttpPost(getCrxPackageManagerUrl() + "/.json?cmd=upload"); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create().addBinaryBody("package", file); if (this.force) { entityBuilder.addTextBody("force", "true"); } post.setEntity(entityBuilder.build()); // execute post JSONObject jsonResponse = executePackageManagerMethodJson(httpClient, post); boolean success = jsonResponse.optBoolean("success", false); String msg = jsonResponse.optString("msg", null); String path = jsonResponse.optString("path", null); if (success) { if (this.install) { getLog().info("Package uploaded, now installing..."); try { post = new HttpPost(getCrxPackageManagerUrl() + "/console.html" + new URIBuilder().setPath(path).build().getRawPath() + "?cmd=install" + (this.recursive ? "&recursive=true" : "")); } catch (URISyntaxException ex) { throw new MojoExecutionException("Invalid path: " + path, ex); } // execute post executePackageManagerMethodHtml(httpClient, post, 0); } else { getLog().info("Package uploaded successfully (without installing)."); } } else if (StringUtils.startsWith(msg, CRX_PACKAGE_EXISTS_ERROR_MESSAGE_PREFIX) && !this.force) { getLog().info("Package skipped because it was already uploaded."); } else { throw new MojoExecutionException("Package upload failed: " + msg); } } catch (IOException ex) { throw new MojoExecutionException("Install operation failed.", ex); } }
From source file:com.thruzero.domain.service.impl.AbstractInfoNodeService.java
@Override public InfoNodeElement getFirstInfoNode(final EntityPath entityPath, final String xpathExpr) { InfoNodeElement result = null;//from w w w.java 2 s . c om InfoNodeElement infoNode = getInfoNode(entityPath); if (infoNode != null) { try { if (StringUtils.startsWith(xpathExpr, "//")) { infoNode.enableRootNode(); } result = (InfoNodeElement) infoNode.find(xpathExpr); } catch (JDOMException e) { throw new RuntimeException("Exception while attempting to find node using xpathExpr: " + xpathExpr, e); } } return result; }
From source file:gobblin.util.ConfigUtils.java
/** * Convert all the keys that start with a <code>prefix</code> in {@link Properties} to a {@link Config} instance. * * <p>// w w w . j a va2s . com * This method will throw an exception if (1) the {@link Object#toString()} method of any two keys in the * {@link Properties} objects returns the same {@link String}, or (2) if any two keys are prefixes of one another, * see the Java Docs of {@link ConfigFactory#parseMap(Map)} for more details. * </p> * * @param properties the given {@link Properties} instance * @param prefix of keys to be converted * @return a {@link Config} instance */ public static Config propertiesToConfig(Properties properties, Optional<String> prefix) { Set<String> blacklistedKeys = new HashSet<>(); if (properties.containsKey(GOBBLIN_CONFIG_BLACKLIST_KEYS)) { blacklistedKeys = new HashSet<>(Splitter.on(',').omitEmptyStrings().trimResults() .splitToList(properties.getProperty(GOBBLIN_CONFIG_BLACKLIST_KEYS))); } Set<String> fullPrefixKeys = findFullPrefixKeys(properties, prefix); ImmutableMap.Builder<String, Object> immutableMapBuilder = ImmutableMap.builder(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, prefix.or(StringUtils.EMPTY)) && !blacklistedKeys.contains(entryKey)) { if (fullPrefixKeys.contains(entryKey)) { entryKey = sanitizeFullPrefixKey(entryKey); } else if (entryKey.endsWith(STRIP_SUFFIX)) { throw new RuntimeException("Properties are not allowed to end in " + STRIP_SUFFIX); } immutableMapBuilder.put(entryKey, entry.getValue()); } } return ConfigFactory.parseMap(immutableMapBuilder.build()); }
From source file:com.adguard.filter.rules.FilterRule.java
/** * Loads PermittedDomains and RestrictedDomains collections * from the rule text/*from ww w . ja va 2 s . c om*/ * * @param domains Domains part of the rule text */ protected void loadDomains(String domains) { if (StringUtils.isEmpty(domains)) { return; } String[] parts = StringUtils.split(domains, new String(new char[] { COMA_DELIMITER, LINE_DELIMITER })); try { for (String domain : parts) { if (StringUtils.startsWith(domain, NOT_MARK)) { String domainName = toPunycode(domain.substring(1).trim()); if (StringUtils.isNotEmpty(domainName)) { addRestrictedDomain(domainName); } } else { String domainName = toPunycode(domain.trim()); if (StringUtils.isNotEmpty(domainName)) { addPermittedDomain(domainName); } } } } catch (Exception ex) { LoggerFactory.getLogger(this.getClass()).error("Error while loading domains from " + domains, ex); } }
From source file:eionet.webq.web.controller.WebQProxyDelegation.java
/** * /**// ww w .j a va2 s . c o m * This method delegates GET request to remote host using authorisation stored in UserFile. * * @param uri the actual uri to make the request * @param fileId user session file id * @param request standard HttpServletRequest * @return result request results received from uri * @throws URISyntaxException wrong uri of remote file * @throws FileNotAvailableException the remote file is not available * @throws UnsupportedEncodingException unable to convert the remote file to UTF-8 */ @RequestMapping(value = "/restProxyWithAuth", method = RequestMethod.GET, produces = "text/html;charset=utf-8") @ResponseBody public String restProxyGetWithAuth(@RequestParam("uri") String uri, @RequestParam int fileId, HttpServletRequest request) throws URISyntaxException, FileNotAvailableException, UnsupportedEncodingException { UserFile file = userFileHelper.getUserFile(fileId, request); if (file != null && ProxyDelegationHelper.isCompanyIdParameterValidForBdrEnvelope(uri, file.getEnvelope())) { if (StringUtils.startsWith(uri, file.getEnvelope())) { return new String(envelopeService.fetchFileFromCdr(file, uri).getBody(), "UTF-8"); } else if (file.isAuthorized()) { // check if we have known host in db KnownHost knownHost = knownHostsService.getKnownHost(uri); if (knownHost != null) { if (knownHost.getAuthenticationMethod() == KnownHostAuthenticationMethod.REQUEST_PARAMETER) { // add ticket parameter to request URI if needed LOGGER.info("Add ticket parameter from known hosts to URL: " + uri); uri += (uri.contains("?")) ? "&" : "?"; uri += knownHost.getKey() + "=" + knownHost.getTicket(); } else if (knownHost.getAuthenticationMethod() == KnownHostAuthenticationMethod.BASIC) { // Add basic authorisation if needed HttpHeaders authorization = getHttpHeaderWithBasicAuthentication(knownHost); LOGGER.info("Add basic auth from known hosts to URL: " + uri); String response = (restTemplate.exchange(new URI(uri), HttpMethod.GET, new HttpEntity<Object>(authorization), String.class)).getBody(); return response; } } } } LOGGER.info("/restProxy [GET] uri=" + uri); if (new URI(uri).isAbsolute()) { return restTemplate.getForObject(uri, String.class); } else { // todo fix for local /download/file_id= return restTemplate.getForObject(new URI(uri), String.class); } }
From source file:io.kahu.hawaii.util.call.sql.DbRequestBuilderRepository.java
private void load(final String resourcePath) { String directory = resourcePath; if (!StringUtils.startsWith(directory, "/")) { directory = "/" + directory; }//from ww w.j ava 2 s.c o m if (!StringUtils.endsWith(directory, "/")) { directory += "/"; } walkDirectory(directory); }
From source file:com.pidoco.juri.JURI.java
@Nullable private CharSequence buildHostString() { String decodedHost = this.host; if (decodedHost == null) { decodedHost = prototype.getHost(); }/*from w ww .j av a 2s . c o m*/ if (StringUtils.startsWith(decodedHost, "[") && StringUtils.endsWith(decodedHost, "]")) { return decodedHost; // ipv6 and other address literal that is not encoded (at least currently) } return urlEncode(decodedHost); }