Example usage for org.apache.commons.io FilenameUtils separatorsToSystem

List of usage examples for org.apache.commons.io FilenameUtils separatorsToSystem

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils separatorsToSystem.

Prototype

public static String separatorsToSystem(String path) 

Source Link

Document

Converts all separators to the system separator.

Usage

From source file:org.nuxeo.ecm.platform.publisher.test.TestFSPublishing.java

@Test
public void testFSPublishing() throws Exception {
    createInitialDocs();//w  w  w .  j  a  v  a  2s  . com
    createFSDirs();

    registerFSTree("TestingFSTree");

    PublicationTree tree = service.getPublicationTree("TestingFSTree", session, null);

    // check browsing
    List<PublicationNode> sectionsNodes = tree.getChildrenNodes();
    assertNotNull(sectionsNodes);
    assertEquals(3, sectionsNodes.size());

    PublicationNode section2 = sectionsNodes.get(1);
    assertEquals("section2", section2.getName());
    assertEquals(FilenameUtils.separatorsToSystem(rootFolder + "/section2"),
            FilenameUtils.separatorsToSystem(section2.getPath()));

    List<PublicationNode> subSectionsNodes = section2.getChildrenNodes();
    assertNotNull(subSectionsNodes);
    assertEquals(2, subSectionsNodes.size());

    PublicationNode section22 = subSectionsNodes.get(1);
    assertEquals("section22", section22.getName());
    assertEquals(FilenameUtils.separatorsToSystem(rootFolder + "/section2/section22"),
            FilenameUtils.separatorsToSystem(section22.getPath()));

    // check treeconfigName propagation
    assertEquals(tree.getConfigName(), tree.getTreeConfigName());
    assertEquals(tree.getConfigName(), section22.getTreeConfigName());
    assertEquals(tree.getSessionId(), section22.getSessionId());

    // test publish
    PublishedDocument pubDoc = tree.publish(doc2Publish, section22);
    assertNotNull(pubDoc);
    File container = new File(section22.getPath());
    File[] files = container.listFiles();
    assertEquals(1, files.length);

    assertEquals(doc2Publish.getRepositoryName(), pubDoc.getSourceRepositoryName());
    assertEquals(doc2Publish.getRef(), pubDoc.getSourceDocumentRef());

    List<PublishedDocument> foundDocs = tree.getExistingPublishedDocument(doc2publishLocation);
    assertNotNull(foundDocs);
    assertEquals(1, foundDocs.size());

    foundDocs = section22.getChildrenDocuments();
    assertNotNull(foundDocs);
    assertEquals(1, foundDocs.size());

    tree.publish(doc2Publish, section2);
    foundDocs = tree.getExistingPublishedDocument(doc2publishLocation);
    assertNotNull(foundDocs);
    assertEquals(2, foundDocs.size());

    tree.unpublish(doc2Publish, section22);
    foundDocs = tree.getExistingPublishedDocument(doc2publishLocation);
    assertNotNull(foundDocs);
    assertEquals(1, foundDocs.size());

    tree.unpublish(doc2Publish, section2);
    foundDocs = tree.getExistingPublishedDocument(doc2publishLocation);
    assertNotNull(foundDocs);
    assertEquals(0, foundDocs.size());

    PublishedDocument pubDoc3 = tree.publish(doc2Publish, section2);
    foundDocs = tree.getExistingPublishedDocument(doc2publishLocation);
    assertNotNull(foundDocs);
    assertEquals(1, foundDocs.size());

    tree.unpublish(pubDoc3);
    foundDocs = tree.getExistingPublishedDocument(doc2publishLocation);
    assertNotNull(foundDocs);
    assertEquals(0, foundDocs.size());
}

From source file:org.opendaylight.controller.netconf.ssh.osgi.NetconfSSHActivator.java

