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

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

Introduction

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

Prototype

public static String getBaseName(String filename) 

Source Link

Document

Gets the base name, minus the full path and extension, from a full filename.

Usage

From source file:com.teradata.tempto.internal.convention.sql.SqlQueryConventionBasedTest.java

@Override
public String testCaseName() {
    String testCaseName;//from w ww . ja va 2 s  .c  om
    if (queryDescriptor.getName().isPresent()) {
        testCaseName = queryDescriptor.getName().get().replaceAll("\\s", "");
    } else {
        testCaseName = FilenameUtils.getBaseName(queryFile.getFileName().toString()) + "_" + testNumber;
    }

    if (!isAlphabetic(testCaseName.charAt(0))) {
        return "test_" + testCaseName;
    }

    return testCaseName;
}

From source file:com.streamsets.datacollector.cluster.TestTarFileCreator.java

private static void readJar(TarInputStream tis) throws IOException {
    TarEntry fileEntry = readFile(tis);//w  w w . j  av a 2 s.c o  m
    byte[] buffer = new byte[8192 * 8];
    int read = IOUtils.read(tis, buffer);
    JarInputStream jar = new JarInputStream(new ByteArrayInputStream(buffer, 0, read));
    JarEntry entry = jar.getNextJarEntry();
    Assert.assertNotNull(Utils.format("Read {} bytes and found a null entry", read), entry);
    Assert.assertEquals("sample.txt", entry.getName());
    read = IOUtils.read(jar, buffer);
    Assert.assertEquals(FilenameUtils.getBaseName(fileEntry.getName()),
            new String(buffer, 0, read, StandardCharsets.UTF_8));
}

From source file:cz.mzk.editor.server.quartz.jobs.ConvertImages.java

/**
 * {@inheritDoc}//from   w w w .j a  v  a  2  s.c  o  m
 */
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    ;
    this.setJobKey(context.getJobDetail().getKey());
    JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    guice = (Injector) dataMap.get("Injector");
    EditorConfiguration configuration = guice.getInstance(EditorConfiguration.class);
    ImageResolverDAO imageResolverDAO = guice.getInstance(ImageResolverDAO.class);

    String model = dataMap.getString("model");
    String code = dataMap.getString("code");

    ScanFolderImpl.ScanFolderFactory scanFolderFactory = guice
            .getInstance(ScanFolderImpl.ScanFolderFactory.class);
    ScanFolder scanFolder = scanFolderFactory.create(model, code);
    final List<String> fileNames = scanFolder.getFileNames();

    Collections.sort(fileNames);
    ArrayList<String> resolvedIdentifiers = null;
    try {
        resolvedIdentifiers = imageResolverDAO.resolveItems(fileNames);
    } catch (DatabaseException e) {
        e.printStackTrace();
    }

    //TODO-MR need refactoring! (http://jdem.cz/yeqp2)
    ArrayList<ImageItem> toAdd = new ArrayList<ImageItem>();
    ArrayList<ImageItem> result = new ArrayList<ImageItem>(fileNames.size());
    for (int i = 0; i < resolvedIdentifiers.size(); i++) {
        //get mimetype from extension (for audio)
        int position = fileNames.get(i).lastIndexOf('.');
        String extension = null;
        if (position > 0) {
            extension = fileNames.get(i).substring(position);
        }
        Constants.AUDIO_MIMETYPES audioMimeType = Constants.AUDIO_MIMETYPES.findByExtension(extension);

        String newIdentifier = null;
        String resolvedIdentifier = resolvedIdentifiers.get(i);
        if (resolvedIdentifier == null) {
            StringBuffer sb = new StringBuffer();
            sb.append(model).append('#').append(code).append('#').append(i);
            newIdentifier = UUID.nameUUIDFromBytes(sb.toString().getBytes()).toString();
            sb = new StringBuffer();
            sb.append(configuration.getImagesPath()).append(newIdentifier)
                    .append(Constants.JPEG_2000_EXTENSION);
            resolvedIdentifier = sb.toString();

            ImageItem item = new ImageItem(newIdentifier, resolvedIdentifier, fileNames.get(i));
            if (!audioMimeType.equals(Constants.AUDIO_MIMETYPES.UNKOWN_MIMETYPE)) {
                item.setMimeType(audioMimeType.getMimeType());
                sb = new StringBuffer();
                sb.append(configuration.getImagesPath()).append(newIdentifier)
                        .append(Constants.AUDIO_MIMETYPES.WAV_MIMETYPE.getExtension());
                item.setJpeg2000FsPath(sb.toString());
            }

            toAdd.add(item);
        }
        String uuid = newIdentifier != null ? newIdentifier
                : resolvedIdentifier.substring(resolvedIdentifier.lastIndexOf('/') + 1,
                        resolvedIdentifier.lastIndexOf('.'));
        ImageItem item = new ImageItem(uuid, resolvedIdentifier, fileNames.get(i));

        String name = FilenameUtils.getBaseName(fileNames.get(i));
        String[] splits = name.split("-");

        /** audio files - special name convection */
        if (splits.length == 4 && "DS".equals(splits[0])) {
            item.setName(splits[2] + "-" + splits[3]);
        }
        if (splits.length == 5 && "MC".equals(splits[0])) {
            item.setName(splits[2] + "-" + splits[3] + "-" + splits[4]);
        }

        result.add(item);
    }
    if (!toAdd.isEmpty()) {
        try {
            imageResolverDAO.insertItems(toAdd);
        } catch (DatabaseException e) {
            e.printStackTrace();
        }
        convert(toAdd);
    }
}

