package pt.ist.bennu.manager.presentation.actions; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import pt.ist.bennu.core.domain.RoleType; import pt.ist.bennu.core.domain.User; import pt.ist.bennu.core.domain.contents.FunctionalityKey; import pt.ist.bennu.core.domain.contents.Node; import pt.ist.bennu.core.domain.contents.NodeContainer; import pt.ist.bennu.core.domain.groups.EmptyGroup; import pt.ist.bennu.core.presentation.actions.ContextBaseAction; import pt.ist.bennu.core.security.UserView; import pt.ist.renderers.utils.RenderUtils; import pt.ist.struts.dispatch.annotation.Mapping; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import com.google.common.collect.Table; @Mapping(path = "/menuConfiguration") public class MenuConfigurationAction extends ContextBaseAction { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final User user = UserView.getUser(); if (user == null || !user.hasRoleType(RoleType.MANAGER)) { throw new Error("unauthorized.access"); } return super.execute(mapping, form, request, response); } protected ActionForward manageMenus(final NodeContainer parent, final HttpServletRequest request) { request.setAttribute("parent", parent); return forward(request, "/bennu-manager/manageMenus.jsp"); } /** * Entry point class expecting parentId as the externalId of either the * virtualHost or the parent node. */ public ActionForward manageMenus(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { NodeContainer parent = getDomainObject(request, "parentId"); return manageMenus(parent, request); } public final ActionForward addContent(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { NodeContainer parent = getDomainObject(request, "parentId"); request.setAttribute("parent", parent); Table functionalityTable = FunctionalityKey.entries(); request.setAttribute("functionalities", functionalityTable); return forward(request, "/bennu-manager/newContent.jsp"); } public final ActionForward addFunctionality(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws UnsupportedEncodingException { NodeContainer parent = getDomainObject(request, "parentId"); String tag = getAttribute(request, "functionality"); FunctionalityKey functionalityKey = FunctionalityKey.internalize(URLDecoder.decode(tag, "UTF-8")); Node.create(parent, functionalityKey, EmptyGroup.getInstance()); return manageMenus(parent, request); } public ActionForward prepareEditNode(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final Node node = getDomainObject(request, "nodeId"); request.setAttribute("node", new NodeBean(node)); return forward(request, "/bennu-manager/editNode.jsp"); } public ActionForward customizeNode(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final Node node = getDomainObject(request, "nodeId"); request.setAttribute("node", new NodeBean(node, true)); return forward(request, "/bennu-manager/editNode.jsp"); } public ActionForward editNode(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { NodeBean node = RenderUtils.getRenderedObject("node"); node.save(); return manageMenus(node.getNode().getParent(), request); } public ActionForward deleteNode(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final Node node = getDomainObject(request, "nodeId"); Node parent = node.getParentNode(); node.delete(); return manageMenus(parent, request); } }