001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.kernel.KernelConstants;
038: import org.libresource.kernel.LibresourceSecurityException;
039: import org.libresource.kernel.interfaces.KernelService;
040:
041: import org.libresource.web.Controller;
042: import org.libresource.web.config.Config;
043:
044: import java.net.URI;
045:
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048:
049: public class CreateChildController implements Controller {
050: public Object process(URI uri, HttpServletRequest request,
051: HttpServletResponse response) throws Exception {
052: if (request.getParameter("cancel") != null) {
053: return uri;
054: }
055:
056: KernelService kernelService = (KernelService) Libresource
057: .getService(KernelConstants.SERVICE);
058:
059: if (!kernelService.checkSecurity(uri,
060: KernelConstants.SECURITY_CREATE)) {
061: throw new LibresourceSecurityException(uri,
062: KernelConstants.SECURITY_CREATE);
063: }
064:
065: String node = request.getParameter("node");
066: String type = request.getParameter("type");
067:
068: //
069: if (node == null) {
070: request.setAttribute("types", Config.getInstance(null)
071: .listResourceTypeForCreation());
072:
073: return "/pages/createChild.jsp";
074: }
075:
076: if (type == null) {
077: request.setAttribute("types", Config.getInstance(null)
078: .listResourceTypeForCreation());
079: request.setAttribute("node", node);
080:
081: request.setAttribute("creationError",
082: "Please choose a resource type !");
083:
084: return "/pages/createChild.jsp";
085: }
086:
087: if (node.trim().length() == 0) {
088: request.setAttribute("types", Config.getInstance(null)
089: .listResourceTypeForCreation());
090: request.setAttribute("choosenType", type);
091:
092: request.setAttribute("creationError",
093: "Please choose a name for the new node !");
094:
095: return "/pages/createChild.jsp";
096: }
097:
098: if (!node.matches("[A-Za-z0-9-_/]+")) {
099: request.setAttribute("types", Config.getInstance(null)
100: .listResourceTypeForCreation());
101: request.setAttribute("choosenType", type);
102:
103: request.setAttribute("creationError",
104: "The URI contains forbidden character(s) !");
105:
106: return "/pages/createChild.jsp";
107: }
108:
109: // create
110: Controller controller = Config.getInstance(null)
111: .getCreateController(type);
112: URI uriToCreate = new URI(uri.getPath() + "/" + node);
113: kernelService.createURI(uriToCreate);
114:
115: Object forward = controller.process(uriToCreate, request,
116: response);
117:
118: if (forward instanceof String) {
119: return forward.toString() + "?action=edit";
120: } else if (forward instanceof URI) {
121: return ((URI) forward).getPath() + "?action=edit";
122: }
123:
124: return uriToCreate;
125: }
126: }
|