Package maqetta.core.server.command

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

package maqetta.core.server.command;

import java.io.IOException;

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

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

public class CreateResource extends Command {

    @Override
    public void handleCommand(HttpServletRequest req, HttpServletResponse resp, IUser user) throws IOException {
      // SECURITY, VALIDATION
      //   'path': checked by User.createResource()
      //   'isFolder': validated by Boolean.parseBoolean()

        String path = req.getParameter("path");
        boolean isFolder = Boolean.parseBoolean(req.getParameter("isFolder"));
        IVResource newFile = user.createResource(path,isFolder);
        if (newFile.exists()) {
            responseString = "EXISTS";
        } else if (isFolder) {
            if (newFile.mkdir()) {
                responseString = "OK";
            } else {
              throw new IOException("Failed to create folder. path:" + path);
            }
        } else {
            newFile.createNewInstance();
           
            /* HACK: this fixes a bug that if a user creates a new / empty resource, then closes it the files working copy isn't removed in windows with the file.delete() call.
             * it seems if you open an IO stream to the resource (without writing anything) then close and flush the stream the problem goes away.
             */
            responseString = "OK";
        }
    }
}
TOP

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

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.