From source file:com.hpe.application.automation.tools.run.RunLoadRunnerScript.java

@Override
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
        @Nonnull TaskListener listener) throws InterruptedException, IOException {
    try {/*ww  w. j  av  a 2s  .c  om*/
        jenkinsInstance = Jenkins.getInstance();
        if (jenkinsInstance == null) {
            listener.error("Failed loading Jenkins instance ");
            build.setResult(Result.FAILURE);
            return;
        }
        logger = listener.getLogger();
        ArgumentListBuilder args = new ArgumentListBuilder();
        String scriptName = FilenameUtils.getBaseName(this.scriptsPath);
        FilePath buildWorkDir = workspace.child(build.getId());
        buildWorkDir.mkdirs();
        buildWorkDir = buildWorkDir.absolutize();
        if (build instanceof AbstractBuild) {
            slaveEnvVars = build.getEnvironment(listener);
        }
        FilePath scriptPath = workspace.child(slaveEnvVars.expand(this.scriptsPath));
        FilePath scriptWorkDir = buildWorkDir.child(scriptName);
        scriptWorkDir.mkdirs();
        scriptWorkDir = scriptWorkDir.absolutize();

        if (runScriptMdrv(launcher, args, slaveEnvVars, scriptPath, scriptWorkDir)) {
            build.setResult(Result.FAILURE);
            return;
        }

        final VirtualFile root = build.getArtifactManager().root();

        File masterBuildWorkspace = new File(new File(root.toURI()), "LRReport");
        if (!masterBuildWorkspace.exists()) {
            if (!root.exists()) {
                (new File(root.toURI())).mkdirs();
            }
            masterBuildWorkspace.mkdirs();
        }

        FilePath outputHTML = buildWorkDir.child(scriptName);
        outputHTML.mkdirs();
        outputHTML = outputHTML.child("result.html");
        FilePath xsltOnNode = copyXsltToNode(workspace);
        createHtmlReports(buildWorkDir, scriptName, outputHTML, xsltOnNode);
        LrScriptResultsParser lrScriptResultsParser = new LrScriptResultsParser(listener);
        lrScriptResultsParser.parseScriptResult(scriptName, buildWorkDir);
        copyScriptsResultToMaster(build, listener, buildWorkDir, new FilePath(masterBuildWorkspace));
        parseJunitResult(build, launcher, listener, buildWorkDir, scriptName);
        addLrScriptHtmlReportAcrion(build, scriptName);

        build.setResult(Result.SUCCESS);

    } catch (IllegalArgumentException e) {
        build.setResult(Result.FAILURE);
        logger.println(e);
    } catch (IOException | InterruptedException e) {
        listener.error("Failed loading build environment " + e);
        build.setResult(Result.FAILURE);
    } catch (XMLStreamException e) {
        listener.error(e.getMessage(), e);
        build.setResult(Result.FAILURE);
    }
}

From source file:net.sf.sze.service.impl.converter.PdfConverterImpl.java

