1 24 package org.riotfamily.riot.editor.ui; 25 26 import java.util.Iterator ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.riotfamily.common.i18n.MessageResolver; 32 import org.riotfamily.common.util.ResourceUtils; 33 import org.riotfamily.riot.editor.EditorConstants; 34 import org.riotfamily.riot.editor.EditorDefinition; 35 import org.riotfamily.riot.editor.EditorRepository; 36 import org.riotfamily.riot.editor.GroupDefinition; 37 import org.riotfamily.riot.security.AccessController; 38 import org.springframework.context.MessageSource; 39 import org.springframework.context.MessageSourceAware; 40 import org.springframework.util.Assert; 41 import org.springframework.web.servlet.ModelAndView; 42 import org.springframework.web.servlet.mvc.Controller; 43 import org.springframework.web.servlet.support.RequestContextUtils; 44 45 48 public class EditorGroupController implements Controller, MessageSourceAware { 49 50 private EditorRepository editorRepository; 51 52 private MessageSource messageSource; 53 54 private String modelKey = "group"; 55 56 57 private String viewName = ResourceUtils.getPath( 58 EditorGroupController.class, "EditorGroupView.ftl"); 59 60 public EditorGroupController(EditorRepository editorRepository) { 61 this.editorRepository = editorRepository; 62 } 63 64 public void setMessageSource(MessageSource messageSource) { 65 this.messageSource = messageSource; 66 } 67 68 public ModelAndView handleRequest(HttpServletRequest request, 69 HttpServletResponse response) throws Exception { 70 71 String editorId = (String ) request.getAttribute(EditorConstants.EDITOR_ID); 72 73 GroupDefinition groupDefinition = 74 editorRepository.getGroupDefinition(editorId); 75 76 Assert.notNull(groupDefinition, "No such group: " + editorId); 77 78 if (!AccessController.isGranted("use-editor", groupDefinition)) { 79 response.sendError(HttpServletResponse.SC_FORBIDDEN); 80 } 81 82 MessageResolver messageResolver = new MessageResolver(messageSource, 83 editorRepository.getMessageCodesResolver(), 84 RequestContextUtils.getLocale(request)); 85 86 EditorGroup group = new EditorGroup(); 87 group.setId(groupDefinition.getId()); 88 group.setTitle(groupDefinition.createReference(null, messageResolver).getLabel()); 89 90 Iterator ed = groupDefinition.getEditorDefinitions().iterator(); 91 while (ed.hasNext()) { 92 EditorDefinition editor = (EditorDefinition) ed.next(); 93 if (!editor.isHidden() && AccessController.isGranted("use-editor", editor)) { 94 group.addReference(editor.createReference(null, messageResolver)); 95 } 96 } 97 98 return new ModelAndView(viewName, modelKey, group); 99 } 100 101 } 102 | Popular Tags |