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:jodtemplate.pptx.ImageService.java

private Relationship getImageRelationship(final Image image, final Slide slide) {
    final Path imageFullPath = Paths.get(image.getFullPath());
    final Path slideFullPath = Paths.get(FilenameUtils
            .getFullPath(slide.getPresentation().getFullPath() + slide.getRelationship().getTarget()));
    final Path relativeImagePath = slideFullPath.relativize(imageFullPath);
    final String normRelativeImagePath = FilenameUtils.separatorsToUnix(relativeImagePath.toString());

    Relationship imageRel = slide.getRelationshipByTarget(normRelativeImagePath);

    if (imageRel == null) {
        imageRel = new Relationship();
        imageRel.setId(slide.getNextId());
        imageRel.setTarget(normRelativeImagePath);
        imageRel.setType(Relationship.IMAGE_TYPE);
        slide.addOtherRelationship(imageRel);
    }// ww  w .  j a  v  a 2  s  . c om

    return imageRel;
}

From source file:com.tao_harmony.fx2extend.journal.JournalUtil.java

/**
 * ?????. ?????????????????./* w w  w  .  j  a  va 2  s .c  o  m*/
 *
 * @param journals
 *            
 * @param specifications
 *            
 * @param fileName
 *            ?
 * @throws NoListException
 *             ?Null??????
 * @throws IOException
 *             ???????
 * @throws FileNameEmptyException
 *             ???Null??????
 */
public static void saveJournals(List<Journal> journals, List<DepartmentSpecification> specifications,
        String fileName) throws NoListException, IOException, FileNameEmptyException {
    // ????
    saveJournals(journals, fileName);
    // ????
    // ???.cls???
    String name = FilenameUtils.getFullPath(fileName) + FilenameUtils.getBaseName(fileName) + ".cls";
    CsvManager csvManager = new CsvEntityManager();
    //CsvManager csvManager=CsvManagerFactory.newCsvManager();
    csvManager.save(specifications, DepartmentSpecification.class).to(new File(name));
}

From source file:MSUmpire.DIA.MixtureModelKDESemiParametric.java

public void GeneratePlot(String pngfile) throws IOException {
    String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile)
            + "_ModelPoints.txt";
    FileWriter writer = new FileWriter(modelfile);

    double[] IDObs = new double[IDEmpiricalDist.getN()];
    double[] DecoyObs = new double[DecoyEmpiricalDist.getN()];

    for (int i = 0; i < IDEmpiricalDist.getN(); i++) {
        IDObs[i] = IDEmpiricalDist.getObs(i);
    }/*from   w  w  w .  ja va  2s  .com*/
    for (int i = 0; i < DecoyEmpiricalDist.getN(); i++) {
        DecoyObs[i] = DecoyEmpiricalDist.getObs(i);
    }

    XYSeries model1 = new XYSeries("Incorrect matches");
    XYSeries model2 = new XYSeries("Correct matches");
    XYSeries model3 = new XYSeries("All target hits");

    writer.write("UScore\tModel\tCorrect\tDecoy\n");
    for (int i = 0; i < NoBinPoints; i++) {
        model1.add(model_kde_x[i], decoy_kde_y[i]);
        model2.add(model_kde_x[i], correct_kde_y[i]);
        model3.add(model_kde_x[i], model_kde_y[i]);
        writer.write(model_kde_x[i] + "\t" + model_kde_y[i] + "\t" + correct_kde_y[i] + "\t" + decoy_kde_y[i]
                + "\n");
    }
    writer.close();

    MixtureModelProb = new float[NoBinPoints + 1][3];
    float positiveaccu = 0f;
    float negativeaccu = 0f;

    MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE;
    MixtureModelProb[0][1] = 1f;
    MixtureModelProb[0][2] = 1f;

    for (int i = 1; i < NoBinPoints + 1; i++) {
        double positiveNumber = correct_kde_y[NoBinPoints - i];
        double negativeNumber = decoy_kde_y[NoBinPoints - i];
        MixtureModelProb[i][0] = (float) model_kde_x[NoBinPoints - i];
        positiveaccu += positiveNumber;
        negativeaccu += negativeNumber;
        MixtureModelProb[i][2] = 0.999999f * (float) (positiveNumber / (negativeNumber + positiveNumber));
        MixtureModelProb[i][1] = 0.999999f * (float) (positiveaccu / (negativeaccu + positiveaccu));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(model1);
    dataset.addSeries(model2);
    dataset.addSeries(model3);

    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.setType(HistogramType.SCALE_AREA_TO_1);
    histogramDataset.addSeries("ID hits", IDObs, 100);
    histogramDataset.addSeries("Decoy hits", DecoyObs, 100);
    //histogramDataset.addSeries("Model hits", ModelObs, 100);

    JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits",
            histogramDataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(min, max);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.8f);
    chart.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer();

    plot.setDataset(1, dataset);
    plot.setRenderer(1, render);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    try {
        ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
    } catch (IOException e) {
    }
}

