List of usage examples for org.apache.commons.io FilenameUtils getFullPath
public static String getFullPath(String filename)
From source file:com.joyent.manta.client.MantaClient.java
/** * Moves a file from one path to another path. When moving * files between different directories, this operation is * not transactional and may fail or produce inconsistent result if * the source or the destination is modified while the operation is * in progress.//from w ww . ja va 2s . c o m * * @param source Original path to move from * @param destination Destination path to move to * @param recursivelyCreateDestinationDirectories when true create the full destination directory path * * @throws IOException thrown when something goes wrong */ private void moveFile(final String source, final String destination, final boolean recursivelyCreateDestinationDirectories) throws IOException { final String formattedDestination = formatPath(destination); final String destinationDir = FilenameUtils.getFullPath(formattedDestination); if (recursivelyCreateDestinationDirectories && !existsAndIsAccessible(destinationDir)) { putDirectory(destinationDir, true); } putSnapLink(destination, source, null); delete(source); }
From source file:net.vershinin.flashmind.FlashExportWizard.java
@Override protected void doExport(IProgressMonitor monitor, Display display, Shell parentShell) throws InvocationTargetException, InterruptedException { IMindMap mindMap = getSourceMindMap(); String targetPath = getTargetPath(); path = FilenameUtils.getFullPath(targetPath); baseName = FilenameUtils.getBaseName(targetPath); resourcesDirectory = baseName + RESOURCES_POSTFIX; resourcesPath = FilenameUtils.concat(path, resourcesDirectory); htmlFilename = FilenameUtils.getName(targetPath); mindmapFilename = FilenameUtils.getBaseName(htmlFilename) + MINDMAP_EXT; File path = new File(resourcesPath); path.mkdirs();// w ww . ja v a 2 s . c o m saveHtml(mindMap); saveJavaScrpit(); saveSwf(); saveFreemind(monitor, display, parentShell, mindMap); }
From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileLocationProvider.java
/** * @see ArchiveFileLocationProvider#getChildPathRelativeToParent(java.io.File, java.lang.String) *//*from w w w.ja v a 2 s . c om*/ @Override public String getChildPathRelativeToParent(File parentNodeFile, File childNodeFile) { if (parentNodeFile.equals(childNodeFile)) { throw new IllegalStateException("Parent and child files should be different"); } String parentDirectory = FilenameUtils.getFullPath(parentNodeFile.getAbsolutePath()); Path parentDirPath = Paths.get(parentDirectory); Path childFilePath = Paths.get(childNodeFile.getAbsolutePath()); Path relativePath = parentDirPath.relativize(childFilePath); return relativePath.toString(); }
From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileLocationProviderTest.java
@Test public void getAvailableFile() throws IOException { final String parentPath = "/archive/root/TopNode/Corpusstructure/normalnode.cmdi"; final String parentCorpusNamePathToClosestTopNode = "TopNode/NormalNode"; final String parentDirname = FilenameUtils.getFullPath(parentPath); final String filenameAttempt = "resource.pdf"; final String baseDirectoryForFileType = "/archive/root/TopNode/NormalNode/Annotations"; final File baseDirectoryForFileTypeFile = new File(baseDirectoryForFileType); final String filePathAttempt = parentDirname + File.separator + filenameAttempt; context.checking(new Expectations() { {/*from w w w . j av a 2 s . com*/ oneOf(mockArchiveFileHelper).correctPathElement(FilenameUtils.getName(filenameAttempt), "getAvailableFile"); will(returnValue(filenameAttempt)); oneOf(mockArchiveFileHelper).getDirectoryForNode(parentPath, parentCorpusNamePathToClosestTopNode, mockNode); will(returnValue(baseDirectoryForFileType)); oneOf(mockArchiveFileHelper).getFinalFile(baseDirectoryForFileTypeFile, filenameAttempt); will(returnValue(mockFile)); oneOf(mockArchiveFileHelper).createFileAndDirectories(mockFile); } }); File retrievedFile = archiveFileLocationProvider.getAvailableFile(parentPath, parentCorpusNamePathToClosestTopNode, mockNode, filenameAttempt); assertEquals("Retrieved file different from expected", mockFile, retrievedFile); }
From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileLocationProviderTest.java
@Test public void getAvailableFile_ThrowsException() throws IOException { final String parentPath = "/archive/root/TopNode/Corpusstructure/normalnode.cmdi"; final String parentCorpusNamePathToClosestTopNode = "TopNode/NormalNode"; final String parentDirname = FilenameUtils.getFullPath(parentPath); final String filenameAttempt = "resource.pdf"; final String baseDirectoryForFileType = "/archive/root/TopNode/NormalNode/Annotations"; final File baseDirectoryForFileTypeFile = new File(baseDirectoryForFileType); final String filePathAttempt = parentDirname + File.separator + filenameAttempt; final Exception ioException = new IOException("some error message"); context.checking(new Expectations() { {//from w ww. jav a 2 s. c om oneOf(mockArchiveFileHelper).correctPathElement(FilenameUtils.getName(filenameAttempt), "getAvailableFile"); will(returnValue(filenameAttempt)); oneOf(mockArchiveFileHelper).getDirectoryForNode(parentPath, parentCorpusNamePathToClosestTopNode, mockNode); will(returnValue(baseDirectoryForFileType)); oneOf(mockArchiveFileHelper).getFinalFile(baseDirectoryForFileTypeFile, filenameAttempt); will(returnValue(mockFile)); oneOf(mockArchiveFileHelper).createFileAndDirectories(mockFile); will(throwException(ioException)); } }); try { archiveFileLocationProvider.getAvailableFile(parentPath, parentCorpusNamePathToClosestTopNode, mockNode, filenameAttempt); fail("An exception should have been thrown"); } catch (IOException ex) { assertNotNull(ex); assertEquals("Exception different from expected", ioException, ex); } }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridge.java
/** * @see CorpusStructureBridge#getCorpusNamePathToClosestTopNode(nl.mpi.lamus.workspace.model.WorkspaceNode) *///from www.j av a 2 s. c o m @Override public String getCorpusNamePathToClosestTopNode(WorkspaceNode node) { StringBuilder pathSoFar = new StringBuilder(); boolean foundTopNode = false; URI currentNodeURI = node.getArchiveURI(); logger.trace("Node archive uri: " + currentNodeURI.toString()); CorpusNode currentCorpusNode = corpusStructureProvider.getNode(currentNodeURI); if (currentCorpusNode == null) { String errorMessage = "Node not found in archive database for URI " + currentNodeURI; logger.error(errorMessage); return null; } File currentLocalFile = nodeResolver.getLocalFile(currentCorpusNode); String currentLocalPath = currentLocalFile.getAbsolutePath(); logger.trace("Node local path: " + currentLocalPath); boolean currentPathContainsCorpusstructureDir = currentLocalPath .contains(File.separator + corpusstructureDirectoryName + File.separator); boolean currentPathContainsMetadataDir = currentLocalPath .contains(File.separator + metadataDirectoryName + File.separator); String nextNodeNameToInsert = ""; while (!foundTopNode) { URI parentNodeURI = corpusStructureProvider.getCanonicalParent(currentNodeURI); if (parentNodeURI == null) { String errorMessage = "Could not retrieve canonical parent for node " + currentNodeURI; logger.error(errorMessage); return null; } CorpusNode parentCorpusNode = corpusStructureProvider.getNode(parentNodeURI); if (parentCorpusNode == null) { String errorMessage = "Node not found in archive database for URI " + parentNodeURI; logger.error(errorMessage); return null; } File parentLocalFile = nodeResolver.getLocalFile(parentCorpusNode); String parentLocalPath = parentLocalFile.getAbsolutePath(); boolean parentPathContainsCorpusstructureDir = parentLocalPath .contains(File.separator + corpusstructureDirectoryName + File.separator); boolean parentPathContainsMetadataDir = parentLocalPath .contains(File.separator + metadataDirectoryName + File.separator); logger.trace("Parent local path: " + parentLocalPath); if (currentPathContainsCorpusstructureDir) { String currentDirectory = FilenameUtils.getFullPath(currentLocalPath); String parentDirectory = FilenameUtils.getFullPath(parentLocalPath); logger.trace("Parent directory: " + parentDirectory + " Current directory: " + currentDirectory); if (!currentDirectory.equals(parentDirectory)) { foundTopNode = true; //for the top node, the path name (instead of the node name) should be used, since top node folders were probably created by corpus managers if (!nextNodeNameToInsert.isEmpty()) { insertStringInTheBeginning(pathSoFar, archiveFileLocationProvider.getFolderNameBeforeCorpusstructure(currentDirectory)); } } else { if (!nextNodeNameToInsert.isEmpty()) { insertStringInTheBeginning(pathSoFar, nextNodeNameToInsert); } nextNodeNameToInsert = archiveFileHelper.correctPathElement(parentCorpusNode.getName(), "getCorpusNamePathToClosestTopNode"); } } else if (currentPathContainsMetadataDir && parentPathContainsCorpusstructureDir) { if (!nextNodeNameToInsert.isEmpty()) { insertStringInTheBeginning(pathSoFar, nextNodeNameToInsert); } nextNodeNameToInsert = archiveFileHelper.correctPathElement(parentCorpusNode.getName(), "getCorpusNamePathToClosestTopNode"); } currentNodeURI = parentNodeURI; currentCorpusNode = parentCorpusNode; currentLocalFile = parentLocalFile; currentLocalPath = parentLocalPath; currentPathContainsCorpusstructureDir = parentPathContainsCorpusstructureDir; currentPathContainsMetadataDir = parentPathContainsMetadataDir; } return pathSoFar.toString(); }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_TopNodeChild() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/TopNode/Corpusstructure/othernode.cmdi"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/TopNode/Corpusstructure/topnode.cmdi"; final File parentLocalFile = new File(parentLocalPath); final String parentNodeName = "TopNode"; final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String expectedPath = "TopNode"; context.checking(new Expectations() { {/*from w w w. j a va 2s .c o m*/ allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockParentCorpusNode).getName(); will(returnValue(parentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(parentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(parentNodeName)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); oneOf(mockArchiveFileLocationProvider) .getFolderNameBeforeCorpusstructure(FilenameUtils.getFullPath(localFile.getAbsolutePath())); will(returnValue(expectedPath)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_TopNodeChild_TopNodeFolderNotTheSameAsNodeName() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/topenode/Corpusstructure/othernode.cmdi"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/topenode/Corpusstructure/topnode.cmdi"; final File parentLocalFile = new File(parentLocalPath); final String parentNodeName = "TopNode"; final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String expectedPath = "topenode"; context.checking(new Expectations() { {/*from w w w .j a va 2 s . c o m*/ allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockParentCorpusNode).getName(); will(returnValue(parentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(parentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(parentNodeName)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockArchiveFileLocationProvider) .getFolderNameBeforeCorpusstructure(FilenameUtils.getFullPath(localFile.getAbsolutePath())); will(returnValue(expectedPath)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_OtherDescendant() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/TopNode/Corpusstructure/someothernode.cmdi"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/TopNode/Corpusstructure/othernode.cmdi"; final File parentLocalFile = new File(parentLocalPath); final String parentNodeName = "OtherNode"; final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/TopNode/Corpusstructure/topnode.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String grandParentNodeName = "TopNode"; final URI greatGrandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String greatGrandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File greatGrandParentLocalFile = new File(greatGrandParentLocalPath); final String expectedPath = "TopNode/OtherNode"; context.checking(new Expectations() { {//from www. ja v a 2 s .c o m allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockGrandParentCorpusNode).getNodeURI(); will(returnValue(grandParentArchiveURI)); allowing(mockParentCorpusNode).getName(); will(returnValue(parentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(parentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(parentNodeName)); allowing(mockGrandParentCorpusNode).getName(); will(returnValue(grandParentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(grandParentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(grandParentNodeName)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockArchiveFileLocationProvider) .getFolderNameBeforeCorpusstructure(FilenameUtils.getFullPath(localFile.getAbsolutePath())); will(returnValue(grandParentNodeName)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(grandParentArchiveURI); will(returnValue(greatGrandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(greatGrandParentArchiveURI); will(returnValue(mockGreatGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGreatGrandParentCorpusNode); will(returnValue(greatGrandParentLocalFile)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_OtherDescendant_SpecialCharacters() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/TopNode/Corpusstructure/someothernode.cmdi"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/TopNode/Corpusstructure/outrono.cmdi"; final File parentLocalFile = new File(parentLocalPath); final String parentNodeName = "OutroN"; final String parentNodeName_corrected = "OutroN_"; final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/TopNode/Corpusstructure/topnode.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String grandParentNodeName = "TopNode"; final URI greatGrandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String greatGrandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File greatGrandParentLocalFile = new File(greatGrandParentLocalPath); final String expectedPath = "TopNode/OutroN_"; context.checking(new Expectations() { {// w ww . j av a2 s . c om allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockGrandParentCorpusNode).getNodeURI(); will(returnValue(grandParentArchiveURI)); allowing(mockParentCorpusNode).getName(); will(returnValue(parentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(parentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(parentNodeName_corrected)); allowing(mockGrandParentCorpusNode).getName(); will(returnValue(grandParentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(grandParentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(grandParentNodeName)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockArchiveFileLocationProvider) .getFolderNameBeforeCorpusstructure(FilenameUtils.getFullPath(localFile.getAbsolutePath())); will(returnValue(grandParentNodeName)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(grandParentArchiveURI); will(returnValue(greatGrandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(greatGrandParentArchiveURI); will(returnValue(mockGreatGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGreatGrandParentCorpusNode); will(returnValue(greatGrandParentLocalFile)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }