List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:org.apache.maven.scm.provider.svn.svnjava.command.remoteinfo.SvnJavaRemoteInfoCommand.java
@Override public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { SvnJavaScmProviderRepository javaRepo = (SvnJavaScmProviderRepository) repository; String url = ((SvnScmProviderRepository) repository).getUrl(); // use a default svn layout, url is here http://svn.apache.org/repos/asf/maven/maven-3/trunk // so as we presume we have good users using standard svn layout, we calculate tags and branches url String baseUrl = StringUtils.endsWith(url, "/") ? StringUtils.substringAfter(StringUtils.removeEnd(url, "/"), "/") : StringUtils.substringBeforeLast(url, "/"); RemoteInfoScmResult remoteInfoScmResult = new RemoteInfoScmResult(null, null, null, true); try {/*from w ww. j a va2s .co m*/ DirEntryHandler dirEntryHandler = new DirEntryHandler(baseUrl); javaRepo.getClientManager().getLogClient().doList(SVNURL.parseURIEncoded(baseUrl + "/tags"), SVNRevision.HEAD, SVNRevision.HEAD, false, false, dirEntryHandler); remoteInfoScmResult.setTags(dirEntryHandler.infos); } catch (SVNException e) { return new RemoteInfoScmResult(null, e.getMessage(), null, false); } try { DirEntryHandler dirEntryHandler = new DirEntryHandler(baseUrl); javaRepo.getClientManager().getLogClient().doList(SVNURL.parseURIEncoded(baseUrl + "/branches"), SVNRevision.HEAD, SVNRevision.HEAD, false, false, dirEntryHandler); remoteInfoScmResult.setBranches(dirEntryHandler.infos); } catch (SVNException e) { return new RemoteInfoScmResult(null, e.getMessage(), null, false); } return remoteInfoScmResult; }
From source file:org.apache.ranger.plugin.resourcematcher.RangerAbstractResourceMatcher.java
@Override boolean isMatch(String resourceValue, Map<String, Object> evalContext) { return StringUtils.endsWith(resourceValue, getExpandedValue(evalContext)); }
From source file:org.apache.sling.its.servlets.ItsImportServlet.java
/** * Store the element and its attribute. The child node of global rules are * specially handled so they will not be traversed. * * @param path// www. j a v a 2 s.c om * the target path * @param resourceType * the resourceType * @param doc * the document * @param file * the file. * @param isExternalDoc * true if this is for storing global rules for external documents */ private void store(String path, final String resourceType, final Document doc, final File file, final boolean isExternalDoc) { final ITraversal itsEng = applyITSRules(doc, file, null, false); itsEng.startTraversal(); Node node; while ((node = itsEng.nextNode()) != null) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: final Element element = (Element) node; // Use !backTracking() to get to the elements only once // and to include the empty elements (for attributes). if (itsEng.backTracking()) { if (!SlingItsConstants.getGlobalRules().containsKey(element.getLocalName())) { path = backTrack(path); } } else { if (element.isSameNode(doc.getDocumentElement()) && !isExternalDoc) { path += "/" + element.getNodeName(); output(path, null, null); setAttributes(element, path); } else if (SlingItsConstants.getGlobalRules().containsKey(element.getLocalName())) { storeGlobalRule(element, resourceType, itsEng); } else if (!isExternalDoc && !SlingItsConstants.getGlobalRules().containsKey(element.getLocalName()) && !(element.getParentNode().getLocalName().equals(SlingItsConstants.ITS_RULES) && element.getParentNode().getPrefix() != null)) { if (element.getLocalName().equals(SlingItsConstants.ITS_RULES) && element.getPrefix() != null) { this.hasGlobalRules = true; } if (element.getPrefix() != null) { path += String.format("/%s(%d)", element.getLocalName(), getCounter(path + "/" + element.getLocalName())); element.setAttribute(SlingItsConstants.NODE_PREFIX, element.getPrefix()); } else if (element.getNodeName().equals("link") && StringUtils.endsWith(element.getAttribute("rel"), "-rules")) { path += String.format("/%s(%d)", SlingItsConstants.ITS_RULES, getCounter(path + "/" + SlingItsConstants.ITS_RULES)); final String prefix = StringUtils.substringBefore(element.getAttribute("rel"), "-rules"); element.setAttribute(SlingItsConstants.NODE_PREFIX, prefix); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, SlingItsConstants.XMLNS + prefix, Namespaces.ITS_NS_URI); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:h", Namespaces.HTML_NS_URI); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:jcr", NamespaceRegistry.NAMESPACE_JCR); this.hasGlobalRules = true; } else { path += String.format("/%s(%d)", element.getNodeName(), getCounter(path + "/" + element.getNodeName())); } output(path, null, null); setAttributes(element, path); if (!element.hasChildNodes()) // Empty elements: { path = backTrack(path); } } } break; case Node.TEXT_NODE: if (StringUtils.isNotBlank(node.getNodeValue()) && !isExternalDoc) { path += String.format("/%s(%d)", SlingItsConstants.TEXT_CONTENT_NODE, getCounter(path + "/" + SlingItsConstants.TEXT_CONTENT_NODE)); output(path, null, node.getNodeValue()); path = backTrack(path); } break; default: break; } } }
From source file:org.apache.solr.handler.component.AlfrescoHttpShardHandlerFactory.java
@Override public void init(PluginInfo info) { NamedList args = info.initArgs;//from ww w.j a v a 2s. c o m this.soTimeout = getParameter(args, HttpClientUtil.PROP_SO_TIMEOUT, soTimeout); this.scheme = getParameter(args, INIT_URL_SCHEME, null); if (StringUtils.endsWith(this.scheme, "://")) { this.scheme = StringUtils.removeEnd(this.scheme, "://"); } this.connectionTimeout = getParameter(args, HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); this.maxConnectionsPerHost = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); this.corePoolSize = getParameter(args, INIT_CORE_POOL_SIZE, corePoolSize); this.maximumPoolSize = getParameter(args, INIT_MAX_POOL_SIZE, maximumPoolSize); this.keepAliveTime = getParameter(args, MAX_THREAD_IDLE_TIME, keepAliveTime); this.queueSize = getParameter(args, INIT_SIZE_OF_QUEUE, queueSize); this.accessPolicy = getParameter(args, INIT_FAIRNESS_POLICY, accessPolicy); // magic sysprop to make tests reproducible: set by SolrTestCaseJ4. String v = System.getProperty("tests.shardhandler.randomSeed"); if (v != null) { r.setSeed(Long.parseLong(v)); } BlockingQueue<Runnable> blockingQueue = (this.queueSize == -1) ? new SynchronousQueue<Runnable>(this.accessPolicy) : new ArrayBlockingQueue<Runnable>(this.queueSize, this.accessPolicy); this.commExecutor = new ThreadPoolExecutor(this.corePoolSize, this.maximumPoolSize, this.keepAliveTime, TimeUnit.SECONDS, blockingQueue, new DefaultSolrThreadFactory("httpShardExecutor")); ModifiableSolrParams clientParams = new ModifiableSolrParams(); clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000); clientParams.set(HttpClientUtil.PROP_SO_TIMEOUT, soTimeout); clientParams.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); clientParams.set(HttpClientUtil.PROP_USE_RETRY, false); this.defaultClient = HttpClientUtil.createClient(clientParams); this.loadbalancer = createLoadbalancer(defaultClient); }
From source file:org.apache.solr.handler.component.HttpShardHandlerFactory.java
@Override public void init(PluginInfo info) { StringBuilder sb = new StringBuilder(); NamedList args = info.initArgs;/* ww w . j ava2 s . com*/ this.soTimeout = getParameter(args, HttpClientUtil.PROP_SO_TIMEOUT, soTimeout, sb); this.scheme = getParameter(args, INIT_URL_SCHEME, null, sb); if (StringUtils.endsWith(this.scheme, "://")) { this.scheme = StringUtils.removeEnd(this.scheme, "://"); } String strategy = getParameter(args, "metricNameStrategy", UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY, sb); this.metricNameStrategy = KNOWN_METRIC_NAME_STRATEGIES.get(strategy); if (this.metricNameStrategy == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown metricNameStrategy: " + strategy + " found. Must be one of: " + KNOWN_METRIC_NAME_STRATEGIES.keySet()); } this.connectionTimeout = getParameter(args, HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout, sb); this.maxConnectionsPerHost = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost, sb); this.maxConnections = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections, sb); this.corePoolSize = getParameter(args, INIT_CORE_POOL_SIZE, corePoolSize, sb); this.maximumPoolSize = getParameter(args, INIT_MAX_POOL_SIZE, maximumPoolSize, sb); this.keepAliveTime = getParameter(args, MAX_THREAD_IDLE_TIME, keepAliveTime, sb); this.queueSize = getParameter(args, INIT_SIZE_OF_QUEUE, queueSize, sb); this.accessPolicy = getParameter(args, INIT_FAIRNESS_POLICY, accessPolicy, sb); log.debug("created with {}", sb); // magic sysprop to make tests reproducible: set by SolrTestCaseJ4. String v = System.getProperty("tests.shardhandler.randomSeed"); if (v != null) { r.setSeed(Long.parseLong(v)); } BlockingQueue<Runnable> blockingQueue = (this.queueSize == -1) ? new SynchronousQueue<Runnable>(this.accessPolicy) : new ArrayBlockingQueue<Runnable>(this.queueSize, this.accessPolicy); this.commExecutor = new ExecutorUtil.MDCAwareThreadPoolExecutor(this.corePoolSize, this.maximumPoolSize, this.keepAliveTime, TimeUnit.SECONDS, blockingQueue, new DefaultSolrThreadFactory("httpShardExecutor")); ModifiableSolrParams clientParams = getClientParams(); httpRequestExecutor = new InstrumentedHttpRequestExecutor(this.metricNameStrategy); clientConnectionManager = new InstrumentedPoolingHttpClientConnectionManager( HttpClientUtil.getSchemaRegisteryProvider().getSchemaRegistry()); this.defaultClient = HttpClientUtil.createClient(clientParams, clientConnectionManager, false, httpRequestExecutor); this.loadbalancer = createLoadbalancer(defaultClient); }
From source file:org.apache.struts2.osgi.BaseOsgiHost.java
protected List<String> getBundlesInDir(String dir) { List<String> bundleJars = new ArrayList<String>(); try {//from w w w .j a v a2 s.c o m ResourceFinder finder = new ResourceFinder(); URL url = finder.find(dir); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); File[] bundles = bundlesDir.listFiles(new FilenameFilter() { public boolean accept(File file, String name) { return StringUtils.endsWith(name, ".jar"); } }); if (bundles != null && bundles.length > 0) { //add all the bundles to the list for (File bundle : bundles) { String externalForm = bundle.toURI().toURL().toExternalForm(); if (LOG.isDebugEnabled()) { LOG.debug("Adding bundle [#0]", externalForm); } bundleJars.add(externalForm); } } else if (LOG.isDebugEnabled()) { LOG.debug("No bundles found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) LOG.warn("Unable to read [#0] directory", dir); } else if (LOG.isWarnEnabled()) LOG.warn("The [#0] directory was not found", dir); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Unable load bundles from the [#0] directory", e, dir); } return bundleJars; }
From source file:org.apache.struts2.osgi.host.BaseOsgiHost.java
protected List<String> getBundlesInDir(String dir) { List<String> bundleJars = new ArrayList<String>(); try {//from w w w .j a va 2s . com ResourceFinder finder = new ResourceFinder(); URL url = finder.find(dir); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); File[] bundles = bundlesDir.listFiles(new FilenameFilter() { public boolean accept(File file, String name) { return StringUtils.endsWith(name, ".jar"); } }); if (bundles != null && bundles.length > 0) { //add all the bundles to the list for (File bundle : bundles) { String externalForm = bundle.toURI().toURL().toExternalForm(); if (LOG.isDebugEnabled()) { LOG.debug("Adding bundle [#0]", externalForm); } bundleJars.add(externalForm); } } else if (LOG.isDebugEnabled()) { LOG.debug("No bundles found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) { LOG.warn("Unable to read [#0] directory", dir); } } else if (LOG.isWarnEnabled()) { LOG.warn("The [#0] directory was not found", dir); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Unable load bundles from the [#0] directory", e, dir); } } return bundleJars; }
From source file:org.artifactory.api.maven.MavenArtifactInfo.java
public static MavenArtifactInfo fromRepoPath(RepoPath repoPath) { String groupId, artifactId, version, type = MavenArtifactInfo.NA, classifier = MavenArtifactInfo.NA; String path = repoPath.getPath(); String fileName = repoPath.getName(); //The format of the relative path in maven is a/b/c/artifactId/baseVer/fileName where //groupId="a.b.c". We split the path to elements and analyze the needed fields. LinkedList<String> pathElements = new LinkedList<>(); StringTokenizer tokenizer = new StringTokenizer(path, "/"); while (tokenizer.hasMoreTokens()) { pathElements.add(tokenizer.nextToken()); }//from ww w .j av a 2 s . co m //Sanity check, we need groupId, artifactId and version if (pathElements.size() < 3) { log.debug( "Cannot build MavenArtifactInfo from '{}'. The groupId, artifactId and version are unreadable.", repoPath); return new MavenArtifactInfo(); } //Extract the version, artifactId and groupId int pos = pathElements.size() - 2; // one before the last path element version = pathElements.get(pos--); artifactId = pathElements.get(pos--); StringBuilder groupIdBuff = new StringBuilder(); for (; pos >= 0; pos--) { if (groupIdBuff.length() != 0) { groupIdBuff.insert(0, '.'); } groupIdBuff.insert(0, pathElements.get(pos)); } groupId = groupIdBuff.toString(); //Extract the type and classifier except for metadata files boolean metaData = NamingUtils.isMetadata(fileName); if (!metaData) { if (MavenNaming.isUniqueSnapshotFileName(fileName)) { version = StringUtils.remove(version, "-" + MavenNaming.SNAPSHOT); version = version + "-" + MavenNaming.getUniqueSnapshotVersionTimestampAndBuildNumber(fileName); } type = StringUtils.substring(fileName, artifactId.length() + version.length() + 2); int versionStartIndex = StringUtils.indexOf(fileName, "-", artifactId.length()) + 1; int classifierStartIndex = StringUtils.indexOf(fileName, "-", versionStartIndex + version.length()); if (classifierStartIndex >= 0) { Set<String> customMavenTypes = getMavenCustomTypes(); for (String customMavenType : customMavenTypes) { if (StringUtils.endsWith(fileName, customMavenType)) { classifier = StringUtils.remove(type, "." + customMavenType); type = customMavenType; break; } } if (MavenArtifactInfo.NA.equals(classifier)) { int typeDotStartIndex = StringUtils.lastIndexOf(type, "."); classifier = StringUtils.substring(type, 0, typeDotStartIndex); type = StringUtils.substring(type, classifier.length() + 1); } } } return new MavenArtifactInfo(groupId, artifactId, version, classifier, type); }
From source file:org.artifactory.repo.interceptor.YumCalculationInterceptor.java
private boolean isYumGroupFile(final String path, LocalRepoDescriptor hostingLocalRepo) { List<String> yumGroupFileNames = PathUtils .delimitedListToStringList(hostingLocalRepo.getYumGroupFileNames(), ","); return StringUtils.isNotBlank(Iterables.find(yumGroupFileNames, new Predicate<String>() { @Override//from w w w . ja va 2 s . co m public boolean apply(@Nullable String input) { return StringUtils.endsWith(path, YumAddon.REPO_DATA_DIR + input); } }, null)); }
From source file:org.artifactory.repo.service.DeployServiceImpl.java
private void assertNotFailedRequest(String deployedFileName, InternalArtifactoryResponse response) throws RepoRejectException { if (!response.isSuccessful()) { StringBuilder errorMessageBuilder = new StringBuilder("Cannot deploy file '").append(deployedFileName) .append("'. "); String statusMessage = response.getStatusMessage(); if (StringUtils.isNotBlank(statusMessage)) { errorMessageBuilder.append(statusMessage); if (!StringUtils.endsWith(statusMessage, ".")) { errorMessageBuilder.append("."); }//from w w w . jav a2 s . c o m } else { errorMessageBuilder.append("Please view the logs for further information."); } throw new RepoRejectException(errorMessageBuilder.toString()); } }