From source file:com.bekwam.resignator.SettingsController.java

@FXML
public void browseForJDK() {
    if (logger.isDebugEnabled()) {
        logger.debug("[BROWSE FOR JDK]");
    }/*from   w ww .  java2 s .co m*/

    DirectoryChooser dirChooser = new DirectoryChooser();
    dirChooser.setTitle("Select a JDK");
    dirChooser.setInitialDirectory(new File(jdkDir));

    File d = dirChooser.showDialog(stage);
    if (d != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("[BROWSE FOR JDK] selected dir={}", d.getAbsolutePath());
        }
        tfJDKHome.setText(d.getAbsolutePath());
        jdkDir = FilenameUtils.getFullPath(d.getAbsolutePath());
    }
}

From source file:de.uzk.hki.da.grid.IrodsGridFacade.java

/**
 * register On Working resource./*from w  w  w.j  a v a  2 s.com*/
 *
 * @param file the file
 * @param targetLogically the target logically
 * @param gridfile the gridfile
 * @return true, if successful
 * @throws IOException Signals that an I/O exception has occurred.
 */
private boolean registerOnWorkingResourceAndComputeChecksum(File file, String targetLogically, File gridfile,
        StoragePolicy sp) throws IOException {
    logger.debug("register " + gridfile + " as " + targetLogically);
    if (!irodsSystemConnector.collectionExists(FilenameUtils.getFullPath(targetLogically)))
        irodsSystemConnector.createCollection(FilenameUtils.getFullPath(targetLogically));
    irodsSystemConnector.registerFile(targetLogically, gridfile, irodsSystemConnector.getDefaultStorage());
    if (irodsSystemConnector.fileExists(targetLogically)) {
        logger.debug("compute checksum on " + targetLogically);
        String MD5CheckSum = MD5Checksum.getMD5checksumForLocalFile(file);
        if (irodsSystemConnector.computeChecksum(targetLogically).equals(MD5CheckSum)) {
            irodsSystemConnector.saveOrUpdateAVUMetadataDataObject(targetLogically, "chksum", MD5CheckSum);
            return true;
        }
    }
    return false;
}

From source file:OogieDocumentConverter.java

