1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 import org.apache.log4j.Logger; 33 import org.exolab.castor.jdo.Database; 34 import org.infoglue.cms.applications.contenttool.wizards.actions.CreateContentWizardInfoBean; 35 import org.infoglue.cms.entities.content.ContentVO; 36 import org.infoglue.cms.exception.Bug; 37 import org.infoglue.cms.exception.ConstraintException; 38 import org.infoglue.cms.exception.SystemException; 39 import org.infoglue.cms.security.InfoGluePrincipal; 40 41 42 45 46 public class ContentControllerProxy extends ContentController 47 { 48 private final static Logger logger = Logger.getLogger(ContentControllerProxy.class.getName()); 49 50 protected static final Integer NO = new Integer (0); 51 protected static final Integer YES = new Integer (1); 52 protected static final Integer INHERITED = new Integer (2); 53 54 private static List interceptors = new ArrayList (); 55 56 public static ContentControllerProxy getController() 57 { 58 return new ContentControllerProxy(); 59 } 60 61 87 88 91 92 public ContentVO getACContentVOWithId(InfoGluePrincipal infogluePrincipal, Integer contentId, Database db) throws ConstraintException, SystemException, Bug, Exception 93 { 94 Map hashMap = new HashMap (); 95 hashMap.put("contentId", contentId); 96 97 intercept(hashMap, "Content.Read", infogluePrincipal); 98 99 return getSmallContentVOWithId(contentId, db); 100 } 101 102 105 106 public ContentVO getACContentVOWithId(InfoGluePrincipal infogluePrincipal, Integer contentId) throws ConstraintException, SystemException, Bug, Exception 107 { 108 Map hashMap = new HashMap (); 109 hashMap.put("contentId", contentId); 110 111 intercept(hashMap, "Content.Read", infogluePrincipal); 112 113 return getContentVOWithId(contentId); 114 } 115 116 119 120 public List getACContentVOList(InfoGluePrincipal infoGluePrincipal, HashMap argumentHashMap, Database db) throws SystemException, Bug 121 { 122 List contents = null; 123 124 String method = (String )argumentHashMap.get("method"); 125 logger.info("method:" + method); 126 127 if(method.equalsIgnoreCase("selectContentListOnIdList")) 128 { 129 contents = new ArrayList (); 130 List arguments = (List )argumentHashMap.get("arguments"); 131 logger.info("Arguments:" + arguments.size()); 132 Iterator argumentIterator = arguments.iterator(); 133 while(argumentIterator.hasNext()) 134 { 135 HashMap argument = (HashMap )argumentIterator.next(); 136 Integer contentId = new Integer ((String )argument.get("contentId")); 137 logger.info("Getting the content with Id:" + contentId); 138 try 139 { 140 contents.add(this.getACContentVOWithId(infoGluePrincipal, contentId, db)); 141 } 142 catch(Exception e) 143 { 144 e.printStackTrace(); 146 } 147 } 148 } 149 else if(method.equalsIgnoreCase("selectListOnContentTypeName")) 150 { 151 List arguments = (List )argumentHashMap.get("arguments"); 152 logger.info("Arguments:" + arguments.size()); 153 contents = getContentVOListByContentTypeNames(arguments); 154 Iterator contentIterator = contents.iterator(); 155 while(contentIterator.hasNext()) 156 { 157 ContentVO candidateContentVO = (ContentVO)contentIterator.next(); 158 159 Map hashMap = new HashMap (); 160 hashMap.put("contentId", candidateContentVO.getContentId()); 161 162 try 163 { 164 intercept(hashMap, "Content.Read", infoGluePrincipal); 165 } 166 catch(Exception e) 167 { 168 logger.info("Was not authorized to look at task..."); 169 contentIterator.remove(); 170 } 171 } 172 } 173 return contents; 174 } 175 176 177 180 181 public List getACContentVOList(InfoGluePrincipal infoGluePrincipal, HashMap argumentHashMap) throws SystemException, Bug 182 { 183 List contents = null; 184 185 String method = (String )argumentHashMap.get("method"); 186 logger.info("method:" + method); 187 188 if(method.equalsIgnoreCase("selectContentListOnIdList")) 189 { 190 contents = new ArrayList (); 191 List arguments = (List )argumentHashMap.get("arguments"); 192 logger.info("Arguments:" + arguments.size()); 193 Iterator argumentIterator = arguments.iterator(); 194 while(argumentIterator.hasNext()) 195 { 196 HashMap argument = (HashMap )argumentIterator.next(); 197 Integer contentId = new Integer ((String )argument.get("contentId")); 198 logger.info("Getting the content with Id:" + contentId); 199 try 200 { 201 contents.add(this.getACContentVOWithId(infoGluePrincipal, contentId)); 202 } 203 catch(Exception e) 204 { 205 e.printStackTrace(); 207 } 208 } 209 } 210 else if(method.equalsIgnoreCase("selectListOnContentTypeName")) 211 { 212 List arguments = (List )argumentHashMap.get("arguments"); 213 logger.info("Arguments:" + arguments.size()); 214 contents = getContentVOListByContentTypeNames(arguments); 215 Iterator contentIterator = contents.iterator(); 216 while(contentIterator.hasNext()) 217 { 218 ContentVO candidateContentVO = (ContentVO)contentIterator.next(); 219 220 Map hashMap = new HashMap (); 221 hashMap.put("contentId", candidateContentVO.getContentId()); 222 223 try 224 { 225 intercept(hashMap, "Content.Read", infoGluePrincipal); 226 } 227 catch(Exception e) 228 { 229 logger.info("Was not authorized to look at task..."); 230 contentIterator.remove(); 231 } 232 } 233 } 234 return contents; 235 } 236 237 240 241 public ContentVO acCreate(InfoGluePrincipal infogluePrincipal, CreateContentWizardInfoBean createContentWizardInfoBean) throws ConstraintException, SystemException, Bug, Exception 242 { 243 246 248 return ContentController.getContentController().create(createContentWizardInfoBean); 249 } 250 251 254 255 public ContentVO acCreate(InfoGluePrincipal infogluePrincipal, Integer parentContentId, Integer contentTypeDefinitionId, Integer repositoryId, ContentVO contentVO) throws ConstraintException, SystemException, Bug, Exception 256 { 257 Map hashMap = new HashMap (); 258 hashMap.put("contentId", parentContentId); 259 260 intercept(hashMap, "Content.Create", infogluePrincipal); 261 262 return ContentController.getContentController().create(parentContentId, contentTypeDefinitionId, repositoryId, contentVO); 263 } 264 265 268 269 public ContentVO acUpdate(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer contentTypeDefinitionId) throws ConstraintException, SystemException, Bug, Exception 270 { 271 Map hashMap = new HashMap (); 272 hashMap.put("contentId", contentVO.getId()); 273 274 intercept(hashMap, "Content.Write", infogluePrincipal); 275 276 return update(contentVO, contentTypeDefinitionId); 277 } 278 279 282 283 public void acDelete(InfoGluePrincipal infogluePrincipal, ContentVO contentVO) throws ConstraintException, SystemException, Bug, Exception 284 { 285 Map hashMap = new HashMap (); 286 hashMap.put("contentId", contentVO.getId()); 287 288 intercept(hashMap, "Content.Delete", infogluePrincipal); 289 290 delete(contentVO); 291 } 292 293 294 297 298 public void acMoveContent(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer newParentContentId) throws ConstraintException, SystemException, Bug, Exception 299 { 300 Map hashMap = new HashMap (); 301 hashMap.put("contentId", contentVO.getId()); 302 303 intercept(hashMap, "Content.Move", infogluePrincipal); 304 305 hashMap = new HashMap (); 306 hashMap.put("contentId", newParentContentId); 307 308 intercept(hashMap, "Content.Create", infogluePrincipal); 309 310 moveContent(contentVO, newParentContentId); 311 } 312 313 316 317 public void acMoveContent(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer newParentContentId, Database db) throws ConstraintException, SystemException, Bug, Exception 318 { 319 Map hashMap = new HashMap (); 320 hashMap.put("contentId", contentVO.getId()); 321 322 intercept(hashMap, "Content.Move", infogluePrincipal); 323 324 hashMap = new HashMap (); 325 hashMap.put("contentId", newParentContentId); 326 327 intercept(hashMap, "Content.Create", infogluePrincipal); 328 329 moveContent(contentVO, newParentContentId, db); 330 } 331 332 335 336 public Integer getProtectedContentId(Integer contentId) 337 { 338 Integer protectedContentId = null; 339 boolean isContentProtected = false; 340 341 try 342 { 343 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId); 344 if(contentVO.getIsProtected() != null) 345 { 346 if(contentVO.getIsProtected().intValue() == NO.intValue()) 347 protectedContentId = null; 348 else if(contentVO.getIsProtected().intValue() == YES.intValue()) 349 protectedContentId = contentVO.getId(); 350 else if(contentVO.getIsProtected().intValue() == INHERITED.intValue()) 351 { 352 ContentVO parentContentVO = ContentController.getParentContent(contentId); 353 if(parentContentVO != null) 354 protectedContentId = getProtectedContentId(parentContentVO.getId()); 355 } 356 } 357 } 358 catch(Exception e) 359 { 360 logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e); 361 } 362 363 return protectedContentId; 364 } 365 366 369 370 public boolean getIsContentProtected(Integer contentId) 371 { 372 boolean isContentProtected = false; 373 374 try 375 { 376 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId); 377 if(contentVO.getIsProtected() != null) 378 { 379 if(contentVO.getIsProtected().intValue() == NO.intValue()) 380 isContentProtected = false; 381 else if(contentVO.getIsProtected().intValue() == YES.intValue()) 382 isContentProtected = true; 383 else if(contentVO.getIsProtected().intValue() == INHERITED.intValue()) 384 { 385 ContentVO parentContentVO = ContentController.getParentContent(contentId); 386 if(parentContentVO != null) 387 isContentProtected = getIsContentProtected(parentContentVO.getId()); 388 } 389 } 390 391 } 392 catch(Exception e) 393 { 394 logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e); 395 } 396 397 return isContentProtected; 398 } 399 400 406 412 413 } 414 | Popular Tags |