KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > components > ComponentListController


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.components;
25
26 import java.io.IOException JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.riotfamily.cachius.Cache;
34 import org.riotfamily.components.config.ComponentListConfiguration;
35 import org.riotfamily.components.dao.ComponentDao;
36 import org.riotfamily.components.editor.EditModeUtils;
37 import org.riotfamily.components.render.EditModeRenderStrategy;
38 import org.riotfamily.components.render.LiveModeRenderStrategy;
39 import org.riotfamily.components.render.RenderStrategy;
40 import org.riotfamily.riot.security.AccessController;
41 import org.springframework.transaction.PlatformTransactionManager;
42 import org.springframework.transaction.TransactionStatus;
43 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
44 import org.springframework.transaction.support.TransactionTemplate;
45 import org.springframework.web.servlet.ModelAndView;
46 import org.springframework.web.servlet.mvc.Controller;
47
48 /**
49  * Controller that renders a ComponentList. Which list is to be rendered is
50  * determined using a {@link ComponentListLocator}.
51  */

52 public class ComponentListController implements Controller,
53         ComponentListConfiguration {
54
55     private static final Log log = LogFactory.getLog(
56             ComponentListController.class);
57
58     private Cache cache;
59
60     private ComponentDao componentDao;
61
62     private ComponentListLocator locator;
63
64     private String JavaDoc[] initialComponentTypes;
65
66     private Integer JavaDoc minComponents;
67
68     private Integer JavaDoc maxComponents;
69
70     private ComponentRepository componentRepository;
71
72     private String JavaDoc[] validComponentTypes;
73
74     private PlatformTransactionManager transactionManager;
75
76     public void setCache(Cache cache) {
77         this.cache = cache;
78     }
79
80     public Cache getCache() {
81         return this.cache;
82     }
83
84     public void setComponentDao(ComponentDao componentDao) {
85         this.componentDao = componentDao;
86     }
87
88     public ComponentDao getComponentDao() {
89         return this.componentDao;
90     }
91
92     public void setTransactionManager(PlatformTransactionManager transactionManager) {
93         this.transactionManager = transactionManager;
94     }
95
96     public String JavaDoc[] getInitialComponentTypes() {
97         return this.initialComponentTypes;
98     }
99
100     public void setInitialComponentTypes(String JavaDoc[] initialComponentTypes) {
101         this.initialComponentTypes = initialComponentTypes;
102     }
103
104     public Integer JavaDoc getMinComponents() {
105         return this.minComponents;
106     }
107
108     public void setMinComponents(Integer JavaDoc minComponents) {
109         this.minComponents = minComponents;
110     }
111
112     public Integer JavaDoc getMaxComponents() {
113         return this.maxComponents;
114     }
115
116     public void setMaxComponents(Integer JavaDoc maxComponents) {
117         this.maxComponents = maxComponents;
118     }
119
120     public String JavaDoc[] getValidComponentTypes() {
121         return this.validComponentTypes;
122     }
123
124     public void setValidComponentTypes(String JavaDoc[] validComponentTypes) {
125         this.validComponentTypes = validComponentTypes;
126     }
127
128     public void setComponentRepository(ComponentRepository repository) {
129         this.componentRepository = repository;
130     }
131
132     public ComponentRepository getComponentRepository() {
133         return this.componentRepository;
134     }
135
136     public ComponentListLocator getLocator() {
137         return this.locator;
138     }
139
140     public void setLocator(ComponentListLocator locator) {
141         this.locator = locator;
142     }
143
144     public ModelAndView handleRequest(HttpServletRequest JavaDoc request,
145             HttpServletResponse JavaDoc response) throws Exception JavaDoc {
146
147         final RenderStrategy strategy;
148         if (EditModeUtils.isEditMode(request) &&
149             AccessController.isGranted("edit", locator.getLocation(request))) {
150
151             log.debug("Authenticated user - rendering list in edit-mode");
152             strategy = new EditModeRenderStrategy(componentDao,
153                     componentRepository, this, request, response);
154         }
155         else {
156             strategy = new LiveModeRenderStrategy(componentDao, componentRepository,
157                     this, request, response, cache);
158         }
159
160         new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {
161             protected void doInTransactionWithoutResult(TransactionStatus status) {
162                 try {
163                     strategy.render();
164                 }
165                 catch (IOException JavaDoc e) {
166                     throw new RuntimeException JavaDoc(e);
167                 }
168             }
169         });
170
171         return null;
172     }
173
174
175
176 }
177
Popular Tags