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.eclipse.gyrex.admin.ui.internal.servlets.AdminServletTracker.java
@Override public AdminServletHolder addingService(final ServiceReference<IAdminServlet> reference) { final IAdminServlet servlet = context.getService(reference); if (servlet == null) return null; final AdminServletHolder holder = new AdminServletHolder(servlet); final Object alias = reference.getProperty("http.alias"); if (alias instanceof String) { String pathSpec = (String) alias; // convert to path spec if (!StringUtils.endsWith(pathSpec, "/*")) { pathSpec = StringUtils.removeEnd(pathSpec, "/") + "/*"; }/* www. j av a 2 s . c om*/ try { // register servlet contextHandler.getServletHandler().addServlet(holder); // create, remember & register mapping final ServletMapping mapping = new ServletMapping(); mapping.setPathSpec(pathSpec); mapping.setServletName(holder.getName()); holder.setServletMapping(mapping); contextHandler.getServletHandler().addServletMapping(mapping); } catch (final Exception e) { LOG.error("Error registering contributed servlet {} ({}). {}", reference, pathSpec, ExceptionUtils.getRootCauseMessage(e), e); } } return holder; }
From source file:org.eclipse.gyrex.p2.internal.commands.ListCommand.java
private void listArtifacts() throws Exception { IProvisioningAgent agent = null;//from w w w.j a va 2s . c o m try { // get agent agent = P2Activator.getInstance().getService(IProvisioningAgentProvider.class).createAgent(null); if (agent == null) throw new IllegalStateException( "The current system has not been provisioned using p2. Unable to acquire provisioning agent."); final IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent .getService(IMetadataRepositoryManager.SERVICE_NAME); if (manager == null) throw new IllegalStateException( "The provision system is broken. Unable to acquire metadata repository service."); // sync repos RepoUtil.configureRepositories(manager, (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME)); // load repos final URI[] knownRepositories = manager .getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_SYSTEM); for (final URI uri : knownRepositories) { printf("Loading %s", uri.toString()); manager.loadRepository(uri, new NullProgressMonitor()); } // query for everything that provides an OSGi bundle and features IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery( "properties[$0] == true || providedCapabilities.exists(p | p.namespace == 'osgi.bundle')", //$NON-NLS-1$ new Object[] { MetadataFactory.InstallableUnitDescription.PROP_TYPE_GROUP }); // wrap query if necessary if (latestVersionOnly) { query = QueryUtil.createPipeQuery(query, QueryUtil.createLatestIUQuery()); } // execute printf("Done loading. Searching..."); final SortedSet<String> result = new TreeSet<>(); for (final Iterator stream = manager.query(query, new NullProgressMonitor()).iterator(); stream .hasNext();) { final IInstallableUnit iu = (IInstallableUnit) stream.next(); // exclude fragments if ((iu.getFragments() != null) && (iu.getFragments().size() > 0)) { continue; } final String id = iu.getId(); // exclude source IUs if (StringUtils.endsWith(id, ".source") || StringUtils.endsWith(id, ".source.feature.group")) { continue; } // get name String name = iu.getProperty(IInstallableUnit.PROP_NAME, null); if ((name == null) || name.startsWith("%")) { name = ""; //$NON-NLS-1$ } // check if filter is provided if (StringUtils.isBlank(filterString) || StringUtils.containsIgnoreCase(id, filterString) || StringUtils.containsIgnoreCase(name, filterString)) { result.add(String.format("%s (%s, %s)", name, id, iu.getVersion())); } } if (result.isEmpty()) { printf("No artifacts found!"); } else { printf("Found %d artifacts:", result.size()); for (final String artifact : result) { printf(artifact); } } } finally { if (null != agent) { agent.stop(); } } }
From source file:org.eclipse.mylyn.internal.gerrit.core.GerritConnector.java
Status toStatus(TaskRepository repository, String qualifier, Exception e) { if (StringUtils.isEmpty(qualifier)) { qualifier = ""; //$NON-NLS-1$ } else if (!StringUtils.endsWith(qualifier, ": ")) { //$NON-NLS-1$ qualifier += ": "; //$NON-NLS-1$ }/*from w w w .jav a 2 s . c o m*/ if (e instanceof GerritHttpException) { int code = ((GerritHttpException) e).getResponseCode(); return createErrorStatus(repository, qualifier + HttpStatus.getStatusText(code)); } else if (e instanceof GerritLoginException) { if (repository != null) { return RepositoryStatus.createLoginError(repository.getUrl(), GerritCorePlugin.PLUGIN_ID); } else { return createErrorStatus(null, qualifier + "Unknown Host"); //$NON-NLS-1$ } } else if (e instanceof UnknownHostException) { return createErrorStatus(repository, qualifier + "Unknown Host"); //$NON-NLS-1$ } else if (e instanceof GerritException && e.getCause() != null) { Throwable cause = e.getCause(); if (cause instanceof Exception) { return toStatus(repository, qualifier, (Exception) cause); } } else if (e instanceof GerritException && e.getMessage() != null) { return createErrorStatus(repository, NLS.bind("{0}Gerrit connection issue: {1}", qualifier, e.getMessage())); //$NON-NLS-1$ } String message = NLS.bind("{0}Unexpected error while connecting to Gerrit: {1}", qualifier, e.getMessage()); //$NON-NLS-1$ if (repository != null) { return RepositoryStatus.createStatus(repository, IStatus.ERROR, GerritCorePlugin.PLUGIN_ID, message); } else { return createErrorStatus(repository, message); } }
From source file:org.eclipse.smarthome.model.script.actions.ScriptExecution.java
/** * Calls a script which must be located in the configurations/scripts folder. * //from ww w .ja v a2 s. c o m * @param scriptName the name of the script (if the name does not end with * the .script file extension it is added) * * @return the return value of the script * @throws ScriptExecutionException if an error occurs during the execution */ public static Object callScript(String scriptName) throws ScriptExecutionException { ModelRepository repo = ScriptActivator.modelRepositoryTracker.getService(); if (repo != null) { String scriptNameWithExt = scriptName; if (!StringUtils.endsWith(scriptName, Script.SCRIPT_FILEEXT)) { scriptNameWithExt = scriptName + "." + Script.SCRIPT_FILEEXT; } XExpression expr = (XExpression) repo.getModel(scriptNameWithExt); if (expr != null) { ScriptEngine scriptEngine = ScriptActivator.scriptEngineTracker.getService(); if (scriptEngine != null) { Script script = scriptEngine.newScriptFromXExpression(expr); return script.execute(); } else { throw new ScriptExecutionException("Script engine is not available."); } } else { throw new ScriptExecutionException("Script '" + scriptName + "' cannot be found."); } } else { throw new ScriptExecutionException("Model repository is not available."); } }
From source file:org.ejbca.core.protocol.ws.client.NestedCrmfRequestTestCommand.java
private void writeCertificate(X509Certificate cert, String path, String filename) { if (!StringUtils.endsWith(path, "/")) { path = path + "/"; }//from w w w. ja v a2s . c o m ArrayList<Certificate> certCollection = new ArrayList<Certificate>(); certCollection.add(cert); try { byte[] pemRaCert = CertTools.getPEMFromCerts(certCollection); FileOutputStream out = new FileOutputStream(new File(path + filename)); out.write(pemRaCert); out.close(); } catch (CertificateException e) { e.printStackTrace(getPrintStream()); System.exit(-1); } catch (FileNotFoundException e) { e.printStackTrace(getPrintStream()); System.exit(-1); } catch (IOException e) { e.printStackTrace(getPrintStream()); System.exit(-1); } }
From source file:org.ejbca.ui.cmpclient.commands.CrmfRequestCommand.java
private String getDestinationCertFile(final String destDirectory, final String subjectDN) { return destDirectory + (StringUtils.endsWith(destDirectory, "/") ? "" : "/") + CertTools.getPartFromDN(subjectDN, "CN") + ".pem"; }
From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserController.java
@RequestMapping(value = "listObjects", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)//w ww . j a va 2s . co m public Response listObjects(@RequestParam(required = false) String bucketName, @RequestParam(required = false) String prefix, @RequestParam(required = false) String continuationToken) { // Get bucket list if (StringUtils.isEmpty(bucketName)) { Response response = new Response(); response.getList().addAll(getBucketList()); response.setSuccess(true); return response; } // Get folder & bucket list ListObjectsV2Result result = s3BrowserService.listObjects(bucketName, prefix, continuationToken); List<S3ObjectInfo> list = new ArrayList<>(); List<String> commonPrefixes = result.getCommonPrefixes(); for (String key : commonPrefixes) { S3ObjectInfo object = new S3ObjectInfo(); object.setBucketName(bucketName); object.setKey(key); object.setName(getName(key)); object.setFolder(true); list.add(object); } List<S3ObjectSummary> objectSummaries = result.getObjectSummaries(); if (!StringUtils.endsWith(prefix, S3Constansts.DELIMITER)) { prefix = prefix + S3Constansts.DELIMITER; } for (S3ObjectSummary s3Object : objectSummaries) { String key = s3Object.getKey(); if (prefix.equals(key)) { continue; } S3ObjectInfo object = new S3ObjectInfo(); object.setBucketName(bucketName); object.setPrefix(prefix); object.setKey(key); object.setName(getName(key)); object.setObject(true); object.setSize(s3Object.getSize()); object.setLastModified(s3Object.getLastModified()); object.setStorageClass(s3Object.getStorageClass()); list.add(object); } Map<String, String> map = new HashMap<>(); map.put(S3Constansts.CONTINUATIONTOKEN, result.getNextContinuationToken()); map.put(S3Constansts.ISTRUNCATED, BooleanUtils.toStringTrueFalse(result.isTruncated())); Response response = new Response(); response.getList().addAll(list); response.getMap().putAll(map); response.setSuccess(true); return response; }
From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java
@Override public void createFolder(String bucketName, String key) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(0L);// ww w . ja v a2 s .c o m if (!StringUtils.endsWith(key, S3Constansts.DELIMITER)) { key = key.concat(S3Constansts.DELIMITER); } this.s3.putObject(bucketName, key, new ByteArrayInputStream(new byte[0]), metadata); }
From source file:org.exoplatform.platform.common.software.register.UnlockService.java
/** * Check and update customize path/* w w w . ja va2 s . com*/ * @param lisensePath */ private void checkCustomizeFolder(String lisensePath) { File lisenseFile = new File(lisensePath); if (!StringUtils.endsWith(lisensePath, Utils.LICENSE_FILE)) { if (lisenseFile.exists() && lisenseFile.mkdirs()) { LOG.error("The customize lisense.xml path cannot be use, default value will be applied."); return; } if (lisenseFile.isFile()) { if (lisenseFile.canWrite()) { Utils.HOME_CONFIG_LOCATION = lisenseFile.getParent(); Utils.HOME_CONFIG_FILE_LOCATION = lisenseFile.getPath(); } } else { Utils.HOME_CONFIG_LOCATION = lisenseFile.getPath(); Utils.HOME_CONFIG_FILE_LOCATION = Utils.HOME_CONFIG_LOCATION + "/" + Utils.LICENSE_FILE; } } else { if ((lisenseFile.getParentFile().exists() && lisenseFile.canWrite()) || lisenseFile.getParentFile().mkdirs()) { Utils.HOME_CONFIG_LOCATION = lisenseFile.getParent(); Utils.HOME_CONFIG_FILE_LOCATION = lisenseFile.getPath(); } } }
From source file:org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerConfigurationDefaultFactoryTest.java
/** * Test method for {@link org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerConfigurationFactory#createConfiguration()}. * * @throws IOException/* www. j a va2 s . c om*/ * @throws URISyntaxException */ @Test public void testCreateConfiguration() throws IOException, URISyntaxException { LOGGER.trace("BEGIN {}::testCreateConfiguration", this.getClass().getName()); try { final Configuration templateConfiguration = FreeMarkerConfigurationFactory.createConfiguration(); assertThat(templateConfiguration, is(not(nullValue()))); // FreeMarker TemplateLoader Configuration final TemplateLoader templateLoader = templateConfiguration.getTemplateLoader(); assertThat(templateLoader, is(not(nullValue()))); assertThat(templateLoader, is(instanceOf(ClassTemplateLoader.class))); final String templateSource = ((ClassTemplateLoader) templateLoader).findTemplateSource("").toString(); assertThat(templateSource, is(not(nullValue()))); final Path templateSourcePath = Paths.get(new URI(templateSource)); final Path templateBasePath = Paths.get(FreeMarkerConfigurationFactory.TEMPLATE_BASE_PATH); assertThat(StringUtils.endsWith(templateSourcePath.toString(), templateBasePath.toString()), is(true)); // FreeMarker Default and Output Encoding Configuration assertThat(templateConfiguration.getDefaultEncoding(), is(StandardCharsets.UTF_8.name())); assertThat(templateConfiguration.getOutputEncoding(), is(templateConfiguration.getDefaultEncoding())); // FreeMarker TemplateExceptionHandler Configuration assertThat(templateConfiguration.getTemplateExceptionHandler(), is(TemplateExceptionHandler.RETHROW_HANDLER)); } finally { LOGGER.trace("END {}::testCreateConfiguration", this.getClass().getName()); } }