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:
043: import java.net.URI;
044:
045: import javax.servlet.http.HttpServletRequest;
046: import javax.servlet.http.HttpServletResponse;
047:
048: public class EditMenuController implements Controller {
049: public Object process(URI uri, HttpServletRequest request,
050: HttpServletResponse response) throws Exception {
051: if (request.getParameter("cancel") != null) {
052: return uri;
053: }
054:
055: KernelService kernelService = (KernelService) Libresource
056: .getService(KernelConstants.SERVICE);
057:
058: if (!kernelService.checkSecurity(uri,
059: KernelConstants.SECURITY_UPDATE)) {
060: throw new LibresourceSecurityException(uri,
061: KernelConstants.SECURITY_UPDATE);
062: }
063:
064: URI menuUri = kernelService.getNodeDefiningProperty(uri,
065: "libresource-web.menu");
066: boolean inherit = true;
067:
068: if (menuUri != null) {
069: if (normalizePath(uri.getPath()).equals(
070: normalizePath(menuUri.getPath()))) {
071: inherit = false;
072: request.setAttribute("simpleEdit", new Boolean(true));
073: }
074: }
075:
076: if (request.getParameter("menuContent") == null) {
077: request.setAttribute("menuContent", kernelService
078: .getProperty(uri, "libresource-web.menu", true));
079: request.setAttribute("menuUri", menuUri);
080:
081: return "/pages/editMenu.jsp";
082: }
083:
084: if (inherit) {
085: if (request.getParameter("editType").equals("simpleEdit")) {
086: kernelService.setProperty(menuUri,
087: "libresource-web.menu", request
088: .getParameter("menuContent"));
089: } else if (request.getParameter("editType").equals(
090: "createEdit")) {
091: kernelService.setProperty(uri, "libresource-web.menu",
092: request.getParameter("menuContent"));
093: }
094: } else {
095: if ("deleteEdit".equals(request.getParameter("editType"))) {
096: kernelService.setProperty(uri, "libresource-web.menu",
097: null);
098: } else {
099: kernelService.setProperty(uri, "libresource-web.menu",
100: request.getParameter("menuContent"));
101: }
102: }
103:
104: return uri;
105: }
106:
107: private String normalizePath(String path) {
108: if (!path.startsWith("/")) {
109: path = "/" + path;
110: }
111:
112: if (path.endsWith("/")) {
113: path = path.substring(0, path.length() - 1);
114: }
115:
116: if (path.equals("")) {
117: return "/";
118: }
119:
120: return path;
121: }
122: }
|