List of usage examples for org.apache.commons.lang3 StringUtils endsWith
public static boolean endsWith(final CharSequence str, final CharSequence suffix)
Check if a CharSequence ends with a specified suffix.
null s are handled without exceptions.
From source file:com.adeptj.modules.security.core.credential.UsernamePasswordCredential.java
public static UsernamePasswordCredential from(HttpServletRequest request) { String username = request.getParameter(PARAM_USERNAME); String password = request.getParameter(PARAM_PWD); if (METHOD_POST.equals(request.getMethod()) && StringUtils.endsWith(request.getRequestURI(), LOGIN_URI_SUFFIX) && StringUtils.isNoneEmpty(username, password)) { return new UsernamePasswordCredential(username, password.toCharArray()); }//from w ww . j ava 2 s . c o m return null; }
From source file:com.threewks.thundr.view.jsp.JspView.java
private String completeViewName(String view) { if (!StringUtils.startsWith(view, "/")) { view = "/WEB-INF/jsp/" + view; }/*from ww w .jav a 2 s. c o m*/ if (!StringUtils.endsWith(view, ".jsp")) { view = view + ".jsp"; } return view; }
From source file:ch.cyberduck.core.sftp.openssh.OpenSSHPrivateKeyConfigurator.java
public List<Local> list() { final List<Local> keys = new ArrayList<>(); try {/*ww w . j a v a 2 s . com*/ for (Local file : directory.list(new Filter<String>() { @Override public boolean accept(final String file) { return !StringUtils.endsWith(file, ".pub"); } @Override public Pattern toPattern() { return Pattern.compile(".*\\.pub"); } })) { final KeyFormat format; try { format = KeyProviderUtil.detectKeyFileFormat( new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")), true); } catch (AccessDeniedException | IOException e) { log.debug(String.format("Ignore file %s with unknown format. %s", file, e.getMessage())); continue; } switch (format) { case PKCS5: case PKCS8: case OpenSSH: case OpenSSHv1: case PuTTY: keys.add(file); break; } } } catch (AccessDeniedException e) { log.warn(String.format("Failure loading keys from directory %s", directory)); } return keys; }
From source file:com.kryptnostic.rhizome.configuration.amazon.AwsLaunchConfiguration.java
@JsonCreator public AwsLaunchConfiguration(@JsonProperty(BUCKET_FIELD) String bucket, @JsonProperty(FOLDER_FIELD) Optional<String> folder, @JsonProperty(REGION_FIELD) Optional<String> region) { Preconditions.checkArgument(StringUtils.isNotBlank(bucket), "S3 bucket for configuration must be specified."); this.bucket = bucket; String rawFolder = folder.or(DEFAULT_FOLDER); while (StringUtils.endsWith(rawFolder, "/")) { StringUtils.removeEnd(rawFolder, "/"); }// www . java2 s . c o m // We shouldn't prefix if (StringUtils.isNotBlank(rawFolder)) { this.folder = rawFolder + "/"; } else { this.folder = rawFolder; } this.region = region.isPresent() ? Optional.of(Regions.fromName(region.get())) : Optional.absent(); }
From source file:io.wcm.devops.conga.resource.ResourceLoaderFilesystemTest.java
@Test public void testResource() throws Exception { Resource resource = underTest.getResource(FILE_PREFIX + ROOT + "/folder1/file1.txt"); assertTrue(resource.exists());/*from w ww . j a va 2 s .c om*/ assertEquals("file1.txt", resource.getName()); assertEquals("txt", resource.getFileExtension()); assertEquals(ROOT + "/folder1/file1.txt", unifySlashes(resource.getPath())); assertTrue( "Canonical path " + unifySlashes(resource.getCanonicalPath()) + " does not end with /" + ROOT + "/folder1/file1.txt", StringUtils.endsWith(unifySlashes(resource.getCanonicalPath()), "/" + ROOT + "/folder1/file1.txt")); assertTrue(resource.getLastModified() > 0); try (InputStream is = resource.getInputStream()) { assertEquals("File 1", IOUtils.toString(is, CharEncoding.UTF_8)); } }
From source file:de.micromata.tpsb.doc.sources.JarSourceFileRepository.java
@Override public Collection<JavaSourceFileHolder> getSources() { List<JavaSourceFileHolder> fileContentList = new ArrayList<JavaSourceFileHolder>(); for (String jarFileName : getLocations()) { try {// w w w.j a va2s . com JarFile jarFile; jarFile = new JarFile(jarFileName); Enumeration<? extends ZipEntry> jarEntryEnum = jarFile.entries(); while (jarEntryEnum.hasMoreElements()) { JarEntry jarEntry = (JarEntry) jarEntryEnum.nextElement(); // nur Java-Dateien beachten if (jarEntry.isDirectory() || StringUtils.endsWith(jarEntry.getName(), ".java") == false) { continue; } String javaFilename = jarEntry.getName(); String javaFileContent = getContents(jarFile, jarEntry); if (StringUtils.isBlank(javaFileContent) == true) { continue; } JavaSourceFileHolder fileHolder = new JavaSourceFileHolder(javaFilename, javaFileContent); fileHolder.setSource(Source.Jar); fileHolder.setOrigin(jarFileName); fileContentList.add(fileHolder); } } catch (IOException e) { e.printStackTrace(); } } return fileContentList; }
From source file:com.glaf.core.startup.DBNativeCmdThread.java
public void run() { Map<String, Object> params = new HashMap<String, Object>(); java.util.Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = props.getProperty(key); params.put(key, value);// w w w. ja v a 2 s .c om } try { String path = SystemProperties.getConfigRootPath() + "/conf/bootstrap/scripts"; File dir = new File(path); File contents[] = dir.listFiles(); if (contents != null) { for (int i = 0; i < contents.length; i++) { if (contents[i].isFile() && StringUtils.endsWith(contents[i].getName(), ".sql")) { params.put("file", contents[i].getAbsolutePath()); String command = QueryUtils.replaceBlankParas(cmd, params); logger.debug("exec cmd:" + command); Runtime.getRuntime().exec(command); } } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } }
From source file:io.wcm.devops.conga.generator.plugins.fileheader.UnixShellScriptFileHeaderTest.java
@Test public void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.sh"); FileUtils.write(file, "#!/bin/bash\n" + "myscript"); List<String> lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); assertTrue(underTest.accepts(fileContext, context)); underTest.apply(fileContext, context); String content = FileUtils.readFileToString(file); assertTrue(StringUtils.contains(content, "# Der Jodelkaiser\n# aus dem Oetztal\n# ist wieder daheim.\n")); assertTrue(StringUtils.endsWith(content, "\nmyscript")); assertTrue(StringUtils.startsWith(content, "#!/bin/bash\n")); FileHeaderContext extractContext = underTest.extract(fileContext); assertEquals(lines, extractContext.getCommentLines()); file.delete();/*from ww w.j a v a2s . c o m*/ }
From source file:com.quancheng.saluki.plugin.Proto2Java.java
private File listAllProtoFile(File file) { if (file != null) { if (file.isDirectory()) { File[] fileArray = file.listFiles(); if (fileArray != null) { for (int i = 0; i < fileArray.length; i++) { listAllProtoFile(fileArray[i]); }//from w ww .ja v a 2 s . co m } } else { if (StringUtils.endsWith(file.getName(), "proto")) { allProtoFile.add(file); } } } return null; }
From source file:com.glaf.core.startup.DBUpdateThread.java
public void run() { logger.debug("->jdbc url:" + props.getProperty(DBConfiguration.JDBC_URL)); FileExecutionHelper helper = new FileExecutionHelper(); Connection conn = null;//from w w w . j a va 2s .c o m Statement stmt = null; try { conn = DBConnectionFactory.getConnection(props); if (conn != null) { helper.createTable(conn); String path = SystemProperties.getConfigRootPath() + "/conf/bootstrap/update"; File dir = new File(path); File contents[] = dir.listFiles(); if (contents != null) { for (int i = 0; i < contents.length; i++) { if (contents[i].isFile() && StringUtils.endsWith(contents[i].getName(), ".sql")) { try { if (!helper.exists(conn, "update_sql", contents[i])) { long lastModified = helper.lastModified(conn, "update_sql", contents[i]); if (contents[i].lastModified() > lastModified) { conn.setAutoCommit(false); String ddlStatements = FileUtils.readFile(contents[i].getAbsolutePath()); DBUtils.executeSchemaResourceIgnoreException(conn, ddlStatements); helper.save(conn, "update_sql", contents[i]); conn.commit(); } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } } } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } finally { JdbcUtils.close(stmt); JdbcUtils.close(conn); } }