Java Code Examples for org.apache.commons.io.FilenameUtils#getFullPathNoEndSeparator()
The following examples show how to use
org.apache.commons.io.FilenameUtils#getFullPathNoEndSeparator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PBXProject.java From thym with Eclipse Public License 1.0 | 6 votes |
private NSString searchPathForFile(PBXFile pbxfile) throws PBXProjectException { String filepath = FilenameUtils.getFullPathNoEndSeparator(pbxfile.getPath()); if(filepath.equals(".")){ filepath = ""; }else{ filepath = "/"+filepath; } NSDictionary group = getGroupByName("Plugins"); if(pbxfile.isPlugin() && group.containsKey("path")){ NSString groupPath = (NSString)group.objectForKey("path"); return NSObject.wrap("$(SRCROOT)/" + groupPath.getContent().replace('"', ' ').trim()); } else{ return NSObject.wrap("$(SRCROOT)/"+ getProductName() + filepath ); } }
Example 2
Source File: ImporterDialog.java From ghidra with Apache License 2.0 | 6 votes |
private boolean isFilenameTooLong() { int maxNameLen = tool.getProject().getProjectData().getMaxNameLength(); String fullPath = getName(); String currentPath = fullPath; while (!StringUtils.isBlank(currentPath)) { String filename = FilenameUtils.getName(currentPath); if (filename.isEmpty()) { return false; } if (filename.length() >= maxNameLen) { return true; } currentPath = FilenameUtils.getFullPathNoEndSeparator(currentPath); } return false; }
Example 3
Source File: BddResourceLoader.java From vividus with Apache License 2.0 | 6 votes |
@Override public Resource getResource(String rawResourcePath) { String parentDir = FilenameUtils.getFullPathNoEndSeparator(rawResourcePath); String fileName = FilenameUtils.getName(rawResourcePath); Resource[] resources = getResources(parentDir, fileName); if (resources.length > 1) { throw new ResourceLoadException("More than 1 resource is found for " + rawResourcePath); } if (resources.length == 0) { throw new ResourceLoadException("No resource is found for " + rawResourcePath); } return resources[0]; }
Example 4
Source File: TempDir.java From piper with Apache License 2.0 | 5 votes |
@Override public TypedValue execute (EvaluationContext aContext, Object aTarget, Object... aArguments) throws AccessException { String tmpDir = System.getProperty("java.io.tmpdir"); if(tmpDir.endsWith(File.separator)) { tmpDir = FilenameUtils.getFullPathNoEndSeparator(tmpDir); } return new TypedValue(tmpDir); }
Example 5
Source File: AgentConf.java From ankush with GNU Lesser General Public License v3.0 | 5 votes |
/** * Load the properties from the default file. * * @throws IOException * * @throws FileNotFoundException */ public void load() throws IOException { File file = new File(fileName); if (!file.exists()) { String confPath = FilenameUtils.getFullPathNoEndSeparator(fileName); FileUtils.forceMkdir(new File(confPath)); FileUtils.touch(file); } this.properties = load(fileName); }
Example 6
Source File: FileEL.java From datacollector with Apache License 2.0 | 5 votes |
@ElFunction( prefix = "file", name = "parentPath", description = "Returns parent path to given file or directory. Returns path without separator (e.g. result will not end with slash)." ) public static String parentPath ( @ElParam("filePath") String filePath ) { if(isEmpty(filePath)) { return null; } return FilenameUtils.getFullPathNoEndSeparator(filePath); }
Example 7
Source File: RollingLogsSource.java From logsniffer with GNU Lesser General Public License v3.0 | 5 votes |
protected Log[] getPastLogs(final String liveLog) throws IOException { final File dir = new File(FilenameUtils.getFullPathNoEndSeparator(liveLog)); final String pastPattern = FilenameUtils.getName(liveLog) + getPastLogsSuffixPattern(); final FileFilter fileFilter = new WildcardFileFilter(pastPattern); final File[] files = dir.listFiles(fileFilter); final FileLog[] logs = new FileLog[files.length]; Arrays.sort(files, getPastLogsType().getPastComparator()); int i = 0; for (final File file : files) { // TODO Decouple direct file log association logs[i++] = new FileLog(file); } logger.debug("Found {} past logs for {} with pattern {}", logs.length, liveLog, pastPattern); return logs; }
Example 8
Source File: MultipleFilesWatcher.java From pgptool with GNU General Public License v3.0 | 5 votes |
public void stopWatchingFile(String filePathName) { try { String baseFolderStr = FilenameUtils.getFullPathNoEndSeparator(filePathName); String relativeFilename = FilenameUtils.getName(filePathName); synchronized (watcherName) { BaseFolder baseFolder = baseFolders.get(baseFolderStr); if (baseFolder == null) { log.debug("No associated watchers found for " + baseFolderStr); return; } baseFolder.interestedFiles.remove(relativeFilename); log.debug("File is no longer watched in folder " + baseFolderStr + " file " + relativeFilename); if (baseFolder.interestedFiles.size() > 0) { return; } // NOTE: Decided to turn this off, because file might re-appear in case it's app // re-created it. See #91, #75 // keys.remove(baseFolder.key); // baseFolders.remove(baseFolder.folder); // baseFolder.key.cancel(); // log.debug("Folder watch key is canceled " + baseFolderStr); } } catch (Throwable t) { log.error("Failed to watch file " + filePathName, t); // not goinf to ruin app workflow } }
Example 9
Source File: MultipleFilesWatcher.java From pgptool with GNU General Public License v3.0 | 5 votes |
public void watchForFileChanges(String filePathName) { try { String baseFolderStr = FilenameUtils.getFullPathNoEndSeparator(filePathName); String relativeFilename = FilenameUtils.getName(filePathName); synchronized (watcherName) { BaseFolder baseFolder = baseFolders.get(baseFolderStr); if (baseFolder != null) { log.debug("Parent directory is already being watched " + baseFolderStr + ", will just add file to watch " + relativeFilename); baseFolder.interestedFiles.add(relativeFilename); return; } Path path = Paths.get(baseFolderStr); WatchKey key = path.register(watcher, ENTRY_DELETE, ENTRY_MODIFY, ENTRY_CREATE); baseFolder = new BaseFolder(baseFolderStr, key, path, relativeFilename); keys.put(key, baseFolder); baseFolders.put(baseFolderStr, baseFolder); log.debug("New watch key created for folder " + baseFolderStr + ", add first file " + relativeFilename); } } catch (Throwable t) { log.error("Failed to watch file " + filePathName, t); // not goinf to ruin app workflow } }
Example 10
Source File: ImportBatchTask.java From ghidra with Apache License 2.0 | 5 votes |
private Pair<DomainFolder, String> getDestinationInfo(BatchLoadConfig batchLoadConfig, DomainFolder rootDestinationFolder) { FSRL fsrl = batchLoadConfig.getFSRL(); String pathStr = fsrlToPath(fsrl, batchLoadConfig.getUasi().getFSRL(), stripLeadingPath, stripAllContainerPath); String preferredName = batchLoadConfig.getPreferredFileName(); String fsrlFilename = fsrl.getName(); if (!fsrlFilename.equals(preferredName)) { pathStr = FSUtilities.appendPath(pathStr, preferredName); } // REGEX doc: match any character in the set ('\\', ':', '|') and replace with '/' pathStr = pathStr.replaceAll("[\\\\:|]+", "/"); String parentDir = FilenameUtils.getFullPathNoEndSeparator(pathStr); if (parentDir == null) { parentDir = ""; } String destFilename = FilenameUtils.getName(pathStr); try { DomainFolder batchDestFolder = ProjectDataUtils.createDomainFolderPath(rootDestinationFolder, parentDir); return new Pair<>(batchDestFolder, destFilename); } catch (InvalidNameException | IOException e) { Msg.error(this, "Problem creating project folder root: " + rootDestinationFolder.getPathname() + ", subpath: " + parentDir, e); } return new Pair<>(rootDestinationFolder, fsrlFilename); }
Example 11
Source File: ImporterDialog.java From ghidra with Apache License 2.0 | 5 votes |
private boolean isDuplicateFilename() { String pathFilename = getName(); String parentPath = FilenameUtils.getFullPathNoEndSeparator(pathFilename); String filename = FilenameUtils.getName(pathFilename); DomainFolder localDestFolder = (parentPath != null) ? ProjectDataUtils.lookupDomainPath(destinationFolder, parentPath) : destinationFolder; if (localDestFolder != null) { if (localDestFolder.getFolder(filename) != null || localDestFolder.getFile(filename) != null) { return true; } } return false; }
Example 12
Source File: EncryptOnePm.java From pgptool with GNU General Public License v3.0 | 4 votes |
public SaveFileChooserDialog getTargetFileChooser() { if (targetFileChooser == null) { targetFileChooser = new SaveFileChooserDialog("action.chooseTargetFile", "action.choose", appProps, "EncryptionTargetChooser") { @Override protected String onDialogClosed(String filePathName, JFileChooser ofd) { String ret = super.onDialogClosed(filePathName, ofd); if (ret != null) { targetFile.setValueByOwner(ret); } return ret; } @Override protected void onFileChooserPostConstruct(JFileChooser ofd) { ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter(new FileNameExtensionFilter("GPG Files (.pgp)", "pgp")); // NOTE: Should we support other extensions?.... ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); } @Override protected void suggestTarget(JFileChooser ofd) { String sourceFileStr = sourceFile.getValue(); if (StringUtils.hasText(targetFile.getValue())) { use(ofd, targetFile.getValue()); } else if (encryptionDialogParameters != null && encryptionDialogParameters.getTargetFile() != null) { if (encryptionDialogParameters.getSourceFile().equals(sourceFile.getValue())) { use(ofd, encryptionDialogParameters.getTargetFile()); } else { use(ofd, madeUpTargetFileName(sourceFile.getValue(), FilenameUtils .getFullPathNoEndSeparator(encryptionDialogParameters.getTargetFile()))); } } else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) { String basePath = FilenameUtils.getFullPathNoEndSeparator(sourceFileStr); ofd.setCurrentDirectory(new File(basePath)); ofd.setSelectedFile(new File(madeUpTargetFileName(sourceFileStr, basePath))); } } private void use(JFileChooser ofd, String filePathName) { ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName))); ofd.setSelectedFile(new File(filePathName)); } }; } return targetFileChooser; }
Example 13
Source File: FilePath.java From piper with Apache License 2.0 | 4 votes |
@Override public Object handle (TaskExecution aTask) { return FilenameUtils.getFullPathNoEndSeparator(aTask.getRequiredString("filename")); }
Example 14
Source File: LocalDocReader.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public static File findDefaultPageXmlForImage(String imagePath) { String folder = FilenameUtils.getFullPathNoEndSeparator(imagePath); String basename = FilenameUtils.getBaseName(imagePath); return findXml(basename, new File(folder+File.separator+LocalDocConst.PAGE_FILE_SUB_FOLDER), false); }
Example 15
Source File: ProgramAnnotatedStringHandler.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean handleMouseClick(String[] annotationParts, Navigatable navigatable, ServiceProvider serviceProvider) { ProjectDataService projectDataService = serviceProvider.getService(ProjectDataService.class); ProjectData projectData = projectDataService.getProjectData(); // default folder is the root folder DomainFolder folder = projectData.getRootFolder(); // Get program name and folder from program comment annotation // handles forward and back slashes and with and without first slash String programText = getProgramText(annotationParts); String programName = FilenameUtils.getName(programText); String path = FilenameUtils.getFullPathNoEndSeparator(programText); if (path.length() > 0) { path = StringUtils.prependIfMissing(FilenameUtils.separatorsToUnix(path), "/"); folder = projectData.getFolder(path); } if (folder == null) { Msg.showInfo(getClass(), null, "No Folder: " + path, "Unable to locate folder by the name \"" + path); return true; } DomainFile programFile = findProgramByName(programName, folder); if (programFile == null) { Msg.showInfo(getClass(), null, "No Program: " + programName, "Unable to locate a program by the name \"" + programName + "\".\nNOTE: Program name is case-sensitive. "); return true; } SymbolPath symbolPath = getSymbolPath(annotationParts); navigate(programFile, symbolPath, navigatable, serviceProvider); return true; }
Example 16
Source File: LocalStorageManagerInterface.java From entando-core with GNU Lesser General Public License v3.0 | 4 votes |
public void addResource(JAXBStorageResource storageResource, Properties properties) throws Throwable { try { boolean isProtected = storageResource.isProtectedResource(); //validate parent directory; String path = StringUtils.removeEnd(storageResource.getName(), "/"); String parentFolder = FilenameUtils.getFullPathNoEndSeparator(path); if (StringUtils.isNotBlank(parentFolder)) parentFolder = URLDecoder.decode(parentFolder, "UTF-8"); if (!StorageManagerUtil.isValidDirName(parentFolder)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } BasicFileAttributeView parentBasicFileAttributeView = this.getStorageManager().getAttributes(parentFolder, isProtected); if (null == parentBasicFileAttributeView || !parentBasicFileAttributeView.isDirectory()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } //validate exists BasicFileAttributeView basicFileAttributeView2 = this.getStorageManager().getAttributes(path, isProtected); if (null != basicFileAttributeView2) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "File already present", Response.Status.CONFLICT); } String filename = StringUtils.substringAfter(storageResource.getName(), parentFolder); if (storageResource.isDirectory()) { if (!StorageManagerUtil.isValidDirName(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid dir name", Response.Status.CONFLICT); } this.getStorageManager().createDirectory(storageResource.getName(), isProtected); } else { //validate file content if (!storageResource.isDirectory() && (null == storageResource.getBase64() || storageResource.getBase64().length == 0 )) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "A file cannot be empty", Response.Status.CONFLICT); } if (!StorageManagerUtil.isValidFilename(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid filename name", Response.Status.CONFLICT); } this.getStorageManager().saveFile(storageResource.getName(), isProtected, new ByteArrayInputStream(storageResource.getBase64())); } } catch (ApiException ae) { throw ae; } catch (Throwable t) { logger.error("Error adding new storage resource", t); throw t; } }
Example 17
Source File: LocalStorageManagerInterface.java From entando-core with GNU Lesser General Public License v3.0 | 4 votes |
public void deleteResource(Properties properties) throws Throwable { String pathValue = properties.getProperty(PARAM_PATH); String protectedValue = properties.getProperty(PARAM_IS_PROTECTED); boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true"); try { if (StringUtils.isNotBlank(pathValue)) pathValue = URLDecoder.decode(pathValue, "UTF-8"); String path = StringUtils.removeEnd(pathValue, "/"); String parentFolder = FilenameUtils.getFullPathNoEndSeparator(path); BasicFileAttributeView parentBasicFileAttributeView = this.getStorageManager().getAttributes(parentFolder, isProtected); if (null == parentBasicFileAttributeView || !parentBasicFileAttributeView.isDirectory()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } if (!StorageManagerUtil.isValidDirName(parentFolder)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } BasicFileAttributeView basicFileAttributeView = this.getStorageManager().getAttributes(pathValue, isProtected); if (null == basicFileAttributeView) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The file does not exists", Response.Status.CONFLICT); } String filename = StringUtils.substringAfter(pathValue, parentFolder); if (basicFileAttributeView.isDirectory()) { if (!StorageManagerUtil.isValidDirName(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid dir name", Response.Status.CONFLICT); } String recursiveDelete = properties.getProperty(PARAM_DELETE_RECURSIVE); boolean isRecursiveDelete = StringUtils.equalsIgnoreCase(recursiveDelete, "true"); if (!isRecursiveDelete) { String[] dirContents = this.getStorageManager().list(pathValue, isProtected); if (null != dirContents && dirContents.length > 0) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The directory is not empty", Response.Status.CONFLICT); } } this.getStorageManager().deleteDirectory(pathValue, isProtected); } else { //it's a file if (!StorageManagerUtil.isValidFilename(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid filename", Response.Status.CONFLICT); } this.getStorageManager().deleteFile(pathValue, isProtected); } } catch (ApiException ae) { throw ae; } catch (Throwable t) { logger.error("Error adding new storage resource", t); throw t; } }
Example 18
Source File: BPELAnsibleOperationPluginHandler.java From container with Apache License 2.0 | 4 votes |
private Variable appendBPELAssignOperationShScript(final BPELPlanContext templateContext, final AbstractOperation operation, final AbstractArtifactReference reference, final AbstractImplementationArtifact ia) { final String runShScriptStringVarName = "runShFile" + templateContext.getIdForNames(); // install ansible String runShScriptString = "sudo apt-add-repository -y ppa:ansible/ansible && sudo apt-get update && sudo apt-get install -y ansible"; // install unzip runShScriptString += " && sudo apt-get install unzip"; final String ansibleZipPath = templateContext.getCSARFileName() + "/" + reference.getReference(); final String ansibleZipFileName = FilenameUtils.getName(ansibleZipPath); final String ansibleZipFolderName = FilenameUtils.getBaseName(ansibleZipFileName); final String ansibleZipParentPath = FilenameUtils.getFullPathNoEndSeparator(ansibleZipPath); // go into directory of the ansible zip runShScriptString += " && cd " + ansibleZipParentPath; // unzip runShScriptString += " && unzip " + ansibleZipFileName; final String playbookPath = getAnsiblePlaybookFilePath(templateContext); if (playbookPath == null) { LOG.error("No specified Playbook found in the corresponding ArtifactTemplate!"); } else { LOG.debug("Found Playbook: {}", playbookPath); final String completePlaybookPath = ansibleZipFolderName + "/" + FilenameUtils.separatorsToUnix(playbookPath); final String playbookFolder = FilenameUtils.getFullPathNoEndSeparator(completePlaybookPath); final String playbookFile = FilenameUtils.getName(completePlaybookPath); // go into the unzipped directory runShScriptString += " && cd " + playbookFolder; // execute ansible playbook runShScriptString += " && ansible-playbook " + playbookFile; } final Variable runShScriptStringVar = templateContext.createGlobalStringVariable(runShScriptStringVarName, runShScriptString); return runShScriptStringVar; }
Example 19
Source File: ClassJar.java From ghidra with Apache License 2.0 | 4 votes |
private static boolean isPatchJar(String pathName) { String jarDirectory = FilenameUtils.getFullPathNoEndSeparator(pathName); return jarDirectory.equalsIgnoreCase(PATCH_DIR_PATH_FORWARD_SLASHED); }
Example 20
Source File: AbstractLibrarySupportLoader.java From ghidra with Apache License 2.0 | 3 votes |
/** * Returns the path the loaded {@link ByteProvider} is located in. * <p> * Special case when the ByteProvider specifies a {@link FSRL}, try to get the 'real' * path on the local filesystem, otherwise return null. * * @param provider The {@link ByteProvider}. * @return The path the loaded {@link ByteProvider} is located in. */ private String getProviderFilePath(ByteProvider provider) { FSRL fsrl = provider.getFSRL(); if ((fsrl != null) && !fsrl.getFS().hasContainer()) { return FilenameUtils.getFullPathNoEndSeparator(fsrl.getPath()); } File f = provider.getFile(); return (f != null) ? f.getParent() : null; }