protected void loadAndExport(String inputUrl, Map/*<String,Object>*/ loadProperties, String outputUrl,
        Map/*<String,Object>*/ storeProperties) throws Exception {
    XComponentLoader desktop = openOfficeConnection.getDesktop();
    XComponent document = desktop.loadComponentFromURL(inputUrl, "_blank", 0, toPropertyValues(loadProperties));
    if (document == null) {
        throw new OpenOfficeException("conversion failed: input document is null after loading");
    }/*from  w  w  w  .ja  v a2  s  .  c om*/

    refreshDocument(document);

    try {

        outputUrl = FilenameUtils.getFullPath(outputUrl) + FilenameUtils.getBaseName(outputUrl);

        //          filter
        PropertyValue[] loadProps = new PropertyValue[4];

        // type of image
        loadProps[0] = new PropertyValue();
        loadProps[0].Name = "MediaType";
        loadProps[0].Value = "image/png";

        // Height and width
        PropertyValue[] filterDatas = new PropertyValue[4];
        for (int i = 0; i < 4; i++) {
            filterDatas[i] = new PropertyValue();
        }

        filterDatas[0].Name = "PixelWidth";
        filterDatas[0].Value = new Integer(this.width);
        filterDatas[1].Name = "PixelHeight";
        filterDatas[1].Value = new Integer(this.height);
        filterDatas[2].Name = "LogicalWidth";

        filterDatas[2].Value = new Integer(2000);
        filterDatas[3].Name = "LogicalHeight";
        filterDatas[3].Value = new Integer(2000);

        XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime
                .queryInterface(XDrawPagesSupplier.class, document);
        //System.out.println(pagesSupplier.toString());            
        XDrawPages pages = pagesSupplier.getDrawPages();
        int nbPages = pages.getCount();
        String[] slidenames = new String[nbPages];
        Arrays.fill(slidenames, "");

        for (int i = 0; i < nbPages; i++) {

            XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class,
                    pages.getByIndex(i));
            XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, page);
            int top = 0;
            String slidename = "";
            for (int j = 0; j < xShapes.getCount(); j++) {
                XShape firstXshape = (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(j));
                Point pos = firstXshape.getPosition();
                if (pos.Y < top || top == 0) {
                    XText xText = (XText) UnoRuntime.queryInterface(XText.class, firstXshape);
                    if (xText != null && xText.getString().length() > 0) {
                        top = pos.Y;
                        slidename = xText.getString();
                    }
                }
            }

            String slidenameDisplayed = "";
            if (slidename.trim().length() == 0) {
                slidename = "slide" + (i + 1);
            } else {
                int nbSpaces = 0;
                String formatedSlidename = "";
                slidename = slidename.replaceAll(" ", "_");
                slidename = slidename.replaceAll("\n", "_");
                slidename = slidename.replaceAll("__", "_");

                for (int j = 0; j < slidename.length(); j++) {
                    char currentChar = slidename.charAt(j);
                    if (currentChar == '_') {
                        nbSpaces++;
                    }
                    if (nbSpaces == 5) {
                        break;
                    }
                    formatedSlidename += slidename.charAt(j);
                }

                slidenameDisplayed = formatedSlidename;

                slidename = formatedSlidename.toLowerCase();
                slidename = slidename.replaceAll("\\W", "_");
                slidename = slidename.replaceAll("__", "_");
                slidename = StringOperation.sansAccent(slidename);

            }
            int j = 1;
            String slidenamebackup = slidename;
            Arrays.sort(slidenames);
            while (Arrays.binarySearch(slidenames, slidename) >= 0) {
                j++;
                slidename = slidenamebackup + j;
            }
            slidenames[nbPages - (i + 1)] = slidename;

            XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class, page);

            xPageName.setName(slidename);

            XMultiComponentFactory localServiceManager = ((DokeosSocketOfficeConnection) this.openOfficeConnection)
                    .getServiceManager();
            Object GraphicExportFilter = localServiceManager.createInstanceWithContext(
                    "com.sun.star.drawing.GraphicExportFilter",
                    ((DokeosSocketOfficeConnection) this.openOfficeConnection).getComponentContext());

            XExporter xExporter = (XExporter) UnoRuntime.queryInterface(XExporter.class, GraphicExportFilter);

            XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, page);

            xExporter.setSourceDocument(xComp);
            loadProps[1] = new PropertyValue();
            loadProps[1].Name = "URL";

            loadProps[1].Value = outputUrl + "/" + xPageName.getName() + ".png";
            loadProps[2] = new PropertyValue();
            loadProps[2].Name = "FilterData";
            loadProps[2].Value = filterDatas;
            loadProps[3] = new PropertyValue();
            loadProps[3].Name = "Quality";
            loadProps[3].Value = new Integer(100);

            XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, GraphicExportFilter);

            xFilter.filter(loadProps);
            if (slidenameDisplayed == "")
                slidenameDisplayed = xPageName.getName();
            System.out.println(slidenameDisplayed + "||" + xPageName.getName() + ".png");

        }

    } finally {
        document.dispose();
    }
}

