/**
* LibreSource
* Copyright (C) 2004-2008 Artenum SARL / INRIA
* http://www.libresource.org - contact@artenum.com
*
* This file is part of the LibreSource software,
* which can be used and distributed under license conditions.
* The license conditions are provided in the LICENSE.TXT file
* at the root path of the packaging that enclose this file.
* More information can be found at
* - http://dev.libresource.org/home/license
*
* Initial authors :
*
* Guillaume Bort / INRIA
* Francois Charoy / Universite Nancy 2
* Julien Forest / Artenum
* Claude Godart / Universite Henry Poincare
* Florent Jouille / INRIA
* Sebastien Jourdain / INRIA / Artenum
* Yves Lerumeur / Artenum
* Pascal Molli / Universite Henry Poincare
* Gerald Oster / INRIA
* Mariarosa Penzi / Artenum
* Gerard Sookahet / Artenum
* Raphael Tani / INRIA
*
* Contributors :
*
* Stephane Bagnier / Artenum
* Amadou Dia / Artenum-IUP Blois
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package org.libresource.web.controllers;
import org.libresource.Libresource;
import org.libresource.kernel.KernelConstants;
import org.libresource.kernel.LibresourceSecurityException;
import org.libresource.kernel.interfaces.KernelService;
import org.libresource.web.Controller;
import org.libresource.web.config.Config;
import java.net.URI;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CreateChildController implements Controller {
public Object process(URI uri, HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (request.getParameter("cancel") != null) {
return uri;
}
KernelService kernelService = (KernelService) Libresource.getService(KernelConstants.SERVICE);
if (!kernelService.checkSecurity(uri, KernelConstants.SECURITY_CREATE)) {
throw new LibresourceSecurityException(uri, KernelConstants.SECURITY_CREATE);
}
String node = request.getParameter("node");
String type = request.getParameter("type");
//
if (node == null) {
request.setAttribute("types", Config.getInstance(null).listResourceTypeForCreation());
return "/pages/createChild.jsp";
}
if (type == null) {
request.setAttribute("types", Config.getInstance(null).listResourceTypeForCreation());
request.setAttribute("node", node);
request.setAttribute("creationError", "Please choose a resource type !");
return "/pages/createChild.jsp";
}
if (node.trim().length() == 0) {
request.setAttribute("types", Config.getInstance(null).listResourceTypeForCreation());
request.setAttribute("choosenType", type);
request.setAttribute("creationError", "Please choose a name for the new node !");
return "/pages/createChild.jsp";
}
if (!node.matches("[A-Za-z0-9-_/]+")) {
request.setAttribute("types", Config.getInstance(null).listResourceTypeForCreation());
request.setAttribute("choosenType", type);
request.setAttribute("creationError", "The URI contains forbidden character(s) !");
return "/pages/createChild.jsp";
}
// create
Controller controller = Config.getInstance(null).getCreateController(type);
URI uriToCreate = new URI(uri.getPath() + "/" + node);
kernelService.createURI(uriToCreate);
Object forward = controller.process(uriToCreate, request, response);
if (forward instanceof String) {
return forward.toString() + "?action=edit";
} else if (forward instanceof URI) {
return ((URI) forward).getPath() + "?action=edit";
}
return uriToCreate;
}
}
|