private SshProxyServer startSSHServer(final BundleContext bundleContext) throws IOException {
    final Optional<InetSocketAddress> maybeSshSocketAddress = NetconfConfigUtil
            .extractNetconfServerAddress(bundleContext, InfixProp.ssh);

    if (maybeSshSocketAddress.isPresent() == false) {
        LOG.trace("SSH bridge not configured");
        return null;
    }/*from w  w w.j  av a  2  s.c o  m*/

    final InetSocketAddress sshSocketAddress = maybeSshSocketAddress.get();
    LOG.trace("Starting netconf SSH bridge at {}", sshSocketAddress);

    final LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();

    authProviderTracker = new AuthProviderTracker(bundleContext);

    final String path = FilenameUtils.separatorsToSystem(NetconfConfigUtil.getPrivateKeyPath(bundleContext));
    checkState(!Strings.isNullOrEmpty(path), "Path to ssh private key is blank. Reconfigure %s",
            NetconfConfigUtil.getPrivateKeyKey());

    final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerExecutor, clientGroup, nioExecutor);
    sshProxyServer.bind(new SshProxyServerConfigurationBuilder().setBindingAddress(sshSocketAddress)
            .setLocalAddress(localAddress).setAuthenticator(authProviderTracker)
            .setKeyPairProvider(new PEMGeneratorHostKeyProvider(path, ALGORITHM, KEY_SIZE))
            .setIdleTimeout(DEFAULT_IDLE_TIMEOUT).createSshProxyServerConfiguration());
    return sshProxyServer;
}

From source file:org.openscore.lang.tools.verifier.VerifierMain.java

public static void main(String[] args) {
    String repositoryPath = args[0];
    Validate.notNull(repositoryPath, "You must pass a path to your repository");
    repositoryPath = FilenameUtils.separatorsToSystem(repositoryPath);
    Validate.isTrue(new File(repositoryPath).isDirectory(),
            "Directory path argument \'" + repositoryPath + "\' does not lead to a directory");

    ApplicationContext context = new AnnotationConfigApplicationContext(VerifierSpringConfiguration.class);
    SlangContentVerifier slangContentVerifier = context.getBean(SlangContentVerifier.class);
    try {//from w  w w  .j a  v  a 2s  .co m
        int numberOfValidSlangFiles = slangContentVerifier.verifyAllSlangFilesInDirAreValid(repositoryPath);
        System.out.println("SUCCESS: Found " + numberOfValidSlangFiles + " slang files under directory: \""
                + repositoryPath + "\" and all are valid.");
        System.exit(0);
    } catch (Exception e) {
        System.out.println(e.getMessage() + "\n\nFAILURE: Validation of slang files under directory: \""
                + repositoryPath + "\" failed.");
        // TODO - do we want to throw exception or exit with 1?
        System.exit(1);
    }
}

From source file:org.pentaho.metaverse.impl.VfsLineageCollectorTest.java

@Before
public void setUp() throws Exception {
    collector = new VfsLineageCollector();
    String basePath = new File(".").getCanonicalPath();
    collector.setOutputFolder(FilenameUtils
            .separatorsToSystem("file://" + basePath + "/src/test/resources/pentaho-lineage-output"));
}

From source file:org.pentaho.metaverse.impl.VfsLineageWriterTest.java

@Before
public void setUp() throws Exception {
    String basePath = new File(".").getCanonicalPath();

    writer = new VfsLineageWriter();
    writer = spy(writer);/*  w  w w .ja va2s .c o m*/

    holder = new LineageHolder();
    IExecutionProfile profile = new ExecutionProfile();
    profile.setName("test");
    IExecutionData data = new ExecutionData();
    data.setStartTime(now);
    profile.setExecutionData(data);

    holder.setExecutionProfile(profile);

    BAD_OUTPUT_FOLDER = FilenameUtils
            .separatorsToSystem("file://" + basePath + BAD_OUTPUT_FOLDER_DEFAULT + random.nextInt());
    GOOD_OUTPUT_FOLDER = FilenameUtils
            .separatorsToSystem("file://" + basePath + GOOD_OUTPUT_FOLDER_DEFAULT + random.nextInt());

    writer.setOutputFolder(GOOD_OUTPUT_FOLDER);
}

From source file:org.pepstock.jem.node.security.SecurityUtils.java

/**
 * Extract the right file name, used inside the permissions
 * @param fileName complete path/*from  w w w . j a  va  2 s.c  o m*/
 * @return relative file name
 */
public String normalizeFileName(String fileName) {
    // gets data path
    String dataPath = DataPathsContainer.getInstance().getAbsoluteDataPath(fileName);
    // if not a data path, return file name as is
    if (dataPath != null) {
        // extract the filename, without the path of DATA path
        // because the permission are based on the file name
        // without the mount point of data path
        String file = StringUtils.substringAfter(fileName, dataPath);
        if (FilenameUtils.separatorsToSystem(file).startsWith(File.separator)) {
            return file.substring(1);
        } else {
            return file;
        }
    }
    return fileName;
}

