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

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

Introduction

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

Prototype

public static String getName(String filename) 

Source Link

Document

Gets the name minus the path from a full filename.

Usage

From source file:de.xirp.plugin.PluginLoader.java

/**
 * Checks the needs of all plugins.//from w  w w .  jav  a 2 s  .  c o  m
 * 
 * @see IPlugable#requiredLibs()
 */
@SuppressWarnings("unchecked")
private static void checkAllNeeds() {
    HashMap<String, IPlugable> plugables = new HashMap<String, IPlugable>();
    MultiValueHashMap<String, String> refs = new MultiValueHashMap<String, String>();

    // list of all plugins
    List<String> fullPluginList = new ArrayList<String>(plugins.size());
    for (PluginInfo info : plugins.values()) {
        fullPluginList.add(info.getMainClass());
    }

    ClassLoader loader = logClass.getClass().getClassLoader();

    // Read the list of available jars from the class path
    String cp = ManagementFactory.getRuntimeMXBean().getClassPath();
    // String cp = System.getProperty("java.class.path");
    // //$NON-NLS-1$
    String[] jars = cp.split(File.pathSeparator);
    List<String> jarList = new ArrayList<String>(jars.length);
    for (String jar : jars) {
        jarList.add(FilenameUtils.getName(jar));
    }
    // The initial list of current plugins equals the full list
    // every plugin which does not full fill the needs
    // it removed from this list
    currentPluginList = new ArrayList<String>(fullPluginList);
    for (PluginInfo info : plugins.values()) {
        try {
            SecurePluginView view = PluginManager.getInstance(info, Robot.NAME_NONE);
            plugables.put(info.getMainClass(), view);
            boolean check = checkNeeds(view, loader, jarList);
            if (!check) {
                // remove plugins which reference this plugin
                removeRefs(info.getMainClass());
            }
        } catch (Exception e) {
            logClass.trace(e, e);
        }
    }
    // Remove all plugins of the full list
    // which are no more contained in the current list
    for (String clazz : fullPluginList) {
        if (!currentPluginList.contains(clazz)) {
            plugins.remove(clazz);
            plugables.remove(clazz);
        }
    }
    instances = new ArrayList<IPlugable>(plugables.values());
    refs.clear();
    refs = null;
    currentPluginList.clear();
    currentPluginList = null;
    fullPluginList.clear();
    fullPluginList = null;
}

From source file:com.epam.catgenome.manager.maf.parser.MafCodec.java

private void parseFileName(String fileName) {
    sampleName = Utils.removeFileExtension(FilenameUtils.getName(fileName), Utils.getFileExtension(fileName));
}

From source file:com.ephesoft.dcma.gwt.admin.bm.server.ImportBatchClassUploadServlet.java

private void attachFile(HttpServletRequest req, HttpServletResponse resp, BatchSchemaService batchSchemaService,
        DeploymentService deploymentService, BatchClassService bcService, ImportBatchService imService)
        throws IOException {
    PrintWriter printWriter = resp.getWriter();
    File tempZipFile = null;//  www.  ja  va2s . c o  m
    InputStream instream = null;
    OutputStream out = null;
    String zipWorkFlowName = BatchClassManagementConstants.EMPTY_STRING,
            tempOutputUnZipDir = BatchClassManagementConstants.EMPTY_STRING,
            systemFolderPath = BatchClassManagementConstants.EMPTY_STRING;
    BatchClass importBatchClass = null;
    if (ServletFileUpload.isMultipartContent(req)) {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        String exportSerailizationFolderPath = batchSchemaService.getBatchExportFolderLocation();
        File exportSerailizationFolder = new File(exportSerailizationFolderPath);
        if (!exportSerailizationFolder.exists()) {
            exportSerailizationFolder.mkdir();
        }
        String zipFileName = BatchClassManagementConstants.EMPTY_STRING;
        String zipPathname = BatchClassManagementConstants.EMPTY_STRING;
        List<FileItem> items;
        try {
            items = (List<FileItem>) upload.parseRequest(req);
            for (FileItem item : items) {
                if (!item.isFormField() && "importFile".equals(item.getFieldName())) {
                    zipFileName = item.getName();
                    if (zipFileName != null) {
                        zipFileName = zipFileName.substring(zipFileName.lastIndexOf(File.separator) + 1);
                    }
                    zipPathname = exportSerailizationFolderPath + File.separator + zipFileName;
                    if (zipFileName != null) {
                        zipFileName = FilenameUtils.getName(zipFileName);
                    }
                    try {
                        instream = item.getInputStream();
                        tempZipFile = new File(zipPathname);
                        if (tempZipFile.exists()) {
                            tempZipFile.delete();
                        }
                        out = new FileOutputStream(tempZipFile);
                        byte buf[] = new byte[BatchClassManagementConstants.BUFFER_SIZE];
                        int len = instream.read(buf);
                        while ((len) > 0) {
                            out.write(buf, 0, len);
                            len = instream.read(buf);
                        }
                    } catch (FileNotFoundException e) {
                        LOG.error("Unable to create the export folder." + e, e);
                        printWriter.write("Unable to create the export folder.Please try again.");

                    } catch (IOException e) {
                        LOG.error("Unable to read the file." + e, e);
                        printWriter.write("Unable to read the file.Please try again.");
                    } finally {
                        IOUtils.closeQuietly(out);
                        IOUtils.closeQuietly(instream);
                    }
                }
            }
        } catch (FileUploadException e) {
            LOG.error("Unable to read the form contents." + e, e);
            printWriter.write("Unable to read the form contents.Please try again.");
        }
        tempOutputUnZipDir = exportSerailizationFolderPath + File.separator
                + zipFileName.substring(0, zipFileName.lastIndexOf('.'));
        try {
            FileUtils.unzip(tempZipFile, tempOutputUnZipDir);
        } catch (Exception e) {
            LOG.error("Unable to unzip the file." + e, e);
            printWriter.write("Unable to unzip the file.Please try again.");
            tempZipFile.delete();
        }
        String serializableFilePath = FileUtils.getFileNameOfTypeFromFolder(tempOutputUnZipDir,
                SERIALIZATION_EXT);
        InputStream serializableFileStream = null;
        try {
            serializableFileStream = new FileInputStream(serializableFilePath);
            importBatchClass = (BatchClass) SerializationUtils.deserialize(serializableFileStream);
            zipWorkFlowName = importBatchClass.getName();
            systemFolderPath = importBatchClass.getSystemFolder();
            if (systemFolderPath == null) {
                systemFolderPath = BatchClassManagementConstants.EMPTY_STRING;
            }
        } catch (Exception e) {
            tempZipFile.delete();
            LOG.error("Error while importing" + e, e);
            printWriter.write("Error while importing.Please try again.");
        } finally {
            IOUtils.closeQuietly(serializableFileStream);
        }
    } else {
        LOG.error("Request contents type is not supported.");
        printWriter.write("Request contents type is not supported.");
    }
    if (tempZipFile != null) {
        tempZipFile.delete();
    }
    List<String> uncList = bcService.getAssociatedUNCList(zipWorkFlowName);
    boolean isWorkflowDeployed = deploymentService.isDeployed(zipWorkFlowName);
    boolean isWorkflowEqual = imService.isImportWorkflowEqualDeployedWorkflow(importBatchClass,
            importBatchClass.getName());
    printWriterMethod(printWriter, zipWorkFlowName, tempOutputUnZipDir, systemFolderPath, uncList,
            isWorkflowDeployed, isWorkflowEqual);
}

From source file:com.openkm.servlet.admin.OmrServlet.java

@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("doPost({}, {})", request, response);
    request.setCharacterEncoding("UTF-8");
    String action = "";
    String userId = request.getRemoteUser();
    updateSessionManager(request);/* w  w w.  ja  v  a 2 s. com*/

    try {
        if (ServletFileUpload.isMultipartContent(request)) {
            String fileName = null;
            InputStream is = null;
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<FileItem> items = upload.parseRequest(request);
            Set<String> properties = new HashSet<String>();
            Omr om = new Omr();

            for (Iterator<FileItem> it = items.iterator(); it.hasNext();) {
                FileItem item = it.next();

                if (item.isFormField()) {
                    if (item.getFieldName().equals("action")) {
                        action = item.getString("UTF-8");
                    } else if (item.getFieldName().equals("om_id")) {
                        om.setId(Integer.parseInt(item.getString("UTF-8")));
                    } else if (item.getFieldName().equals("om_name")) {
                        om.setName(item.getString("UTF-8"));
                    } else if (item.getFieldName().equals("om_properties")) {
                        properties.add(item.getString("UTF-8"));
                    } else if (item.getFieldName().equals("om_active")) {
                        om.setActive(true);
                    }
                } else {
                    is = item.getInputStream();
                    fileName = item.getName();
                }
            }

            om.setProperties(properties);

            if (action.equals("create") || action.equals("edit")) {
                // Store locally template file to be used later
                if (is != null && is.available() > 0) { // Case update only name
                    byte[] data = IOUtils.toByteArray(is);
                    File tmp = FileUtils.createTempFile();
                    FileOutputStream fos = new FileOutputStream(tmp);
                    IOUtils.write(data, fos);
                    IOUtils.closeQuietly(fos);

                    // Store template file
                    om.setTemplateFileName(FilenameUtils.getName(fileName));
                    om.setTemplateFileMime(MimeTypeConfig.mimeTypes.getContentType(fileName));
                    om.setTemplateFilContent(data);
                    IOUtils.closeQuietly(is);

                    // Create training files
                    Map<String, File> trainingMap = OMRHelper.trainingTemplate(tmp);
                    File ascFile = trainingMap.get(OMRHelper.ASC_FILE);
                    File configFile = trainingMap.get(OMRHelper.CONFIG_FILE);

                    // Store asc file
                    om.setAscFileName(om.getTemplateFileName() + ".asc");
                    om.setAscFileMime(MimeTypeConfig.MIME_TEXT);
                    is = new FileInputStream(ascFile);
                    om.setAscFileContent(IOUtils.toByteArray(is));
                    IOUtils.closeQuietly(is);

                    // Store config file
                    om.setConfigFileName(om.getTemplateFileName() + ".config");
                    om.setConfigFileMime(MimeTypeConfig.MIME_TEXT);
                    is = new FileInputStream(configFile);
                    om.setConfigFileContent(IOUtils.toByteArray(is));
                    IOUtils.closeQuietly(is);

                    // Delete temporal files
                    FileUtils.deleteQuietly(tmp);
                    FileUtils.deleteQuietly(ascFile);
                    FileUtils.deleteQuietly(configFile);
                }

                if (action.equals("create")) {
                    long id = OmrDAO.getInstance().create(om);

                    // Activity log
                    UserActivity.log(userId, "ADMIN_OMR_CREATE", Long.toString(id), null, om.toString());
                } else if (action.equals("edit")) {
                    OmrDAO.getInstance().updateTemplate(om);
                    om = OmrDAO.getInstance().findByPk(om.getId());

                    // Activity log
                    UserActivity.log(userId, "ADMIN_OMR_EDIT", Long.toString(om.getId()), null, om.toString());
                }

                list(userId, request, response);
            } else if (action.equals("delete")) {
                OmrDAO.getInstance().delete(om.getId());

                // Activity log
                UserActivity.log(userId, "ADMIN_OMR_DELETE", Long.toString(om.getId()), null, null);
                list(userId, request, response);
            } else if (action.equals("editAsc")) {
                Omr omr = OmrDAO.getInstance().findByPk(om.getId());
                omr.setAscFileContent(IOUtils.toByteArray(is));
                omr.setAscFileMime(MimeTypeConfig.MIME_TEXT);
                omr.setAscFileName(omr.getTemplateFileName() + ".asc");
                OmrDAO.getInstance().update(omr);
                omr = OmrDAO.getInstance().findByPk(om.getId());
                IOUtils.closeQuietly(is);

                // Activity log
                UserActivity.log(userId, "ADMIN_OMR_EDIT_ASC", Long.toString(om.getId()), null, null);
                list(userId, request, response);
            } else if (action.equals("editFields")) {
                Omr omr = OmrDAO.getInstance().findByPk(om.getId());
                omr.setFieldsFileContent(IOUtils.toByteArray(is));
                omr.setFieldsFileMime(MimeTypeConfig.MIME_TEXT);
                omr.setFieldsFileName(omr.getTemplateFileName() + ".fields");
                OmrDAO.getInstance().update(omr);
                omr = OmrDAO.getInstance().findByPk(om.getId());
                IOUtils.closeQuietly(is);

                // Activity log
                UserActivity.log(userId, "ADMIN_OMR_EDIT_FIELDS", Long.toString(om.getId()), null, null);
                list(userId, request, response);
            } else if (action.equals("check")) {
                File form = FileUtils.createTempFile();
                OutputStream formFile = new FileOutputStream(form);
                formFile.write(IOUtils.toByteArray(is));
                IOUtils.closeQuietly(formFile);
                formFile.close();
                Map<String, String> results = OMRHelper.process(form, om.getId());
                FileUtils.deleteQuietly(form);
                IOUtils.closeQuietly(is);
                UserActivity.log(userId, "ADMIN_OMR_CHECK_TEMPLATE", Long.toString(om.getId()), null, null);
                results(userId, request, response, action, results, om.getId());
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    }
}

From source file:com.ikon.servlet.admin.OmrServlet.java

@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("doPost({}, {})", request, response);
    request.setCharacterEncoding("UTF-8");
    String action = "";
    String userId = request.getRemoteUser();
    updateSessionManager(request);//ww w .ja  v  a  2 s  . c  o m

    try {
        if (ServletFileUpload.isMultipartContent(request)) {
            String fileName = null;
            InputStream is = null;
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<FileItem> items = upload.parseRequest(request);
            Set<String> properties = new HashSet<String>();
            Omr om = new Omr();

            for (Iterator<FileItem> it = items.iterator(); it.hasNext();) {
                FileItem item = it.next();

                if (item.isFormField()) {
                    if (item.getFieldName().equals("action")) {
                        action = item.getString("UTF-8");
                    } else if (item.getFieldName().equals("om_id")) {
                        om.setId(Integer.parseInt(item.getString("UTF-8")));
                    } else if (item.getFieldName().equals("om_name")) {
                        om.setName(item.getString("UTF-8"));
                    } else if (item.getFieldName().equals("om_properties")) {
                        properties.add(item.getString("UTF-8"));
                    } else if (item.getFieldName().equals("om_active")) {
                        om.setActive(true);
                    }
                } else {
                    is = item.getInputStream();
                    fileName = item.getName();
                }
            }

            om.setProperties(properties);

            if (action.equals("create") || action.equals("edit")) {
                // Store locally template file to be used later
                if (is != null && is.available() > 0) { // Case update only name
                    byte[] data = IOUtils.toByteArray(is);
                    File tmp = FileUtils.createTempFile();
                    FileOutputStream fos = new FileOutputStream(tmp);
                    IOUtils.write(data, fos);
                    IOUtils.closeQuietly(fos);

                    // Store template file
                    om.setTemplateFileName(FilenameUtils.getName(fileName));
                    om.setTemplateFileMime(MimeTypeConfig.mimeTypes.getContentType(fileName));
                    om.setTemplateFilContent(data);
                    IOUtils.closeQuietly(is);

                    // Create training files
                    Map<String, File> trainingMap = OMRHelper.trainingTemplate(tmp);
                    File ascFile = trainingMap.get(OMRHelper.ASC_FILE);
                    File configFile = trainingMap.get(OMRHelper.CONFIG_FILE);

                    // Store asc file
                    om.setAscFileName(om.getTemplateFileName() + ".asc");
                    om.setAscFileMime(MimeTypeConfig.MIME_TEXT);
                    is = new FileInputStream(ascFile);
                    om.setAscFileContent(IOUtils.toByteArray(is));
                    IOUtils.closeQuietly(is);

                    // Store config file
                    om.setConfigFileName(om.getTemplateFileName() + ".config");
                    om.setConfigFileMime(MimeTypeConfig.MIME_TEXT);
                    is = new FileInputStream(configFile);
                    om.setConfigFileContent(IOUtils.toByteArray(is));
                    IOUtils.closeQuietly(is);

                    // Delete temporal files
                    FileUtils.deleteQuietly(tmp);
                    FileUtils.deleteQuietly(ascFile);
                    FileUtils.deleteQuietly(configFile);
                }

                if (action.equals("create")) {
                    long id = OmrDAO.getInstance().create(om);

                    // Activity log
                    UserActivity.log(userId, "ADMIN_OMR_CREATE", Long.toString(id), null, om.toString());
                } else if (action.equals("edit")) {
                    OmrDAO.getInstance().updateTemplate(om);
                    om = OmrDAO.getInstance().findByPk(om.getId());

                    // Activity log
                    UserActivity.log(userId, "ADMIN_OMR_EDIT", Long.toString(om.getId()), null, om.toString());
                }

                list(userId, request, response);
            } else if (action.equals("delete")) {
                OmrDAO.getInstance().delete(om.getId());

                // Activity log
                UserActivity.log(userId, "ADMIN_OMR_DELETE", Long.toString(om.getId()), null, null);
                list(userId, request, response);
            } else if (action.equals("editAsc")) {
                Omr omr = OmrDAO.getInstance().findByPk(om.getId());
                omr.setAscFileContent(IOUtils.toByteArray(is));
                omr.setAscFileMime(MimeTypeConfig.MIME_TEXT);
                omr.setAscFileName(omr.getTemplateFileName() + ".asc");
                OmrDAO.getInstance().update(omr);
                omr = OmrDAO.getInstance().findByPk(om.getId());
                IOUtils.closeQuietly(is);

                // Activity log
                UserActivity.log(userId, "ADMIN_OMR_EDIT_ASC", Long.toString(om.getId()), null, null);
                list(userId, request, response);
            } else if (action.equals("editFields")) {
                Omr omr = OmrDAO.getInstance().findByPk(om.getId());
                omr.setFieldsFileContent(IOUtils.toByteArray(is));
                omr.setFieldsFileMime(MimeTypeConfig.MIME_TEXT);
                omr.setFieldsFileName(omr.getTemplateFileName() + ".fields");
                OmrDAO.getInstance().update(omr);
                omr = OmrDAO.getInstance().findByPk(om.getId());
                IOUtils.closeQuietly(is);

                // Activity log
                UserActivity.log(userId, "ADMIN_OMR_EDIT_FIELDS", Long.toString(om.getId()), null, null);
                list(userId, request, response);
            } else if (action.equals("check")) {
                File form = FileUtils.createTempFile();
                OutputStream formFile = new FileOutputStream(form);
                formFile.write(IOUtils.toByteArray(is));
                IOUtils.closeQuietly(formFile);
                formFile.close();
                Map<String, String> results = OMRHelper.process(form, om.getId());
                FileUtils.deleteQuietly(form);
                IOUtils.closeQuietly(is);
                UserActivity.log(userId, "ADMIN_OMR_CHECK_TEMPLATE", Long.toString(om.getId()), null, null);
                results(userId, request, response, action, results, om.getId());
            }
        }
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (FileUploadException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (OMRException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (InvalidFileStructureException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (InvalidImageIndexException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (UnsupportedTypeException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (MissingParameterException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    } catch (WrongParameterException e) {
        log.error(e.getMessage(), e);
        sendErrorRedirect(request, response, e);
    }
}

From source file:at.ac.univie.mminf.luceneSKOS.skos.impl.SKOSEngineImpl.java

/**
 * This constructor loads the SKOS model from a given filename or URI, starts
 * the indexing process and sets up the index searcher.
 * //from  w w  w .  j  a va2  s . co  m
 * @param languages
 *          the languages to be considered
 * @param filenameOrURI
 * @throws IOException
 */
public SKOSEngineImpl(final Version version, String filenameOrURI, String... languages) throws IOException {
    matchVersion = version;
    analyzer = new SimpleAnalyzer(matchVersion);

    String langSig = "";
    if (languages != null && languages.length > 0) {
        this.languages = new TreeSet<String>(Arrays.asList(languages));
        langSig = "-" + StringUtils.join(this.languages, ".");
    }

    String name = FilenameUtils.getName(filenameOrURI);
    File dir = new File("skosdata/" + name + langSig);
    indexDir = FSDirectory.open(dir);

    // TODO: Generate also if source file is modified
    if (!dir.isDirectory()) {
        // load the skos model from the given file
        FileManager fileManager = new FileManager();
        fileManager.addLocatorFile();
        fileManager.addLocatorURL();
        fileManager.addLocatorClassLoader(SKOSEngineImpl.class.getClassLoader());

        if (FilenameUtils.getExtension(filenameOrURI).equals("zip")) {
            fileManager.addLocatorZip(filenameOrURI);
            filenameOrURI = FilenameUtils.getBaseName(filenameOrURI);
        }

        skosModel = fileManager.loadModel(filenameOrURI);

        entailSKOSModel();

        indexSKOSModel();
    }

    searcher = new IndexSearcher(DirectoryReader.open(indexDir));
}

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.WorkflowUploadPortlet.java

@Override
protected void doUpload(ActionRequest request, ActionResponse response) {
    PortletContext context = getPortletContext();
    context.log("[FileUploadPortlet] doUpload() called");

    try {//from  w  w  w. j  av a  2  s  .com
        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);
        pfu.setSizeMax(uploadMaxSize); // Maximum upload size
        pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

        PortletSession ps = request.getPortletSession();
        if (ps.getAttribute("uploads", ps.APPLICATION_SCOPE) == null)
            ps.setAttribute("uploads", new Hashtable<String, ProgressListener>());

        //get the FileItems
        String fieldName = null;

        List fileItems = pfu.parseRequest(request);
        Iterator iter = fileItems.iterator();
        File serverSideFile = null;
        Hashtable h = new Hashtable(); //fileupload
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                fieldName = item.getFieldName();
                if ("newGrafName".equals(fieldName))
                    h.put("newGrafName", item.getString());
                if ("newAbstName".equals(fieldName))
                    h.put("newAbstName", item.getString());
                if ("newRealName".equals(fieldName))
                    h.put("newRealName", item.getString());
            } else { // item is not a form field, do file upload
                Hashtable<String, ProgressListener> tmp = (Hashtable<String, ProgressListener>) ps
                        .getAttribute("uploads");//,ps.APPLICATION_SCOPE
                pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

                String s = item.getName();
                s = FilenameUtils.getName(s);
                ProgressListener pl = pfu.getProgressListener();
                tmp.put(s, pl);
                ps.setAttribute("uploads", tmp);

                String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/" + request.getRemoteUser();
                File f = new File(tempDir);
                if (!f.exists())
                    f.mkdirs();
                serverSideFile = new File(tempDir, s);
                item.write(serverSideFile);
                item.delete();
                context.log("[FileUploadPortlet] - file " + s + " uploaded successfully to " + tempDir);
            }
        }
        // file upload to storage
        try {
            ServiceType st = InformationBase.getI().getService("wfs", "portal", new Hashtable(), new Vector());
            h.put("senderObj", "ZipFileSender");
            h.put("portalURL", PropertyLoader.getInstance().getProperty("service.url"));
            h.put("wfsID", st.getServiceUrl());
            h.put("userID", request.getRemoteUser());

            Hashtable hsh = new Hashtable();
            //                    st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
            //                    hsh.put("url", "http://localhost:8080/storage");
            st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
            PortalStorageClient psc = (PortalStorageClient) Class.forName(st.getClientObject()).newInstance();
            psc.setServiceURL(st.getServiceUrl());
            psc.setServiceID("/receiver");
            if (serverSideFile != null)
                psc.fileUpload(serverSideFile, "fileName", h);
        } catch (Exception ex) {
            response.setRenderParameter("full", "error.upload");
            ex.printStackTrace();
            return;
        }
        ps.removeAttribute("uploads", ps.APPLICATION_SCOPE);

    } catch (FileUploadException fue) {
        response.setRenderParameter("full", "error.upload");

        fue.printStackTrace();
        context.log("[FileUploadPortlet] - failed to upload file - " + fue.toString());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        response.setRenderParameter("full", "error.exception");
        context.log("[FileUploadPortlet] - failed to upload file - " + e.toString());
        return;
    }
    response.setRenderParameter("full", "action.succesfull");
}

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

/**
 * Gets checksum from ICAT for the newest instance destDao
 * @author Jens Peters/*from   ww  w . j av  a 2s  .c o m*/
 * @param destDao
 * @return
 */
public String getChecksum(String destDao) {
    String ret = "";
    String commandAsArray[] = new String[] { "ichksum", destDao };
    String out = executeIcommand(commandAsArray);
    if (out.indexOf("ERROR") >= 0)
        throw new RuntimeException(" Get Checksum of " + destDao + " failed !");
    Scanner scanner = new Scanner(out);
    String data_name = FilenameUtils.getName(destDao);
    if (data_name.length() > 30)
        data_name = data_name.substring(0, 30);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (line.contains(data_name)) {
            ret = line.substring(38, line.length());
        }
    }
    scanner.close();
    return ret;
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Export all collections in the repository.
 * /*from  w w w  . jav  a2s .c o m*/
 * @param repository - repository to export
 * @throws IOException 
 */
public void export(Repository repository, File zipFileDestination) throws IOException {
    // create the path if it doesn't exist
    String path = FilenameUtils.getPath(zipFileDestination.getCanonicalPath());
    if (!path.equals("")) {
        File pathOnly = new File(FilenameUtils.getFullPath(zipFileDestination.getCanonicalPath()));
        FileUtils.forceMkdir(pathOnly);
    }

    File collectionXmlFile = temporaryFileCreator.createTemporaryFile(extension);
    Set<FileInfo> allPictures = createXmlFile(collectionXmlFile, repository.getInstitutionalCollections(),
            true);

    FileOutputStream out = new FileOutputStream(zipFileDestination);
    ArchiveOutputStream os = null;
    try {
        os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
        os.putArchiveEntry(new ZipArchiveEntry("collection.xml"));

        FileInputStream fis = null;
        try {
            log.debug("adding xml file");
            fis = new FileInputStream(collectionXmlFile);
            IOUtils.copy(fis, os);
        } finally {
            if (fis != null) {
                fis.close();
                fis = null;
            }
        }

        log.debug("adding pictures size " + allPictures.size());
        for (FileInfo fileInfo : allPictures) {
            File f = new File(fileInfo.getFullPath());
            String name = FilenameUtils.getName(fileInfo.getFullPath());
            name = name + '.' + fileInfo.getExtension();
            log.debug(" adding name " + name);
            os.putArchiveEntry(new ZipArchiveEntry(name));
            try {
                log.debug("adding input stream");
                fis = new FileInputStream(f);
                IOUtils.copy(fis, os);
            } finally {
                if (fis != null) {
                    fis.close();
                    fis = null;
                }
            }
        }

        os.closeArchiveEntry();
        out.flush();
    } catch (ArchiveException e) {
        throw new IOException(e);
    } finally {
        if (os != null) {
            os.close();
            os = null;
        }
    }

    FileUtils.deleteQuietly(collectionXmlFile);

}

From source file:codes.thischwa.c5c.impl.LocalConnector.java

@Override
public boolean delete(String backendPath) throws C5CException {
    Path file = buildRealPath(backendPath);
    boolean isDir = Files.isDirectory(file);
    if (!Files.exists(file)) {
        logger.error("Requested file not exits: {}", file.toAbsolutePath());
        FilemanagerException.Key key = (isDir) ? FilemanagerException.Key.DirectoryNotExist
                : FilemanagerException.Key.FileNotExists;
        throw new FilemanagerException(FilemanagerAction.DELETE, key, file.getFileName().toString());
    }/* ww  w .java2 s.c  o  m*/
    boolean success = false;
    if (isDir) {
        try {
            FileUtils.deleteDirectory(file.toFile());
            success = true;
        } catch (IOException e) {
        }
    } else {
        try {
            Files.delete(file);
            success = true;
        } catch (IOException e) {
        }
    }
    if (!success)
        throw new FilemanagerException(FilemanagerAction.DELETE,
                FilemanagerException.Key.InvalidDirectoryOrFile, FilenameUtils.getName(backendPath));
    return isDir;
}