From source file:de.iai.ilcd.xml.read.SourceReader.java

@Override
public Source parse(JXPathContext context, PrintWriter out) {

    context.registerNamespace("ilcd", "http://lca.jrc.it/ILCD/Source");

    Source source = new Source();

    // OK, now read in all fields common to all DataSet types
    readCommonFields(source, DataSetType.SOURCE, context);

    IMultiLangString shortName = parserHelper.getIMultiLanguageString("//common:shortName");
    IMultiLangString citation = parserHelper.getIMultiLanguageString("//ilcd:sourceCitation");
    String publicationType = parserHelper.getStringValue("//ilcd:publicationType");
    PublicationTypeValue publicationTypeValue = PublicationTypeValue.UNDEFINED;
    if (publicationType != null) {
        try {// ww w. j a  v a2 s . co  m
            publicationTypeValue = PublicationTypeValue.fromValue(publicationType);
        } catch (Exception e) {
            if (out != null) {
                out.println("Warning: the field publicationType has an illegal value " + publicationType);
            }
        }
    }

    IMultiLangString description = parserHelper.getIMultiLanguageString("//ilcd:sourceDescriptionOrComment");

    source.setShortName(shortName);
    source.setName(shortName);
    source.setCitation(citation);
    source.setPublicationType(publicationTypeValue);
    source.setDescription(description);

    List<String> digitalFileReferences = parserHelper.getStringValues("//ilcd:referenceToDigitalFile", "uri");
    for (String digitalFileReference : digitalFileReferences) {
        logger.info("raw source data set file name is {}", getDataSetFileName());
        String baseDirectory = FilenameUtils.getFullPath(getDataSetFileName());
        // get rid of any leading/trailing white space
        digitalFileReference = digitalFileReference.trim();
        String absoluteFileName = FilenameUtils.concat(baseDirectory, digitalFileReference);
        absoluteFileName = FilenameUtils.normalize(absoluteFileName);
        logger.info("normalized form of digital file name is {}", absoluteFileName);
        logger.debug("reference to digital file: " + absoluteFileName);
        File file = new File(absoluteFileName);
        DigitalFile digitalFile = new DigitalFile();
        logger.debug("canread:" + (file.canRead()));
        String fileName = null;
        if (file.canRead()) {
            fileName = absoluteFileName; // file will be imported and Name
            // stripped after importing
        } else if (absoluteFileName.toLowerCase().endsWith(".jpg")
                || absoluteFileName.toLowerCase().endsWith(".jpeg")
                || absoluteFileName.toLowerCase().endsWith(".gif")
                || absoluteFileName.toLowerCase().endsWith(".pdf")) {
            // in case we're on a case sensitive filesystem and the case of the extension is not correct, we'll try
            // to fix this
            // TO DO this could be a little more elegant

            java.io.File parentDir = file.getParentFile();
            String fileNotFound = file.getName();
            String[] matches = parentDir.list(new CaseInsensitiveFilenameFilter(fileNotFound));
            if (matches != null && matches.length == 1) {
                fileName = parentDir + File.separator + matches[0];
                logger.debug(fileName);
            } else {
                fileName = digitalFileReference;
            }
        } else {
            logger.debug("file could not be read from " + file.getAbsolutePath());
            fileName = digitalFileReference; // Not a local filename, likely
            // be an URL to external
            // resource
        } // logger.debug("found reference to digital file: " + fileName);
        logger.info("set filename of digital file to {}", fileName);
        digitalFile.setFileName(fileName);
        source.addFile(digitalFile);
    }

    List<GlobalReference> contacts = commonReader.getGlobalReferences("//ilcd:referenceToContact", out);
    for (GlobalReference contact : contacts) {
        source.addContact(contact);
    }

    return source;
}

