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

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

Introduction

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

Prototype

public static String getFullPath(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path.

Usage

From source file:com.artofsolving.jodconverter.cli.ConvertDocument.java

public static void main(String[] arguments) throws Exception {
    CommandLineParser commandLineParser = new PosixParser();
    CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments);

    int port = SocketOpenOfficeConnection.DEFAULT_PORT;
    if (commandLine.hasOption(OPTION_PORT.getOpt())) {
        port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt()));
    }//from  ww w  . ja  va  2s.c o  m

    String outputFormat = null;
    if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) {
        outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt());
    }

    boolean verbose = false;
    if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) {
        verbose = true;
    }

    DocumentFormatRegistry registry;
    if (commandLine.hasOption(OPTION_XML_REGISTRY.getOpt())) {
        File registryFile = new File(commandLine.getOptionValue(OPTION_XML_REGISTRY.getOpt()));
        if (!registryFile.isFile()) {
            System.err.println("ERROR: specified XML registry file not found: " + registryFile);
            System.exit(EXIT_CODE_XML_REGISTRY_NOT_FOUND);
        }
        registry = new XmlDocumentFormatRegistry(new FileInputStream(registryFile));
        if (verbose) {
            System.out.println("-- loaded document format registry from " + registryFile);
        }
    } else {
        registry = new DefaultDocumentFormatRegistry();
    }

    String[] fileNames = commandLine.getArgs();
    if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) {
        String syntax = "convert [options] input-file output-file; or\n"
                + "[options] -f output-format input-file [input-file...]";
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(syntax, OPTIONS);
        System.exit(EXIT_CODE_TOO_FEW_ARGS);
    }

    OpenOfficeConnection connection = new SocketOpenOfficeConnection(port);
    try {
        if (verbose) {
            System.out.println("-- connecting to OpenOffice.org on port " + port);
        }
        connection.connect();
    } catch (ConnectException officeNotRunning) {
        System.err.println(
                "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
                        + port + ".");
        System.exit(EXIT_CODE_CONNECTION_FAILED);
    }
    try {
        DocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry);
        if (outputFormat == null) {
            File inputFile = new File(fileNames[0]);
            File outputFile = new File(fileNames[1]);
            convertOne(converter, inputFile, outputFile, verbose);
        } else {
            for (int i = 0; i < fileNames.length; i++) {
                File inputFile = new File(fileNames[i]);
                File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                        + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                convertOne(converter, inputFile, outputFile, verbose);
            }
        }
    } finally {
        if (verbose) {
            System.out.println("-- disconnecting");
        }
        connection.disconnect();
    }
}

From source file:DokeosConverter.java

public static void main(String[] arguments) throws Exception {
    CommandLineParser commandLineParser = new PosixParser();
    CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments);

    int port = SocketOpenOfficeConnection.DEFAULT_PORT;
    if (commandLine.hasOption(OPTION_PORT.getOpt())) {
        port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt()));
    }/*from  w  w w  .  j a v  a2s . c  o  m*/

    String outputFormat = null;
    if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) {
        outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt());
    }

    boolean verbose = false;
    if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) {
        verbose = true;
    }

    String dokeosMode = "woogie";
    if (commandLine.hasOption(OPTION_DOKEOS_MODE.getOpt())) {
        dokeosMode = commandLine.getOptionValue(OPTION_DOKEOS_MODE.getOpt());
    }
    int width = 800;
    if (commandLine.hasOption(OPTION_WIDTH.getOpt())) {
        width = Integer.parseInt(commandLine.getOptionValue(OPTION_WIDTH.getOpt()));
    }

    int height = 600;
    if (commandLine.hasOption(OPTION_HEIGHT.getOpt())) {
        height = Integer.parseInt(commandLine.getOptionValue(OPTION_HEIGHT.getOpt()));
    }

    String[] fileNames = commandLine.getArgs();
    if ((outputFormat == null && fileNames.length != 2 && dokeosMode != null) || fileNames.length < 1) {
        String syntax = "convert [options] input-file output-file; or\n"
                + "[options] -f output-format input-file [input-file...]";
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(syntax, OPTIONS);
        System.exit(EXIT_CODE_TOO_FEW_ARGS);
    }

    OpenOfficeConnection connection = new DokeosSocketOfficeConnection(port);
    try {
        if (verbose) {
            System.out.println("-- connecting to OpenOffice.org on port " + port);
        }
        connection.connect();
    } catch (ConnectException officeNotRunning) {
        System.err.println(
                "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
                        + port + ".");
        System.exit(EXIT_CODE_CONNECTION_FAILED);
    }
    try {

        // choose the good constructor to deal with the conversion
        DocumentConverter converter;
        if (dokeosMode.equals("oogie")) {
            converter = new OogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width,
                    height);
        } else if (dokeosMode.equals("woogie")) {
            converter = new WoogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width,
                    height);
        } else {
            converter = new OpenOfficeDocumentConverter(connection);
        }

        if (outputFormat == null) {
            File inputFile = new File(fileNames[0]);
            File outputFile = new File(fileNames[1]);
            convertOne(converter, inputFile, outputFile, verbose);
        } else {
            for (int i = 0; i < fileNames.length; i++) {
                File inputFile = new File(fileNames[i]);
                File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                        + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                convertOne(converter, inputFile, outputFile, verbose);
            }
        }
    } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
        connection.disconnect();
        System.err.println("ERROR: conversion failed.");
        System.exit(EXIT_CODE_CONVERSION_FAILED);
    } finally {
        if (verbose) {
            System.out.println("-- disconnecting");
        }
        connection.disconnect();
    }
}

