1 24 package org.riotfamily.components; 25 26 import java.io.IOException ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 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 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 [] initialComponentTypes; 65 66 private Integer minComponents; 67 68 private Integer maxComponents; 69 70 private ComponentRepository componentRepository; 71 72 private String [] 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 [] getInitialComponentTypes() { 97 return this.initialComponentTypes; 98 } 99 100 public void setInitialComponentTypes(String [] initialComponentTypes) { 101 this.initialComponentTypes = initialComponentTypes; 102 } 103 104 public Integer getMinComponents() { 105 return this.minComponents; 106 } 107 108 public void setMinComponents(Integer minComponents) { 109 this.minComponents = minComponents; 110 } 111 112 public Integer getMaxComponents() { 113 return this.maxComponents; 114 } 115 116 public void setMaxComponents(Integer maxComponents) { 117 this.maxComponents = maxComponents; 118 } 119 120 public String [] getValidComponentTypes() { 121 return this.validComponentTypes; 122 } 123 124 public void setValidComponentTypes(String [] 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 request, 145 HttpServletResponse response) throws Exception { 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 e) { 166 throw new RuntimeException (e); 167 } 168 } 169 }); 170 171 return null; 172 } 173 174 175 176 } 177 | Popular Tags |