KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > editor > ui > PathController


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.editor.ui;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
41  * Controller that displays a breadcrumb navigation for an editor.
42  */

43 public class PathController implements Controller, MessageSourceAware {
44
45     private EditorRepository repository;
46
47     private MessageSource messageSource;
48
49     private String JavaDoc viewName = ResourceUtils.getPath(
50             PathController.class, "PathView.ftl");
51
52     private String JavaDoc 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 JavaDoc getModelKey() {
63         return modelKey;
64     }
65
66     public void setModelKey(String JavaDoc modelKey) {
67         this.modelKey = modelKey;
68     }
69
70     public String JavaDoc getViewName() {
71         return viewName;
72     }
73
74     public void setViewName(String JavaDoc viewName) {
75         this.viewName = viewName;
76     }
77
78     public EditorRepository getRepository() {
79         return repository;
80     }
81
82     /**
83      */

84     public ModelAndView handleRequest(HttpServletRequest JavaDoc request,
85             HttpServletResponse JavaDoc response) throws Exception JavaDoc {
86
87         EditorPath path;
88         String JavaDoc editorId = request.getParameter(EditorConstants.EDITOR_ID);
89
90         EditorDefinition editor = repository.getEditorDefinition(editorId);
91
92         String JavaDoc objectId = request.getParameter(EditorConstants.OBJECT_ID);
93         String JavaDoc 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 JavaDoc objectId,
112             final String JavaDoc parentId, final MessageResolver messageResolver) {
113
114         return editor.createEditorPath(objectId, parentId, messageResolver);
115     }
116 }
117
Popular Tags