1 package org.jahia.data.beans; 2 3 import java.util.ArrayList ; 4 import java.util.Enumeration ; 5 import java.util.Iterator ; 6 import java.util.Map ; 7 import java.util.Properties ; 8 9 import org.jahia.data.containers.JahiaContainer; 10 import org.jahia.data.containers.JahiaContainerDefinition; 11 import org.jahia.data.containers.JahiaContainerList; 12 import org.jahia.data.containers.JahiaContainerListPagination; 13 import org.jahia.data.fields.LoadFlags; 14 import org.jahia.exceptions.JahiaException; 15 import org.jahia.gui.GuiBean; 16 import org.jahia.gui.HTMLToolBox; 17 import org.jahia.params.ParamBean; 18 import org.jahia.registries.ServicesRegistry; 19 import org.jahia.services.acl.JahiaBaseACL; 20 import org.jahia.services.containers.ContainerFactory; 21 import org.jahia.services.containers.ContentContainerList; 22 import org.jahia.services.lock.LockKey; 23 import org.jahia.services.lock.LockService; 24 import org.jahia.utils.InsertionSortedMap; 25 import org.jahia.content.JahiaObject; 26 import org.jahia.services.pages.ContentPage; 27 import org.jahia.services.pages.JahiaPage; 28 29 39 40 public class ContainerListBean extends ContentBean { 41 42 private static org.apache.log4j.Logger logger = 43 org.apache.log4j.Logger.getLogger(ContainerListBean.class); 44 45 private JahiaContainerList jahiaContainerList; 46 private ParamBean paramBean; 47 private ArrayList containers = null; 48 private ContainerBean parentContainerBean = null; 49 private Map actionURIs = null; 50 private boolean completelyLocked = false; 51 52 public ContainerListBean() { 53 } 54 55 static { 56 registerType(ContentContainerList.class.getName(), ContainerListBean.class.getName()); 57 } 58 59 public ContainerListBean(JahiaContainerList jahiaContainerList, ParamBean paramBean) { 60 this.jahiaContainerList = jahiaContainerList; 61 this.paramBean = paramBean; 62 } 63 64 public static AbstractJahiaObjectBean getChildInstance (JahiaObject 65 jahiaObject, 66 ParamBean paramBean) { 67 ContentContainerList contentContainerList = (ContentContainerList) jahiaObject; 68 try { 69 return new ContainerListBean(contentContainerList.getJahiaContainerList( 70 paramBean, paramBean.getEntryLoadRequest()), paramBean); 71 } catch (JahiaException je) { 72 logger.error("Error while converting content container to jahia container", je); 73 return null; 74 } 75 } 76 77 public int getId() { 78 return jahiaContainerList.getID(); 79 } 80 81 public JahiaContainerList getJahiaContainerList() { 82 return jahiaContainerList; 83 } 84 85 public int getFullSize() { 86 return jahiaContainerList.getFullSize(); 87 } 88 89 public int getSize() { 90 return jahiaContainerList.size(); 91 } 92 93 public ArrayList getContainerBeans() { 94 if (containers != null) { 95 return containers; 96 } 97 Enumeration containerEnum = jahiaContainerList.getContainers(); 98 containers = new ArrayList (); 99 while (containerEnum.hasMoreElements()) { 100 JahiaContainer jahiaContainer = (JahiaContainer) containerEnum.nextElement(); 101 ContainerBean containerBean = new ContainerBean(jahiaContainer, paramBean); 102 containers.add(containerBean); 103 } 104 return containers; 105 } 106 107 public ArrayList getContainers() { 108 return getContainerBeans(); 109 } 110 111 public ContainerBean getContainerByID(int containerID) { 112 ArrayList containers = getContainers(); 113 Iterator containerIter = containers.iterator(); 114 while (containerIter.hasNext()) { 115 ContainerBean curContainerBean = (ContainerBean) containerIter.next(); 116 if (curContainerBean.getId() == containerID) { 117 return curContainerBean; 118 } 119 } 120 return null; 121 } 122 123 public JahiaContainerListPagination getJahiaContainerListPagination() { 124 return jahiaContainerList.getCtnListPagination(); 125 } 126 127 public boolean isContainersLoaded() { 128 return jahiaContainerList.isContainersLoaded(); 129 } 130 131 public int getPageID() { 132 return jahiaContainerList.getPageID(); 133 } 134 135 public JahiaContainerDefinition getDefinition() { 136 try { 137 return jahiaContainerList.getDefinition(); 138 } catch (JahiaException je) { 139 logger.error("Error retrieving container list definition ", je); 140 return null; 141 } 142 } 143 144 public String getName() { 145 try { 146 return jahiaContainerList.getDefinition().getName(); 147 } catch (JahiaException je) { 148 logger.error("Error retrieving container list definition ", je); 149 return null; 150 } 151 } 152 153 public String getTitle() { 154 try { 155 return jahiaContainerList.getDefinition().getTitle(paramBean.getPage().getPageTemplateID(), paramBean.getLocale()); 156 } catch (JahiaException je) { 157 logger.error("Error retrieving field definition for field " + getId() + ":", je); 158 return null; 159 } 160 } 161 162 public int getParentContainerID () { 163 return jahiaContainerList.getParentEntryID(); 164 } 165 166 public ContentBean getParent() { 167 int parentContainerID = jahiaContainerList.getParentEntryID(); 168 if (parentContainerID == 0) { 169 170 try { 172 ContentPage parentContentPage = ContentPage.getPage( 173 jahiaContainerList.getPageID()); 174 JahiaPage parentJahiaPage = parentContentPage.getPage(paramBean); 175 PageBean parentPageBean = new PageBean(parentJahiaPage, paramBean); 176 return parentPageBean; 177 } catch (JahiaException je) { 178 logger.error("Error while loading parent page " + 179 jahiaContainerList.getPageID() + 180 " for container list " + jahiaContainerList.getID(), 181 je); 182 } 183 return null; 184 } 185 if (parentContainerBean != null) { 186 return parentContainerBean; 187 } 188 ContainerFactory containerFactory = ContainerFactory.getInstance(); 189 try { 190 JahiaContainer parentContainer = ServicesRegistry.getInstance(). 191 getJahiaContainersService().loadContainer( 192 parentContainerID,LoadFlags.ALL,paramBean,paramBean.getEntryLoadRequest()); 193 if (parentContainer == null) { 194 return null; 195 } 196 containerFactory.fullyLoadContainer(parentContainer, LoadFlags.ALL, 197 paramBean, 198 paramBean.getEntryLoadRequest(), null, null, null); 199 parentContainerBean = new ContainerBean (parentContainer, paramBean); 200 return parentContainerBean; 201 } catch (JahiaException je) { 202 logger.error("Error loading parent container for container list " + getId() + " : ", je); 203 return null; 204 } 205 206 } 207 208 public ContainerBean getParentContainer() { 209 int parentContainerID = jahiaContainerList.getParentEntryID(); 210 if (parentContainerID == 0) { 211 return null; 212 } 213 return (ContainerBean) getParent(); 214 } 215 216 public ContentContainerList getContentContainerList() { 217 return jahiaContainerList.getContentContainerList(); 218 } 219 220 public Properties getProperties() { 221 return jahiaContainerList.getProperties(); 222 } 223 224 public int getAclID() { 225 return jahiaContainerList.getAclID(); 226 } 227 228 public JahiaBaseACL getAcl() { 229 return jahiaContainerList.getACL(); 230 } 231 232 public int getContainerDefinitionID() { 233 return jahiaContainerList.getctndefid(); 234 } 235 236 public Map getActionURIBeans() { 237 if (actionURIs == null) { 238 buildActionURIs(); 239 } 240 return actionURIs; 241 } 242 243 public boolean isCompletelyLocked() { 244 if (actionURIs == null) { 245 buildActionURIs(); 246 } 247 return completelyLocked; 248 } 249 250 public boolean isPartiallyLocked() { 251 if (actionURIs == null) { 252 buildActionURIs(); 253 } 254 if (!completelyLocked) { 255 Iterator actionURIIter = actionURIs.entrySet().iterator(); 256 boolean partiallyLocked = false; 257 while (actionURIIter.hasNext()) { 258 Map.Entry curActionURIEntry = (Map.Entry ) actionURIIter.next(); 259 ActionURIBean curActionURIBean = (ActionURIBean) curActionURIEntry.getValue(); 260 if (curActionURIBean.isLocked()) { 261 partiallyLocked = true; 262 } 263 } 264 return partiallyLocked; 265 } else { 266 return false; 267 } 268 } 269 270 public boolean isActionURIsEmpty() { 271 if (!paramBean.getOperationMode().equals(ParamBean.EDIT)) { 272 return true; 273 } 274 if (actionURIs == null) { 275 buildActionURIs(); 276 } 277 return actionURIs.isEmpty(); 278 } 279 280 private void buildActionURIs() { 281 actionURIs = new InsertionSortedMap(); 282 GuiBean guiBean = new GuiBean(paramBean); 283 HTMLToolBox htmlToolBox = new HTMLToolBox(guiBean, paramBean); 284 completelyLocked = true; 285 try { 286 287 String curURL = guiBean.drawAddContainerUrl(jahiaContainerList); 288 String curLauncherURI = htmlToolBox.drawAddContainerLauncher(jahiaContainerList); 289 ActionURIBean curActionURIBean = new ActionURIBean("add", curURL, curLauncherURI); 290 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 291 LockKey lockKey = LockKey.composeLockKey(LockKey.ADD_CONTAINER_TYPE, jahiaContainerList.getID(), jahiaContainerList.getPageID()); 292 if (!lockRegistry.isAcquireable(lockKey, paramBean.getUser(), paramBean.getSessionID())) { 293 curActionURIBean.setLocked(true); 294 } else { 295 completelyLocked = false; 296 } 297 if (!lockRegistry.canRelease(lockKey, paramBean.getUser(), paramBean.getSessionID())) { 298 curActionURIBean.setReleaseable(true); 299 } 300 if ((curActionURIBean.getUri() != null) && (!"".equals(curActionURIBean.getUri()))) { 301 actionURIs.put(curActionURIBean.getName(), curActionURIBean); 302 } 303 if (jahiaContainerList.getID() != 0) { 304 curURL = guiBean.drawContainerListPropertiesUrl( 305 jahiaContainerList); 306 curLauncherURI = htmlToolBox. 307 drawContainerListPropertiesLauncher( 308 jahiaContainerList); 309 curActionURIBean = new ActionURIBean("update", curURL, 310 curLauncherURI); 311 lockKey = LockKey.composeLockKey(LockKey. 312 UPDATE_CONTAINERLIST_TYPE, 313 jahiaContainerList.getID(), jahiaContainerList.getPageID()); 314 if (!lockRegistry.isAcquireable(lockKey, paramBean.getUser(), 315 paramBean.getSessionID())) { 316 curActionURIBean.setLocked(true); 317 } else { 318 completelyLocked = false; 319 } 320 if (!lockRegistry.canRelease(lockKey, paramBean.getUser(), 321 paramBean.getSessionID())) { 322 curActionURIBean.setReleaseable(true); 323 } 324 if ( (curActionURIBean.getUri() != null) && 325 (!"".equals(curActionURIBean.getUri()))) { 326 actionURIs.put(curActionURIBean.getName(), curActionURIBean); 327 } 328 } 329 } catch (JahiaException je) { 330 logger.error("Error while retrieving action URI map for container list " + getId(), je); 331 } 332 } 333 } | Popular Tags |