1 24 package org.riotfamily.riot.editor.ui; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.riotfamily.common.i18n.MessageResolver; 30 import org.riotfamily.common.util.ResourceUtils; 31 import org.riotfamily.riot.editor.EditorConstants; 32 import org.riotfamily.riot.editor.EditorDefinition; 33 import org.riotfamily.riot.editor.EditorRepository; 34 import org.springframework.context.MessageSource; 35 import org.springframework.context.MessageSourceAware; 36 import org.springframework.web.servlet.ModelAndView; 37 import org.springframework.web.servlet.mvc.Controller; 38 import org.springframework.web.servlet.support.RequestContextUtils; 39 40 43 public class PathController implements Controller, MessageSourceAware { 44 45 private EditorRepository repository; 46 47 private MessageSource messageSource; 48 49 private String viewName = ResourceUtils.getPath( 50 PathController.class, "PathView.ftl"); 51 52 private String modelKey = "path"; 53 54 public PathController(EditorRepository repository) { 55 this.repository = repository; 56 } 57 58 public void setMessageSource(MessageSource messageSource) { 59 this.messageSource = messageSource; 60 } 61 62 public String getModelKey() { 63 return modelKey; 64 } 65 66 public void setModelKey(String modelKey) { 67 this.modelKey = modelKey; 68 } 69 70 public String getViewName() { 71 return viewName; 72 } 73 74 public void setViewName(String viewName) { 75 this.viewName = viewName; 76 } 77 78 public EditorRepository getRepository() { 79 return repository; 80 } 81 82 84 public ModelAndView handleRequest(HttpServletRequest request, 85 HttpServletResponse response) throws Exception { 86 87 EditorPath path; 88 String editorId = request.getParameter(EditorConstants.EDITOR_ID); 89 90 EditorDefinition editor = repository.getEditorDefinition(editorId); 91 92 String objectId = request.getParameter(EditorConstants.OBJECT_ID); 93 String parentId = request.getParameter(EditorConstants.PARENT_ID); 94 95 EditorReference lastComponent = createLastPathComponent( 96 editor, objectId, parentId, 97 new MessageResolver(messageSource, 98 repository.getMessageCodesResolver(), 99 RequestContextUtils.getLocale(request))); 100 101 path = new EditorPath(editorId, objectId, parentId, 102 lastComponent); 103 104 path.setSubPage(request.getParameter("subPage")); 105 path.encodeUrls(response); 106 107 return new ModelAndView(viewName, modelKey, path); 108 } 109 110 protected EditorReference createLastPathComponent( 111 final EditorDefinition editor, final String objectId, 112 final String parentId, final MessageResolver messageResolver) { 113 114 return editor.createEditorPath(objectId, parentId, messageResolver); 115 } 116 } 117 | Popular Tags |