Package maqetta.core.server.command

Source Code of maqetta.core.server.command.Rename

package maqetta.core.server.command;

import java.io.IOException;

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

import maqetta.core.server.util.VResourceUtils;

import org.davinci.server.user.IUser;
import org.maqetta.server.Command;
import org.maqetta.server.IVResource;

public class Rename extends Command {

    public void handleCommand(HttpServletRequest req, HttpServletResponse resp, IUser user) throws IOException {
      // SECURITY, VALIDATION
      //   'oldName': checked by User.getResource()
      //   'newName': checked by User.createResource()

        String oldName = req.getParameter("oldName");
        String newName = req.getParameter("newName");

        IVResource source = user.getResource(oldName);
        IVResource newResource = user.createResource(newName, source.isDirectory());
        if (source.isDirectory()) {
            newResource.mkdir();
            VResourceUtils.copyDirectory(source, newResource, true);
        } else {
            VResourceUtils.copyFile(source, newResource);
        }
        source.delete();
        user.rebuildWorkspace();
        this.responseString = "OK";
    }

}
TOP

Related Classes of maqetta.core.server.command.Rename

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.