From source file:jodtemplate.util.Utils.java

public static String getRelsPath(final String path) {
    final String fullPath = FilenameUtils.getFullPath(path);
    final String fileName = FilenameUtils.getName(path);
    return fullPath + "_rels/" + fileName + ".rels";
}

From source file:net.mitnet.tools.pdf.book.io.FileNameHelper.java

public static String rewriteFileNameSuffix(String sourceFileName, String newFileNameExtension) {
    String pathPath = FilenameUtils.getFullPath(sourceFileName);
    String baseFileName = FilenameUtils.getBaseName(sourceFileName);
    String newFileName = baseFileName + newFileNameExtension;
    String newFile = FilenameUtils.concat(pathPath, newFileName);
    return newFile;
}

From source file:br.com.pontocontrol.controleponto.ExtObject.java

protected static String projectRootPath() {
    String buildDir = FilenameUtils
            .getFullPath(main().getProtectionDomain().getCodeSource().getLocation().getFile());
    return new File(buildDir).getParentFile().getAbsolutePath();
}

From source file:eu.mrbussy.pdfsplitter.Splitter.java

/**
 * Split the given PDF file into multiple files using pages.
 * //from  w w  w .  j  a  va2  s. c  o m
 * @param filename
 *            - Name of the PDF to split
 * @param useSubFolder
 *            - Use a separate folder to place the files in.
 */
public static void Run(File file, boolean useSubFolder) {
    PdfReader reader = null;
    String format = null;

    if (useSubFolder) {
        format = "%1$s%2$s%4$s"; // Directory format
        try {
            FileUtils.forceMkdir(
                    new File(String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()),
                            FilenameUtils.getBaseName(file.getAbsolutePath()),
                            FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        format = "%1$s%2$s%4$s%2$s_%%03d.%3$s"; // Directory format + filename
    } else
        format = "%1$s%2$s_%%03d.%3$s";

    String splitFile = String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()),
            FilenameUtils.getBaseName(file.getAbsolutePath()),
            FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR);

    try {
        reader = new PdfReader(new FileInputStream(file));

        if (reader.getNumberOfPages() > 0) {
            for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) {
                System.out.println(String.format(splitFile, pageNum));
                String filename = String.format(splitFile, pageNum);
                Document document = new Document(reader.getPageSizeWithRotation(1));
                PdfCopy writer = new PdfCopy(document, new FileOutputStream(filename));
                document.open();
                // Copy the page from the original
                PdfImportedPage page = writer.getImportedPage(reader, pageNum);
                writer.addPage(page);
                document.close();
                writer.close();
            }
        }
    } catch (Exception ex) {
        // TODO Implement exception handling
        ex.printStackTrace(System.err);
    } finally {
        if (reader != null)
            // Always close the stream
            reader.close();
    }
}

From source file:controllers.base.Application.java

public static String minifyInProd(String file, Boolean neverMinify) {
    if (Play.isProd() && !ObjectUtils.defaultIfNull(neverMinify, false)) {
        String path = FilenameUtils.getFullPath(file);
        String name = FilenameUtils.getBaseName(file);
        String ext = FilenameUtils.getExtension(file);

        if (!name.toLowerCase().endsWith(".min")) {
            return String.format("%s%s.min.%s", path, name, ext);
        }//from w  w w  .  java 2  s  . c o m
    }

    return file;
}

From source file:com.notes.listen.FsWatchService.java

@Subscribe
@AllowConcurrentEvents/* w ww  .  j a  v  a2s  .c  o m*/
public void proc(PathEvent event) {
    try {

        Path path = event.getEventTarget();
        String fileName = FilenameUtils.concat("D:\\temp\\", path.toString());
        if (fileName.endsWith(".aspx")) {

            String fullPath = FilenameUtils.getFullPath(fileName);
            String srcName = FilenameUtils.getBaseName(fileName);

        }
    } catch (Error e) {
        e.printStackTrace();
    }

}

From source file:main.Operations.java

public boolean GetInfo(String path, String expath) {
    File f = new File(path);
    if (f.exists() && !f.isDirectory())
        URI = path;// w w  w. ja  va  2 s. co  m
    else
        return false;

    filename = FilenameUtils.getBaseName(path);
    extension = FilenameUtils.getExtension(path);

    destfile = path;

    if (".".equals(expath))
        exURI = FilenameUtils.getFullPath(URI);
    else
        exURI = expath;

    SetPrimaryImage();
    return true;
}

From source file:MSUmpire.BaseDataStructure.TandemParam.java

public void SetCombineFileName(String filename, String tag) {
    CombinedPepXML = FilenameUtils.separatorsToUnix(FilenameUtils.getFullPath(filename) + "interact-"
            + FilenameUtils.getBaseName(filename) + tag + ".tandem.combine.pep.xml");
    CombinedProt = FilenameUtils.getFullPath(filename) + FilenameUtils.getBaseName(filename) + tag
            + ".tandem.Qcombine.prot.xml";
}