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

📄 filesystemviewdispatchaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package com.sslexplorer.vfs.actions;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.sslexplorer.boot.Util;
import com.sslexplorer.core.BundleActionMessage;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.FileDownloadPageInterceptListener;
import com.sslexplorer.core.PopupException;
import com.sslexplorer.core.actions.AbstractPopupAuthenticatedDispatchAction;
import com.sslexplorer.policyframework.NoPermissionException;
import com.sslexplorer.policyframework.OwnedResource;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.ResourceType;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.vfs.FileItem;
import com.sslexplorer.vfs.FileSystemItem;
import com.sslexplorer.vfs.FolderItem;
import com.sslexplorer.vfs.NetworkPlace;
import com.sslexplorer.vfs.NetworkPlaceResourceType;
import com.sslexplorer.vfs.UploadDetails;
import com.sslexplorer.vfs.ZipDownload;
import com.sslexplorer.vfs.clipboard.Clipboard;
import com.sslexplorer.vfs.clipboard.DAVResourceClipboardContent;
import com.sslexplorer.vfs.forms.FileSystemForm;
import com.sslexplorer.vfs.utils.DAVUploadHandler;
import com.sslexplorer.vfs.webdav.AbstractNetworkPlaceMount;
import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException;
import com.sslexplorer.vfs.webdav.DAVBundleActionMessageException;
import com.sslexplorer.vfs.webdav.DAVException;
import com.sslexplorer.vfs.webdav.DAVResource;
import com.sslexplorer.vfs.webdav.DAVServlet;
import com.sslexplorer.vfs.webdav.DAVUtilities;
import com.sslexplorer.vfs.webdav.FileObjectDAVResource;

/**
 * <p>
 * This class performs the operations on the file system accessed through a
 * {@link com.sslexplorer.vfs.NetworkPlace}.
 * <p>
 * This action <b>must</b> use request scope as there may be many instances in
 * one users session.
 * 
 * @author James D Robinson <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 * 
 */
public class FileSystemViewDispatchAction extends AbstractPopupAuthenticatedDispatchAction {

    final static Log log = LogFactory.getLog(FileSystemViewDispatchAction.class);

    final static List NO_DELETE = new ArrayList();
    final static List READ_ONLY = new ArrayList();

    static {
        // This is a holder for the actions which are not allowed for a given
        // parameter.
        NO_DELETE.add("delete");
        NO_DELETE.add("deleteFile");

        READ_ONLY.add("delete");
        READ_ONLY.add("deleteFile");
        READ_ONLY.add("cut");
        READ_ONLY.add("cutFile");
        READ_ONLY.add("copy");
        READ_ONLY.add("copyFile");
        READ_ONLY.add("paste");
        READ_ONLY.add("pasteFile");
        READ_ONLY.add("showMkDir");
        READ_ONLY.add("upload");
    }

    /**
     * Constructor
     */
    public FileSystemViewDispatchAction() {
        super(null, null, PolicyConstants.NETWORK_PLACE_RESOURCE_TYPE);
    }

    /*
     * } else if (request.getParameter("actionTarget").equals("mkdir")) { if
     * (this.getNewFolder() == null || this.getNewFolder().equals("")) {
     * msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.mkdir.error")); return
     * msgs; } } else } }
     */

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        try {
            ActionForward fwd = super.execute(mapping, form, request, response);
            Util.noCache(response);
            return fwd;
        } catch (DAVAuthenticationRequiredException dare) {
            // Response will have already been set
            return null;
        } catch (PopupException pe) {
            if (pe.getCause() instanceof DAVBundleActionMessageException) {
                ActionMessages errs = getErrors(request);
                errs.add(Globals.ERROR_KEY, ((DAVBundleActionMessageException) pe.getCause()).getBundleActionMessage());
                saveErrors(request, errs);
                return mapping.getInputForward();
            }
            throw pe;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                     HttpServletResponse response) throws Exception {
        return super.unspecified(mapping, form, request, response);
    }

    /**
     * <p>
     * Return the file system to the home of the <@link
     * com.sslexplorer.vfs.NetworkPlace>.
     * 
     * @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 an exception is thrown.
     */
    public ActionForward home(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("List files.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        DAVResource res = getResourceForPath(request, response, fileSystemForm);
        return new ActionForward(mapping.getPath() + ".do?actionTarget=list&path=" + res.getMount().getMountString(), true);
    }

    /**
     * <p>
     * Return the file system to the location specified.
     * 
     * @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 gotoPath(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("goto path location.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        fileSystemForm.clearPathsTo(request.getParameter("id"));
        return this.list(mapping, fileSystemForm, request, response);
    }

    /**
     * <p>
     * Rename 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 renameFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("rename the file.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;

        getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        DAVResource sourceResource = DAVServlet.getDAVResource(request, response, fileSystemForm.getPath() + "/"
                        + fileSystemForm.getFileName());
        DAVResource destResource = DAVServlet.getDAVResource(request, response, fileSystemForm.getPath() + "/"
                        + fileSystemForm.getNewName());
        try {
            if (sourceResource == null) {
                throw new Exception("Could not locate source resource '" + fileSystemForm.getPath() + "/"
                                + fileSystemForm.getFileName() + "'");
            }
            if (destResource == null) {
                throw new Exception("Could not locate destination resource '" + fileSystemForm.getPath() + "/"
                                + fileSystemForm.getNewName() + "'");
            }
            sourceResource.move(destResource, true);

        } catch (Exception e) {
        }

        return mapping.findForward("list");
    }

    /**
     * <p>
     * Upload a file to the file system.
     * 
     * @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 upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (log.isDebugEnabled())
            log.debug("List files.");
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        UploadDetails details = new UploadDetails(DAVUploadHandler.TYPE_DAV, fileSystemForm.getPath(), mapping
                        .findForward("upload"), new ActionForward("/fileSystem.do?actionTarget=list&path="
                        + Util.urlEncode(fileSystemForm.getPath()), true), null);
        details.setExtraAttribute1(fileSystemForm.getPath());
        request.setAttribute(Constants.REQ_ATTR_UPLOAD_DETAILS, new Integer(CoreUtil.addUpload(request.getSession(), details)));
        return mapping.findForward("upload");
    }

    /**
     * Refilter.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward filter(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        return list(mapping, form, request, response);
    }

    /**
     * List.
     * 
     * @param mapping mapping

⌨️ 快捷键说明

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