⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesystemviewdispatchaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("List files.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;

        try {
            DAVResource res = getResourceForPath(request, response, fileSystemForm);
            ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
            if (fwd != null) {
                return fwd;
            }
            buildModel(res, fileSystemForm, request);
        } catch (Exception e) {
            throw e;
        }

        return mapping.findForward("display");
    }

    void buildModel(DAVResource res, FileSystemForm fileSystemForm, HttpServletRequest request) throws Exception {
        List allFileSystemItems = new ArrayList();
        ActionMessages warnings = new ActionMessages();
        if (res != null) {
            Iterator itr = res.getChildren();

            for (int i = 0; itr != null && itr.hasNext(); i++) {
                // We overide to string so filtering works
                Calendar gc = new GregorianCalendar() {
                    public String toString() {
                        return SimpleDateFormat.getInstance().format(this.getTime());
                    }
                };
                FileObjectDAVResource element = (FileObjectDAVResource) itr.next();
                // this is an extra defense against imaginary files.
                FileType ft = null;
                try {
                    ft = element.getFile().getType();
                } catch (FileSystemException e) {
                } catch (IOException e) {
                }
                FileSystemItem item = null;
                if (ft != null && element.getFile().getType().equals(FileType.FOLDER)
                                && fileSystemForm.getNetworkPlace().isAllowResursive()) {
                    // if it is a folder
                    gc.setTime(element.getLastModified());
                    item = new FolderItem(element.getDisplayName(), res.getMount().getStore().getName(), fileSystemForm.getPath(),
                                    gc, element.getFile().getType().getName(), false, i);
                } else if (ft != null && element.getFile().getType().equals(FileType.FILE)) {
                    // if it is a file
                    gc.setTime(element.getLastModified());
                    item = new FileItem(element.getDisplayName(), element.getContentLength().longValue(), gc, element.getFile()
                                    .getType().getName(), false, i);
                } else {
                    if (log.isInfoEnabled())
                        log.info("Unable to display file " + element.getDisplayName() + " as it is an imaginary file.");
                    warnings.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("vfs", "vfs.imaginary.file", element
                                    .getDisplayName()));

                    // decrement the counter as there is no file added.
                    i--;
                }
                if (item != null) {
                    allFileSystemItems.add(item);
                    if (request.getParameter("select" + Util.urlEncode(item.getFileName())) != null) {
                        item.setChecked(true);
                    }
                }
            }
            if (fileSystemForm.getPaths() == null || fileSystemForm.getPaths().isEmpty()) {
                fileSystemForm.setHome(fileSystemForm.getPath());
            } else {
                fileSystemForm.addPath(fileSystemForm.getPath());
            }
        }
        if (warnings.size() > 0) {
            addWarnings(request, warnings);
        }
        fileSystemForm.initialize(request, allFileSystemItems, this.getSessionInfo());
    }

    DAVResource getResourceForPath(HttpServletRequest request, HttpServletResponse response, FileSystemForm fileSystemForm)
                    throws Exception {
        DAVResource res = DAVServlet.getDAVResource(request, response, fileSystemForm.getPath());
        if (res == null) {
            throw new Exception("Could not find network place resource for path " + fileSystemForm.getPath() + ".");
        }
        NetworkPlace np = (res.getMount() instanceof AbstractNetworkPlaceMount) ? ((AbstractNetworkPlaceMount) res.getMount())
                        .getNetworkPlace() : null;
        if (np == null) {
            throw new Exception("No network place.");
        }
        fileSystemForm.setNetworkPlace(np);
        return res;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
    }

    /**
     * <p>
     * Zip a collection of files from the file system to your choice.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward zip(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("Zip files.");

        FileSystemForm fileSystemForm = (FileSystemForm) form;
        DAVResource res = getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        buildModel(res, fileSystemForm, request);
        String[] uris = fileSystemForm.getSelectedFileNames();
        if (uris == null || uris.length < 1) {
            ActionMessages msgs = getErrors(request);
            msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.zip.select.error"));
            saveErrors(request, msgs);
            return mapping.getInputForward();
        }
        return zipSelection(mapping, request, fileSystemForm, uris);
    }

    /**
     * <p>
     * Zip a selection of files.
     * 
     * @param mapping action mapping
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param fileSystemForm The <code>FileSystemForm<code> for the action.
     * @param uris An array of selected files.
     * @return fwd forward to direct
     */
    private ActionForward zipSelection(ActionMapping mapping, HttpServletRequest request, FileSystemForm fileSystemForm,
                                       String[] uris) {
        ActionForward fwd = mapping.findForward("showFileDownload");
        /*
         * TODO now the vfs displays in its own window using page intercept
         * listeners is going to be a bad idea.
         * 
         * In this case we forward straight to the download page to get it out
         * of the way as quick as possible.
         * 
         * If the user tries to use the main interface whilsts a download is
         * waiting, weird stuff is going to happen.
         * 
         * In fact, now there is the possibility of multiple windows for every
         * use page intercept listeners are a bad idea full stop.
         */
        FileDownloadPageInterceptListener l = (FileDownloadPageInterceptListener) CoreUtil.getPageInterceptListenerById(request
                        .getSession(), FileDownloadPageInterceptListener.INTERCEPT_ID);
        if (l == null) {
            l = new FileDownloadPageInterceptListener();
            CoreUtil.addPageInterceptListener(request.getSession(), l);
        }
        int id = l.addDownload(new ZipDownload(fwd, fileSystemForm.getPath(), uris, new ActionForward(
                        "/fileSystem.do?actionTarget=list&path=" + fileSystemForm.getPath()), "downloadZip.message", "vfs"));
        return CoreUtil.addParameterToForward(fwd, "id", String.valueOf(id));
    }

    /**
     * <p>
     * Delete the selected files.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("Delete files.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        DAVResource res = getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        buildModel(res, fileSystemForm, request);
        String[] uris = fileSystemForm.getSelectedFileNames();
        for (int i = 0; i < uris.length; i++) {
            String delPath = fileSystemForm.getPath() + "/" + uris[i];
            deleteSingleFile(request, response, delPath, fileSystemForm);
        }
        return mapping.findForward("list");
    }

    /**
     * <p>
     * redirect ot confirm the deletion.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward deleteSelected(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled())
            log.debug("Delete selected files.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        DAVResource res = getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        buildModel(res, fileSystemForm, request);
        Object[] uris = fileSystemForm.getSelectedFileNames();
        if (uris == null || uris.length < 1) {
            ActionMessages msgs = getErrors(request);
            msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.delete.select.error"));
            saveErrors(request, msgs);
            return mapping.getInputForward();
        }
        return mapping.findForward("deleteFiles");
    }

    /**
     * <p>
     * Delete the selected file.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward deleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("Delete file.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        DAVResource res = getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        buildModel(res, fileSystemForm, request);
        String delPath = fileSystemForm.getPath() + "/" + fileSystemForm.getFileName();
        deleteSingleFile(request, response, delPath, fileSystemForm);
        return mapping.findForward("list");
    }

    /**
     * <p>
     * Confirm deletion of the selected single file.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -