KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
46  *
47  */

48 public class EditorGroupController implements Controller, MessageSourceAware {
49
50     private EditorRepository editorRepository;
51
52     private MessageSource messageSource;
53
54     private String JavaDoc modelKey = "group";
55
56
57     private String JavaDoc 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 JavaDoc request,
69             HttpServletResponse JavaDoc response) throws Exception JavaDoc {
70
71         String JavaDoc editorId = (String JavaDoc) 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 JavaDoc 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