/**
 * {@inheritDoc}/*w w  w .  j  a  v a  2s.  c om*/
 */
@Override
public int convertOdtToA4(File odtFile, File pdfFileA4, OO2PdfConverter oo2pdfConverter) {
    LOG.debug("Create DinA4-PDF");

    final int result;
    try {
        File tempPdf = File.createTempFile(FilenameUtils.getBaseName(pdfFileA4.getName()), ".pdf");
        FileUtils.deleteQuietly(tempPdf);
        oo2pdfConverter.convert(odtFile, tempPdf);

        PdfReader reader = new PdfReader(new FileInputStream(tempPdf));
        makeCleanPdfA(reader, pdfFileA4);
        FileUtils.deleteQuietly(tempPdf);
        result = reader.getNumberOfPages();
    } catch (DocumentException e) {
        throw new PDFConversionException(e);
    } catch (IOException e) {
        throw new PDFConversionException(e);
    }

    return result;
}

From source file:com.epam.catgenome.manager.DownloadFileManager.java

public String getFileNameFromUrlString(final String url) {
    return FilenameUtils.getBaseName(url);
}

From source file:edu.ku.brc.specify.config.ResImpExpMetaInfoDlg.java

@Override
public void createUI() {
    super.createUI();

    //HelpMgr.registerComponent(helpBtn, "ResImpExpMetaInfoDlg");

    DefaultComboBoxModel mimeModel = new DefaultComboBoxModel(
            new String[] { "XML", "Label", "Report", "Subreport" }); // I18N
    DefaultComboBoxModel typeModel = new DefaultComboBoxModel(
            new String[] { "Report", "Invoice", "WorkBench", "CollectionObject" }); // I18N

    DefaultComboBoxModel tblModel = new DefaultComboBoxModel(
            DBTableIdMgr.getInstance().getTablesForUserDisplay());

    mimeTypeCBX = createComboBox(mimeModel);

    nameTxt = createTextField();/*from  w w w . j a v  a 2s .  c o m*/
    descTxt = createTextField();

    CellConstraints cc = new CellConstraints();

    // Meta Info
    tableIdCBX = createComboBox(tblModel);
    reqsRecSetChk = createCheckBox("Is Record Set Required?");

    rptTypeCBX = createComboBox(typeModel);

    subReportsTxt = createTextField();
    actionsTxt = createTextField();

    PanelBuilder pb = new PanelBuilder(
            new FormLayout("p,2px,p,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,4px,p,4px,p,4px,p,4px")); //$NON-NLS-1$ //$NON-NLS-2$

    int y = 1;
    JLabel lbl = createI18NFormLabel("Mime Type"); // I18N
    pb.add(lbl, cc.xy(1, y));
    pb.add(mimeTypeCBX, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Name"); // I18N
    pb.add(lbl, cc.xy(1, y));
    pb.add(nameTxt, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Description"); // I18N
    pb.add(lbl, cc.xy(1, y));
    pb.add(descTxt, cc.xyw(3, y, 2));
    y += 2;

    lbl = createI18NFormLabel("Table"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(tableIdCBX, cc.xy(3, y));
    y += 2;

    pb.add(reqsRecSetChk, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Report Type"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(rptTypeCBX, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Sub-Reports"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(subReportsTxt, cc.xyw(3, y, 2));
    y += 2;

    lbl = createI18NFormLabel("Action"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(actionsTxt, cc.xyw(3, y, 2));
    y += 2;

    pb.setDefaultDialogBorder();

    nameTxt.setText(FilenameUtils.getBaseName(fileName));

    contentPanel = pb.getPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    pack();

    updateUI();

    mimeTypeCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateUI();
        }
    });
}

From source file:it.geosolutions.geobatch.global.XStreamCatalogLoader.java

protected void loadFlows(File dataDir, final Catalog catalog) {
    // ////from w  w  w.  ja  v a2  s.  c o  m
    //
    // load all flows
    //
    // //
    final Iterator<File> it = FileUtils.iterateFiles(dataDir, new String[] { "xml" }, false);
    while (it.hasNext()) {
        final File flowConfigFile = it.next();

        // skip catalog config file
        if (flowConfigFile.getName().equalsIgnoreCase(catalog.getId() + ".xml"))
            continue;

        try {

            // loaded
            if (LOGGER.isInfoEnabled())
                LOGGER.info("Loading flow from file " + flowConfigFile.getAbsolutePath());

            // try to load the flow and add it to the catalog
            // TODO change this: 

            DAO flowLoader = new XStreamFlowConfigurationDAO(dataDir.getAbsolutePath(), alias);
            String id = FilenameUtils.getBaseName(flowConfigFile.getName());
            FileBasedCatalogImpl fbcImpl = ((FileBasedCatalogImpl) CatalogHolder.getCatalog());
            final FileBasedFlowManager flowManager = new FileBasedFlowManager(id, flowLoader,
                    fbcImpl.getDataDirHandler());
            //              flow.setId(FilenameUtils.getBaseName(o.getName()));
            //                flowManager.setDAO(flowLoader);
            //                flowManager.load();

            // TODO ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            // add to the catalog
            catalog.add(flowManager);

            // loaded
            if (LOGGER.isInfoEnabled())
                LOGGER.info(new StringBuilder("Loaded flow from file ").append(flowConfigFile.getAbsolutePath())
                        .toString());
        } catch (Throwable t) {
            if (LOGGER.isWarnEnabled())
                LOGGER.warn("Skipping flow", t);
        }

    }
}

From source file:MSUmpire.DIA.DIAPack.java

public String GetBaseName() {
    return FilenameUtils.getBaseName(Filename);
}

From source file:edu.ku.brc.specify.datamodel.busrules.AttachmentBusRules.java

@Override
public void initialize(Viewable viewableArg) {
    super.initialize(viewableArg);

    if (formViewObj != null) {
        //morphbankPanel = formViewObj.getCompById("morphbankpanel");

        imageAttributeMultiView = formViewObj.getKids() != null && formViewObj.getKids().size() > 0
                ? formViewObj.getKids().get(0)
                : null;/*ww w .  jav a  2s.  c  om*/

        if (imageAttributeMultiView != null) {
            morphbankPanel = imageAttributeMultiView.getCurrentViewAsFormViewObj()
                    .getCompById("morphbankpanel");
        }

        origComp = formViewObj.getCompById("origFilename");
        final Component titleComp = formViewObj.getCompById("title");

        if (origComp instanceof EditViewCompSwitcherPanel) {
            EditViewCompSwitcherPanel evcsp = (EditViewCompSwitcherPanel) origComp;
            browser = (ValBrowseBtnPanel) evcsp.getComp(true);
            String dir = AppPreferences.getLocalPrefs().get(BROWSE_DIR_PREF, null);
            if (dir != null) {
                browser.setCurrentDir(dir);
            }
        }

        if (browser != null) {
            if (titleComp instanceof ValTextField) {
                final ValTextField titleTF = (ValTextField) titleComp;
                final ValTextField browserTF = browser.getValTextField();

                browserTF.getDocument().addDocumentListener(new DocumentAdaptor() {
                    @Override
                    protected void changed(DocumentEvent e) {
                        if (formViewObj.getDataObj() != null
                                && ((DataModelObjBase) formViewObj.getDataObj()).getId() == null) {
                            String filePath = browserTF.getText();
                            if (!filePath.isEmpty()) {
                                titleTF.setText(FilenameUtils.getBaseName(browserTF.getText()));
                                addImageAttributeIfNecessary();

                            } else {
                                if (!titleTF.getText().isEmpty()) {
                                    titleTF.setText(null);
                                }
                            }
                        }
                    }
                });

                browserTF.addFocusListener(new FocusAdapter() {
                    @Override
                    public void focusLost(FocusEvent e) {
                        super.focusLost(e);
                        if (formViewObj.getDataObj() != null
                                && ((DataModelObjBase) formViewObj.getDataObj()).getId() == null) {
                            String filePath = browserTF.getText();
                            if (titleTF.getText().isEmpty() && !filePath.isEmpty()) {
                                titleTF.setText(FilenameUtils.getBaseName(filePath));
                            }
                        }
                    }
                });
            }

            if (formViewObj.getRsController() != null && formViewObj.getRsController().getNewRecBtn() != null) {
                formViewObj.getRsController().getNewRecBtn().addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                browser.getBrowseBtn().doClick();
                            }
                        });
                    }
                });
            }
        }
    }
}