From source file:com.ewcms.publication.freemarker.generator.ListGenerator.java

@Override
public String[] getPublishAdditionUris() throws PublishException {
    String[] additionUris = new String[0];
    if (createHome && pageNumber == 0) {
        logger.debug("Start create home uri");
        String uri = getPublishUri();
        logger.debug("List page first uri is {}", uri);
        String extension = FilenameUtils.getExtension(uri);
        if (StringUtils.isNotBlank(extension)) {
            extension = "." + extension;
        }/* w  ww. j  av a  2 s .co m*/
        String homeUri = FilenameUtils.getFullPath(uri) + DEFAULT_HOME_NAME + extension;
        additionUris = new String[] { homeUri };
        logger.debug("Home page uri is {}", additionUris[0]);
    }
    return additionUris;
}

From source file:com.nuvolect.deepdive.util.OmniUtil.java

/**
 * Return a unique file given the current file as a model.
 * Example if file exists: /Picture/mypic.jpg > /Picture/mypic~.jpg
 * @return/*from  w  w w. j  av  a2s  .  co  m*/
 */
public static OmniFile makeUniqueName(OmniFile initialFile) {

    String path = initialFile.getPath();
    String basePath = FilenameUtils.getFullPath(path); // path without name
    String baseName = FilenameUtils.getBaseName(path); // name without extension
    String extension = FilenameUtils.getExtension(path); // extension
    String volumeId = initialFile.getVolumeId();
    String dot = ".";
    if (extension.isEmpty())
        dot = "";
    OmniFile file = initialFile;

    while (file.exists()) {

        baseName += "~";
        String fullPath = basePath + baseName + dot + extension;
        file = new OmniFile(volumeId, fullPath);
    }
    return file;
}

From source file:com.abelsky.idea.geekandpoke.entries.impl.OfflineCacheImpl.java

private @Nullable File initRootDirectory() {
    final PluginId id = PluginId.getId(ComicsPlugin.PLUGIN_ID);

    @Nullable/*from ww  w  .j  a va2 s. com*/
    final IdeaPluginDescriptor plugin = PluginManager.getPlugin(id);
    log.assertTrue(plugin != null, "Cannot find plugin \"" + ComicsPlugin.PLUGIN_ID + "\"");

    //noinspection ConstantConditions
    final File pluginPath = plugin.getPath();

    if (pluginPath.isDirectory()) {
        // <my-plugin>/cache
        return new File(pluginPath, "cache");

    } else {
        // <plugins-directory>/<my-plugin>.jar
        final String absolutePath = pluginPath.getAbsolutePath();

        // <plugins-directory>
        final String rootPath = FilenameUtils.getFullPath(absolutePath);

        // <my-plugin>
        final String baseName = FilenameUtils.getBaseName(absolutePath);

        // <plugins-directory>/<my-plugin>.cache
        final File cachePath = new File(rootPath, baseName + ".cache");

        if (cachePath.isFile()) {
            FileUtil.delete(cachePath);
        }

        if (!cachePath.exists()) {
            if (!cachePath.mkdir()) {
                // Couldn't create anything useful, just return some temporary directory.
                if (log.isDebugEnabled()) {
                    log.debug("Couldn't initialize cache at " + cachePath);
                }

                try {
                    return FileUtil.createTempDirectory(baseName, "");
                } catch (IOException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Couldn't create temporary directory with base name \"" + baseName
                                + "\" in \"" + FileUtil.getTempDirectory() + "\"");
                    }
                }
            }
        }

        return cachePath;
    }
}