From source file:org.sakaiproject.lessonbuildertool.cc.ZipLoader.java

private void unzip() throws FileNotFoundException, IOException {
    if (!unzipped) {
        BufferedOutputStream dest = null;
        InputStream fis = null;/*from   ww w .  j a  va2  s .  com*/
        ZipInputStream zis = null;
        try {
            if (cc_inputStream != null)
                fis = cc_inputStream;
            else
                fis = new FileInputStream(cc);
            log.debug("unzip fis " + fis);
            zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                log.debug("zip name " + entry.getName());
                //Fix the path to be correct for the system extracting it to
                String fileName = FilenameUtils.separatorsToSystem(entry.getName());
                File target = new File(root, fileName);
                // not sure if you can put things like .. into a zip file, but be careful
                if (!target.getCanonicalPath().startsWith(rootPath))
                    throw new FileNotFoundException(target.getCanonicalPath());
                if (entry.isDirectory()) {
                    if (!target.mkdirs())
                        throw new IOException("Unable to make temporary directory");
                } else {
                    if (target.getParentFile().exists() == false) {
                        target.getParentFile().mkdirs();
                    }
                    int count;
                    byte data[] = new byte[BUFFER];
                    FileOutputStream fos = new FileOutputStream(target);
                    dest = new BufferedOutputStream(fos, BUFFER);
                    while ((count = zis.read(data, 0, BUFFER)) != -1) {
                        dest.write(data, 0, count);
                    }
                    dest.flush();
                    dest.close();
                    dest = null;
                    log.debug("wrote file " + target);
                }
            }
        } catch (Exception x) {
            log.warn("exception " + x);
        } finally {
            if (zis != null) {
                try {
                    zis.close();
                } catch (Exception ignore) {
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (Exception ignore) {
                }
            }
            if (dest != null) {
                try {
                    dest.close();
                } catch (Exception ignore) {
                }
            }
        }
        unzipped = true;
    }
}

From source file:org.schemaspy.view.DotNode.java

private String getFileSystemPath(String fileName) {
    URL keyPath = getClass().getResource(fileName);
    String filepath = FilenameUtils.separatorsToSystem(keyPath.getPath());
    filepath = new File(filepath).getAbsoluteFile().toString();
    return filepath;
}

From source file:org.sejda.conversion.XmlFileSourceListParserTest.java

@Test
public void parseFileNames() {
    List<String> result = victim.parseFileNames(xmlFile);
    assertThat(result, hasItem("/tmp/pdf/inputFile.pdf"));
    assertThat(result, hasItem("/tmp/pdf/inputFile2.pdf:test"));
    assertThat(result,// ww w . j a va 2  s.c  o m
            org.hamcrest.core.CombinableMatcher.<Iterable<? super String>>either(hasItem("/tmp/inputFile1.pdf"))
                    .or(hasItem("C:\\tmp\\inputFile1.pdf")));
    assertThat(result, CombinableMatcher.<Iterable<? super String>>either(hasItem("/tmp/inputFile2.pdf"))
            .or(hasItem("C:\\tmp\\inputFile2.pdf")));
    assertThat(result, hasItem(FilenameUtils.separatorsToSystem("/tmp/subdir/inputFile1.pdf")));
    assertThat(result, hasItem(FilenameUtils.separatorsToSystem("/tmp/subdir3/inputFile2.pdf"))); // its defined in absolute path mode in the file
    assertThat(result, hasItem(FilenameUtils.separatorsToSystem("/tmp/subdir2/inputFile1.pdf")));
    assertThat(result, hasItem(FilenameUtils.separatorsToSystem("/tmp/subdir2/inputFile2.pdf:secret2")));
    assertThat(result, hasItem(FilenameUtils.separatorsToSystem("/tmp/subdir2/inputFile3.pdf")));
}

From source file:org.silverpeas.core.importexport.attachment.AttachmentDetail.java

private boolean isPhysicalPathAbsolute() {
    String filePath = FilenameUtils.separatorsToSystem(physicalName);
    File file = new File(filePath);
    return file.exists() && file.isFile();
}