1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.io.StringReader ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.apache.log4j.Logger; 33 import org.apache.xerces.parsers.DOMParser; 34 import org.dom4j.Element; 35 import org.exolab.castor.jdo.Database; 36 import org.exolab.castor.jdo.OQLQuery; 37 import org.exolab.castor.jdo.QueryResults; 38 import org.infoglue.cms.applications.common.VisualFormatter; 39 import org.infoglue.cms.entities.content.Content; 40 import org.infoglue.cms.entities.content.DigitalAsset; 41 import org.infoglue.cms.entities.kernel.BaseEntityVO; 42 import org.infoglue.cms.entities.management.ContentTypeDefinition; 43 import org.infoglue.cms.entities.management.GroupContentTypeDefinition; 44 import org.infoglue.cms.entities.management.GroupProperties; 45 import org.infoglue.cms.entities.management.GroupPropertiesVO; 46 import org.infoglue.cms.entities.management.Language; 47 import org.infoglue.cms.entities.management.PropertiesCategory; 48 import org.infoglue.cms.entities.management.PropertiesCategoryVO; 49 import org.infoglue.cms.entities.management.impl.simple.GroupContentTypeDefinitionImpl; 50 import org.infoglue.cms.entities.management.impl.simple.GroupPropertiesImpl; 51 import org.infoglue.cms.entities.management.impl.simple.LanguageImpl; 52 import org.infoglue.cms.entities.structure.SiteNode; 53 import org.infoglue.cms.exception.Bug; 54 import org.infoglue.cms.exception.ConstraintException; 55 import org.infoglue.cms.exception.SystemException; 56 import org.infoglue.cms.util.ConstraintExceptionBuffer; 57 import org.infoglue.cms.util.dom.DOMBuilder; 58 import org.infoglue.deliver.util.CacheController; 59 import org.w3c.dom.CDATASection ; 60 import org.w3c.dom.Document ; 61 import org.w3c.dom.Node ; 62 import org.w3c.dom.NodeList ; 63 import org.xml.sax.InputSource ; 64 65 68 69 public class GroupPropertiesController extends BaseController 70 { 71 private final static Logger logger = Logger.getLogger(GroupPropertiesController.class.getName()); 72 73 76 77 public static GroupPropertiesController getController() 78 { 79 return new GroupPropertiesController(); 80 } 81 82 83 public GroupProperties getGroupPropertiesWithId(Integer groupPropertiesId, Database db) throws SystemException, Bug 84 { 85 return (GroupProperties) getObjectWithId(GroupPropertiesImpl.class, groupPropertiesId, db); 86 } 87 88 public GroupPropertiesVO getGroupPropertiesVOWithId(Integer groupPropertiesId) throws SystemException, Bug 89 { 90 return (GroupPropertiesVO) getVOWithId(GroupPropertiesImpl.class, groupPropertiesId); 91 } 92 93 public List getGroupPropertiesVOList() throws SystemException, Bug 94 { 95 return getAllVOObjects(GroupPropertiesImpl.class, "groupPropertiesId"); 96 } 97 98 99 102 103 public GroupPropertiesVO create(Integer languageId, Integer contentTypeDefinitionId, GroupPropertiesVO groupPropertiesVO) throws ConstraintException, SystemException 104 { 105 Database db = CastorDatabaseService.getDatabase(); 106 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 107 108 GroupProperties groupProperties = null; 109 110 beginTransaction(db); 111 try 112 { 113 groupProperties = create(languageId, contentTypeDefinitionId, groupPropertiesVO, db); 114 commitTransaction(db); 115 } 116 catch(Exception e) 117 { 118 logger.error("An error occurred so we should not completes the transaction:" + e, e); 119 rollbackTransaction(db); 120 throw new SystemException(e.getMessage()); 121 } 122 123 return groupProperties.getValueObject(); 124 } 125 126 130 131 public GroupProperties create(Integer languageId, Integer contentTypeDefinitionId, GroupPropertiesVO groupPropertiesVO, Database db) throws ConstraintException, SystemException, Exception 132 { 133 Language language = LanguageController.getController().getLanguageWithId(languageId, db); 134 ContentTypeDefinition contentTypeDefinition = ContentTypeDefinitionController.getController().getContentTypeDefinitionWithId(contentTypeDefinitionId, db); 135 136 GroupProperties groupProperties = new GroupPropertiesImpl(); 137 groupProperties.setLanguage((LanguageImpl)language); 138 groupProperties.setContentTypeDefinition((ContentTypeDefinition)contentTypeDefinition); 139 140 groupProperties.setValueObject(groupPropertiesVO); 141 db.create(groupProperties); 142 143 return groupProperties; 144 } 145 146 149 150 public GroupPropertiesVO update(Integer languageId, Integer contentTypeDefinitionId, GroupPropertiesVO groupPropertiesVO) throws ConstraintException, SystemException 151 { 152 GroupPropertiesVO realGroupPropertiesVO = groupPropertiesVO; 153 154 if(groupPropertiesVO.getId() == null) 155 { 156 logger.info("Creating the entity because there was no version at all for: " + contentTypeDefinitionId + " " + languageId); 157 realGroupPropertiesVO = create(languageId, contentTypeDefinitionId, groupPropertiesVO); 158 } 159 160 return (GroupPropertiesVO) updateEntity(GroupPropertiesImpl.class, (BaseEntityVO) realGroupPropertiesVO); 161 } 162 163 public GroupPropertiesVO update(GroupPropertiesVO groupPropertiesVO, String [] extranetUsers) throws ConstraintException, SystemException 164 { 165 Database db = CastorDatabaseService.getDatabase(); 166 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 167 168 GroupProperties groupProperties = null; 169 170 beginTransaction(db); 171 172 try 173 { 174 groupProperties = getGroupPropertiesWithId(groupPropertiesVO.getGroupPropertiesId(), db); 176 groupProperties.setValueObject(groupPropertiesVO); 177 178 ceb.throwIfNotEmpty(); 180 181 commitTransaction(db); 182 } 183 catch(ConstraintException ce) 184 { 185 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 186 rollbackTransaction(db); 187 throw ce; 188 } 189 catch(Exception e) 190 { 191 logger.error("An error occurred so we should not complete the transaction:" + e, e); 192 rollbackTransaction(db); 193 throw new SystemException(e.getMessage()); 194 } 195 196 return groupProperties.getValueObject(); 197 } 198 199 200 204 205 public List getGroupPropertiesVOList(String groupName, Integer languageId) throws ConstraintException, SystemException 206 { 207 List groupPropertiesVOList = new ArrayList (); 208 209 Database db = CastorDatabaseService.getDatabase(); 210 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 211 212 beginTransaction(db); 213 214 try 215 { 216 groupPropertiesVOList = getGroupPropertiesVOList(groupName, languageId, db); 217 218 commitTransaction(db); 219 } 220 catch(Exception e) 221 { 222 logger.error("An error occurred so we should not complete the transaction:" + e, e); 223 rollbackTransaction(db); 224 throw new SystemException(e.getMessage()); 225 } 226 227 return groupPropertiesVOList; 228 } 229 230 231 235 236 public List getGroupPropertiesVOList(String groupName, Integer languageId, Database db) throws ConstraintException, Exception 237 { 238 List groupPropertiesVOList = new ArrayList (); 239 240 String cacheKey = "" + groupName + "_" + languageId; 241 logger.info("cacheKey:" + cacheKey); 242 groupPropertiesVOList = (List )CacheController.getCachedObject("groupPropertiesCache", cacheKey); 243 if(groupPropertiesVOList != null) 244 { 245 logger.info("There was an cached groupPropertiesVOList:" + groupPropertiesVOList.size()); 246 } 247 else 248 { 249 List groupPropertiesList = getGroupPropertiesList(groupName, languageId, db, true); 250 if(groupPropertiesList != null) 251 { 252 groupPropertiesVOList = toVOList(groupPropertiesList); 253 CacheController.cacheObject("groupPropertiesCache", cacheKey, groupPropertiesVOList); 254 } 255 256 } 257 258 return groupPropertiesVOList; 259 } 260 261 265 266 public List getGroupPropertiesList(String groupName, Integer languageId, Database db, boolean readOnly) throws ConstraintException, SystemException, Exception 267 { 268 List groupPropertiesList = new ArrayList (); 269 270 OQLQuery oql = db.getOQLQuery("SELECT f FROM org.infoglue.cms.entities.management.impl.simple.GroupPropertiesImpl f WHERE f.groupName = $1 AND f.language = $2"); 271 oql.bind(groupName); 272 oql.bind(languageId); 273 274 QueryResults results; 275 if(readOnly) 276 { 277 results = oql.execute(Database.ReadOnly); 278 } 279 else 280 { 281 this.logger.info("Fetching groupPropertiesList in read/write mode"); 282 results = oql.execute(); 283 } 284 285 while (results.hasMore()) 286 { 287 GroupProperties groupProperties = (GroupProperties)results.next(); 288 groupPropertiesList.add(groupProperties); 289 } 290 291 results.close(); 292 oql.close(); 293 294 return groupPropertiesList; 295 } 296 297 public void delete(GroupPropertiesVO groupPropertiesVO) throws ConstraintException, SystemException 298 { 299 deleteEntity(GroupPropertiesImpl.class, groupPropertiesVO.getGroupPropertiesId()); 300 } 301 302 303 306 307 public List getDigitalAssetVOList(Integer groupPropertiesId) throws SystemException, Bug 308 { 309 Database db = CastorDatabaseService.getDatabase(); 310 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 311 312 List digitalAssetVOList = new ArrayList (); 313 314 beginTransaction(db); 315 316 try 317 { 318 GroupProperties groupProperties = GroupPropertiesController.getController().getGroupPropertiesWithId(groupPropertiesId, db); 319 if(groupProperties != null) 320 { 321 Collection digitalAssets = groupProperties.getDigitalAssets(); 322 digitalAssetVOList = toVOList(digitalAssets); 323 } 324 325 commitTransaction(db); 326 } 327 catch(Exception e) 328 { 329 logger.info("An error occurred when we tried to fetch the list of digitalAssets belonging to this groupProperties:" + e); 330 e.printStackTrace(); 331 rollbackTransaction(db); 332 throw new SystemException(e.getMessage()); 333 } 334 335 return digitalAssetVOList; 336 } 337 338 339 342 public void deleteDigitalAssetRelation(Integer groupPropertiesId, DigitalAsset digitalAsset, Database db) throws SystemException, Bug 343 { 344 GroupProperties groupProperties = getGroupPropertiesWithId(groupPropertiesId, db); 345 groupProperties.getDigitalAssets().remove(digitalAsset); 346 digitalAsset.getGroupProperties().remove(groupProperties); 347 } 348 349 350 353 354 public List getContentTypeDefinitionVOList(String groupName) throws ConstraintException, SystemException 355 { 356 Database db = CastorDatabaseService.getDatabase(); 357 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 358 359 List contentTypeDefinitionVOList = new ArrayList (); 360 361 beginTransaction(db); 362 363 try 364 { 365 List groupContentTypeDefinitionList = getGroupContentTypeDefinitionList(groupName, db); 366 Iterator contentTypeDefinitionsIterator = groupContentTypeDefinitionList.iterator(); 367 while(contentTypeDefinitionsIterator.hasNext()) 368 { 369 GroupContentTypeDefinition groupContentTypeDefinition = (GroupContentTypeDefinition)contentTypeDefinitionsIterator.next(); 370 contentTypeDefinitionVOList.add(groupContentTypeDefinition.getContentTypeDefinition().getValueObject()); 371 } 372 373 ceb.throwIfNotEmpty(); 374 375 commitTransaction(db); 376 } 377 catch(ConstraintException ce) 378 { 379 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 380 rollbackTransaction(db); 381 throw ce; 382 } 383 catch(Exception e) 384 { 385 logger.error("An error occurred so we should not complete the transaction:" + e, e); 386 rollbackTransaction(db); 387 throw new SystemException(e.getMessage()); 388 } 389 390 return contentTypeDefinitionVOList; 391 } 392 393 396 397 public List getGroupContentTypeDefinitionList(String groupName, Database db) throws ConstraintException, SystemException, Exception 398 { 399 List groupContentTypeDefinitionList = new ArrayList (); 400 401 OQLQuery oql = db.getOQLQuery("SELECT f FROM org.infoglue.cms.entities.management.impl.simple.GroupContentTypeDefinitionImpl f WHERE f.groupName = $1"); 402 oql.bind(groupName); 403 404 QueryResults results = oql.execute(); 405 this.logger.info("Fetching groupContentTypeDefinitionList in read/write mode"); 406 407 while (results.hasMore()) 408 { 409 GroupContentTypeDefinition groupContentTypeDefinition = (GroupContentTypeDefinition)results.next(); 410 groupContentTypeDefinitionList.add(groupContentTypeDefinition); 411 } 412 413 results.close(); 414 oql.close(); 415 416 return groupContentTypeDefinitionList; 417 } 418 419 422 423 public void updateContentTypeDefinitions(String groupName, String [] contentTypeDefinitionIds) throws ConstraintException, SystemException 424 { 425 Database db = CastorDatabaseService.getDatabase(); 426 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 427 428 List contentTypeDefinitionVOList = new ArrayList (); 429 430 beginTransaction(db); 431 432 try 433 { 434 List groupContentTypeDefinitionList = this.getGroupContentTypeDefinitionList(groupName, db); 435 Iterator contentTypeDefinitionsIterator = groupContentTypeDefinitionList.iterator(); 436 while(contentTypeDefinitionsIterator.hasNext()) 437 { 438 GroupContentTypeDefinition groupContentTypeDefinition = (GroupContentTypeDefinition)contentTypeDefinitionsIterator.next(); 439 db.remove(groupContentTypeDefinition); 440 } 441 442 for(int i=0; i<contentTypeDefinitionIds.length; i++) 443 { 444 Integer contentTypeDefinitionId = new Integer (contentTypeDefinitionIds[i]); 445 ContentTypeDefinition contentTypeDefinition = ContentTypeDefinitionController.getController().getContentTypeDefinitionWithId(contentTypeDefinitionId, db); 446 GroupContentTypeDefinitionImpl groupContentTypeDefinitionImpl = new GroupContentTypeDefinitionImpl(); 447 groupContentTypeDefinitionImpl.setGroupName(groupName); 448 groupContentTypeDefinitionImpl.setContentTypeDefinition(contentTypeDefinition); 449 db.create(groupContentTypeDefinitionImpl); 450 } 451 452 ceb.throwIfNotEmpty(); 453 454 commitTransaction(db); 455 } 456 catch(ConstraintException ce) 457 { 458 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 459 rollbackTransaction(db); 460 throw ce; 461 } 462 catch(Exception e) 463 { 464 logger.error("An error occurred so we should not complete the transaction:" + e, e); 465 rollbackTransaction(db); 466 throw new SystemException(e.getMessage()); 467 } 468 } 469 470 471 475 476 public void updateAttributeValue(Integer groupPropertiesId, String attributeName, String attributeValue) throws SystemException, Bug 477 { 478 GroupPropertiesVO groupPropertiesVO = getGroupPropertiesVOWithId(groupPropertiesId); 479 480 if(groupPropertiesVO != null) 481 { 482 try 483 { 484 logger.info("attributeName:" + attributeName); 485 logger.info("versionValue:" + groupPropertiesVO.getValue()); 486 logger.info("attributeValue:" + attributeValue); 487 InputSource inputSource = new InputSource (new StringReader (groupPropertiesVO.getValue())); 488 489 DOMParser parser = new DOMParser(); 490 parser.parse(inputSource); 491 Document document = parser.getDocument(); 492 493 NodeList nl = document.getDocumentElement().getChildNodes(); 494 Node attributesNode = nl.item(0); 495 496 boolean existed = false; 497 nl = attributesNode.getChildNodes(); 498 for(int i=0; i<nl.getLength(); i++) 499 { 500 Node n = nl.item(i); 501 if(n.getNodeName().equalsIgnoreCase(attributeName)) 502 { 503 if(n.getFirstChild() != null && n.getFirstChild().getNodeValue() != null) 504 { 505 n.getFirstChild().setNodeValue(attributeValue); 506 existed = true; 507 break; 508 } 509 else 510 { 511 CDATASection cdata = document.createCDATASection(attributeValue); 512 n.appendChild(cdata); 513 existed = true; 514 break; 515 } 516 } 517 } 518 519 if(existed == false) 520 { 521 org.w3c.dom.Element attributeElement = document.createElement(attributeName); 522 attributesNode.appendChild(attributeElement); 523 CDATASection cdata = document.createCDATASection(attributeValue); 524 attributeElement.appendChild(cdata); 525 } 526 527 StringBuffer sb = new StringBuffer (); 528 org.infoglue.cms.util.XMLHelper.serializeDom(document.getDocumentElement(), sb); 529 logger.info("sb:" + sb); 530 groupPropertiesVO.setValue(sb.toString()); 531 update(groupPropertiesVO.getLanguageId(), groupPropertiesVO.getContentTypeDefinitionId(), groupPropertiesVO); 532 } 533 catch(Exception e) 534 { 535 e.printStackTrace(); 536 } 537 } 538 } 539 540 541 544 545 public String getAttributeValue(String groupName, Integer languageId, String attributeName) throws SystemException 546 { 547 String value = ""; 548 549 Database db = CastorDatabaseService.getDatabase(); 550 551 beginTransaction(db); 552 553 try 554 { 555 value = getAttributeValue(groupName, languageId, attributeName, db); 556 557 commitTransaction(db); 558 } 559 catch(Exception e) 560 { 561 logger.error("An error occurred so we should not complete the transaction:" + e, e); 562 rollbackTransaction(db); 563 throw new SystemException(e.getMessage()); 564 } 565 566 return value; 567 } 568 569 570 573 574 public String getAttributeValue(String groupName, Integer languageId, String attributeName, Database db) throws SystemException, Exception 575 { 576 String value = ""; 577 578 List groupPropertiesVO = this.getGroupPropertiesVOList(groupName, languageId, db); 579 Iterator iterator = groupPropertiesVO.iterator(); 580 GroupPropertiesVO groupPropertyVO = null; 581 while(iterator.hasNext()) 582 { 583 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 584 break; 585 } 586 587 if(groupPropertyVO != null) 588 { 589 value = this.getAttributeValue(groupPropertyVO.getValue(), attributeName, false); 590 } 591 592 return value; 593 } 594 595 598 599 public String getAttributeValue(Integer groupPropertiesId, String attributeName, boolean escapeHTML) throws SystemException, Bug 600 { 601 String value = ""; 602 603 GroupPropertiesVO groupPropertiesVO = getGroupPropertiesVOWithId(groupPropertiesId); 604 605 if(groupPropertiesVO != null) 606 { 607 value = getAttributeValue(groupPropertiesVO.getValue(), attributeName, escapeHTML); 608 } 609 610 return value; 611 } 612 613 614 617 618 public String getAttributeValue(String xml, String attributeName, boolean escapeHTML) throws SystemException, Bug 619 { 620 String value = ""; 621 622 try 623 { 624 InputSource inputSource = new InputSource (new StringReader (xml)); 625 626 DOMParser parser = new DOMParser(); 627 parser.parse(inputSource); 628 Document document = parser.getDocument(); 629 630 NodeList nl = document.getDocumentElement().getChildNodes(); 631 Node n = nl.item(0); 632 633 nl = n.getChildNodes(); 634 for(int i=0; i<nl.getLength(); i++) 635 { 636 n = nl.item(i); 637 if(n.getNodeName().equalsIgnoreCase(attributeName)) 638 { 639 if(n.getFirstChild() != null && n.getFirstChild().getNodeValue() != null) 640 { 641 value = n.getFirstChild().getNodeValue(); 642 if(value != null && escapeHTML) 643 value = new VisualFormatter().escapeHTML(value); 644 645 break; 646 } 647 } 648 } 649 } 650 catch(Exception e) 651 { 652 e.printStackTrace(); 653 } 654 655 return value; 656 } 657 658 659 664 665 public List getRelatedContents(String groupName, Integer languageId, String attributeName) throws SystemException 666 { 667 Database db = CastorDatabaseService.getDatabase(); 668 669 List relatedContentVOList = new ArrayList (); 670 671 beginTransaction(db); 672 673 try 674 { 675 List relatedContents = getRelatedContents(groupName, languageId, attributeName, db); 676 if(relatedContents != null) 677 relatedContentVOList = toVOList(relatedContents); 678 679 commitTransaction(db); 680 } 681 catch(Exception e) 682 { 683 logger.error("An error occurred so we should not complete the transaction:" + e, e); 684 rollbackTransaction(db); 685 throw new SystemException(e.getMessage()); 686 } 687 688 return relatedContentVOList; 689 } 690 691 696 697 public List getReadOnlyRelatedContents(String groupName, Integer languageId, String attributeName, Database db) throws SystemException, Exception 698 { 699 List relatedContentList = new ArrayList (); 700 701 List groupPropertiesVO = this.getGroupPropertiesVOList(groupName, languageId, db); 702 Iterator iterator = groupPropertiesVO.iterator(); 703 GroupPropertiesVO groupPropertyVO = null; 704 while(iterator.hasNext()) 705 { 706 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 707 break; 708 } 709 710 if(groupPropertyVO != null) 711 { 712 String xml = this.getAttributeValue(groupPropertyVO.getValue(), attributeName, false); 713 relatedContentList = this.getReadOnlyRelatedContentsFromXML(db, xml); 714 } 715 716 return relatedContentList; 717 } 718 719 724 725 public List getRelatedContents(String groupName, Integer languageId, String attributeName, Database db) throws SystemException, Exception 726 { 727 List relatedContentList = new ArrayList (); 728 729 List groupPropertiesVO = this.getGroupPropertiesVOList(groupName, languageId, db); 730 Iterator iterator = groupPropertiesVO.iterator(); 731 GroupPropertiesVO groupPropertyVO = null; 732 while(iterator.hasNext()) 733 { 734 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 735 break; 736 } 737 738 if(groupPropertyVO != null) 739 { 740 String xml = this.getAttributeValue(groupPropertyVO.getValue(), attributeName, false); 741 relatedContentList = this.getRelatedContentsFromXML(db, xml); 742 } 743 744 return relatedContentList; 745 } 746 747 752 753 public List getRelatedSiteNodes(String groupName, Integer languageId, String attributeName) throws SystemException 754 { 755 Database db = CastorDatabaseService.getDatabase(); 756 757 List relatedSiteNodeVOList = new ArrayList (); 758 759 beginTransaction(db); 760 761 try 762 { 763 List relatedSiteNodes = getRelatedSiteNodes(groupName, languageId, attributeName, db); 764 if(relatedSiteNodes != null) 765 relatedSiteNodeVOList = toVOList(relatedSiteNodes); 766 767 commitTransaction(db); 768 } 769 catch(Exception e) 770 { 771 logger.error("An error occurred so we should not complete the transaction:" + e, e); 772 rollbackTransaction(db); 773 throw new SystemException(e.getMessage()); 774 } 775 776 return relatedSiteNodeVOList; 777 } 778 779 780 785 786 public List getRelatedSiteNodes(String groupName, Integer languageId, String attributeName, Database db) throws SystemException, Exception 787 { 788 List relatedSiteNodeList = new ArrayList (); 789 790 List groupProperties = this.getGroupPropertiesVOList(groupName, languageId, db); 791 Iterator iterator = groupProperties.iterator(); 792 GroupPropertiesVO groupPropertyVO = null; 793 while(iterator.hasNext()) 794 { 795 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 796 break; 797 } 798 799 if(groupPropertyVO != null) 800 { 801 String xml = this.getAttributeValue(groupPropertyVO.getValue(), attributeName, false); 802 relatedSiteNodeList = this.getRelatedSiteNodesFromXML(db, xml); 803 } 804 805 return relatedSiteNodeList; 806 } 807 808 813 814 public List getReadOnlyRelatedSiteNodes(String groupName, Integer languageId, String attributeName, Database db) throws SystemException, Exception 815 { 816 List relatedSiteNodeList = new ArrayList (); 817 818 List groupProperties = this.getGroupPropertiesVOList(groupName, languageId, db); 819 Iterator iterator = groupProperties.iterator(); 820 GroupPropertiesVO groupPropertyVO = null; 821 while(iterator.hasNext()) 822 { 823 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 824 break; 825 } 826 827 if(groupPropertyVO != null) 828 { 829 String xml = this.getAttributeValue(groupPropertyVO.getValue(), attributeName, false); 830 relatedSiteNodeList = this.getReadOnlyRelatedSiteNodesFromXML(db, xml); 831 } 832 833 return relatedSiteNodeList; 834 } 835 836 841 842 private List getRelatedContentsFromXML(Database db, String qualifyerXML) 843 { 844 List contents = new ArrayList (); 845 846 if(qualifyerXML == null || qualifyerXML.length() == 0) 847 return contents; 848 849 try 850 { 851 org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML); 852 853 String entity = document.getRootElement().attributeValue("entity"); 854 855 List children = document.getRootElement().elements(); 856 Iterator i = children.iterator(); 857 while(i.hasNext()) 858 { 859 Element child = (Element)i.next(); 860 String id = child.getStringValue(); 861 862 Content content = ContentController.getContentController().getContentWithId(new Integer (id), db); 863 contents.add(content); 864 } 865 } 866 catch(Exception e) 867 { 868 e.printStackTrace(); 869 } 870 871 return contents; 872 } 873 874 875 880 881 private List getReadOnlyRelatedContentsFromXML(Database db, String qualifyerXML) 882 { 883 List contents = new ArrayList (); 884 885 if(qualifyerXML == null || qualifyerXML.length() == 0) 886 return contents; 887 888 try 889 { 890 org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML); 891 892 String entity = document.getRootElement().attributeValue("entity"); 893 894 List children = document.getRootElement().elements(); 895 Iterator i = children.iterator(); 896 while(i.hasNext()) 897 { 898 Element child = (Element)i.next(); 899 String id = child.getStringValue(); 900 901 Content content = ContentController.getContentController().getReadOnlyContentWithId(new Integer (id), db); 902 contents.add(content); 903 } 904 } 905 catch(Exception e) 906 { 907 e.printStackTrace(); 908 } 909 910 return contents; 911 } 912 913 918 919 private List getRelatedSiteNodesFromXML(Database db, String qualifyerXML) 920 { 921 List siteNodes = new ArrayList (); 922 923 if(qualifyerXML == null || qualifyerXML.length() == 0) 924 return siteNodes; 925 926 try 927 { 928 org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML); 929 930 String entity = document.getRootElement().attributeValue("entity"); 931 932 List children = document.getRootElement().elements(); 933 Iterator i = children.iterator(); 934 while(i.hasNext()) 935 { 936 Element child = (Element)i.next(); 937 String id = child.getStringValue(); 938 939 SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(new Integer (id), db); 940 siteNodes.add(siteNode); 941 } 942 } 943 catch(Exception e) 944 { 945 e.printStackTrace(); 946 } 947 948 return siteNodes; 949 } 950 951 956 957 private List getReadOnlyRelatedSiteNodesFromXML(Database db, String qualifyerXML) 958 { 959 List siteNodes = new ArrayList (); 960 961 if(qualifyerXML == null || qualifyerXML.length() == 0) 962 return siteNodes; 963 964 try 965 { 966 org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML); 967 968 String entity = document.getRootElement().attributeValue("entity"); 969 970 List children = document.getRootElement().elements(); 971 Iterator i = children.iterator(); 972 while(i.hasNext()) 973 { 974 Element child = (Element)i.next(); 975 String id = child.getStringValue(); 976 977 SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(new Integer (id), db, true); 978 siteNodes.add(siteNode); 979 } 980 } 981 catch(Exception e) 982 { 983 e.printStackTrace(); 984 } 985 986 return siteNodes; 987 } 988 989 994 995 public List getRelatedCategories(String groupName, Integer languageId, String attribute) 996 { 997 List relatedCategories = new ArrayList (); 998 999 try 1000 { 1001 List groupPropertiesVOList = this.getGroupPropertiesVOList(groupName, languageId); 1002 Iterator iterator = groupPropertiesVOList.iterator(); 1003 GroupPropertiesVO groupPropertyVO = null; 1004 while(iterator.hasNext()) 1005 { 1006 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 1007 break; 1008 } 1009 1010 if(groupPropertyVO != null && groupPropertyVO.getId() != null) 1011 { 1012 List propertiesCategoryVOList = PropertiesCategoryController.getController().findByPropertiesAttribute(attribute, GroupProperties.class.getName(), groupPropertyVO.getId()); 1013 Iterator propertiesCategoryVOListIterator = propertiesCategoryVOList.iterator(); 1014 while(propertiesCategoryVOListIterator.hasNext()) 1015 { 1016 PropertiesCategoryVO propertiesCategoryVO = (PropertiesCategoryVO)propertiesCategoryVOListIterator.next(); 1017 relatedCategories.add(propertiesCategoryVO.getCategory()); 1018 } 1019 } 1020 } 1021 catch(Exception e) 1022 { 1023 logger.warn("We could not fetch the list of defined category keys: " + e.getMessage(), e); 1024 } 1025 1026 return relatedCategories; 1027 } 1028 1029 1030 1035 1036 public List getRelatedCategoriesVOList(String groupName, Integer languageId, String attribute, Database db) throws SystemException, Exception 1037 { 1038 List relatedCategoriesVOList = new ArrayList (); 1039 1040 1041 String cacheKey = "" + groupName + "_" + languageId + "_" + attribute; 1042 logger.info("cacheKey:" + cacheKey); 1043 relatedCategoriesVOList = (List )CacheController.getCachedObject("relatedCategoriesCache", cacheKey); 1044 if(relatedCategoriesVOList != null) 1045 { 1046 logger.info("There was an cached groupPropertiesVOList:" + relatedCategoriesVOList.size()); 1047 } 1048 else 1049 { 1050 List relatedCategories = getRelatedCategories(groupName, languageId, attribute, db); 1051 if(relatedCategories != null) 1052 { 1053 relatedCategoriesVOList = toVOList(relatedCategories); 1054 CacheController.cacheObject("relatedCategoriesCache", cacheKey, relatedCategoriesVOList); 1055 } 1056 } 1057 1058 return relatedCategoriesVOList; 1059 } 1060 1061 1066 1067 public List getRelatedCategories(String groupName, Integer languageId, String attribute, Database db) 1068 { 1069 List relatedCategories = new ArrayList (); 1070 1071 try 1072 { 1073 List groupPropertiesVOList = this.getGroupPropertiesVOList(groupName, languageId, db); 1074 Iterator iterator = groupPropertiesVOList.iterator(); 1075 GroupPropertiesVO groupPropertyVO = null; 1076 while(iterator.hasNext()) 1077 { 1078 groupPropertyVO = (GroupPropertiesVO)iterator.next(); 1079 break; 1080 } 1081 1082 if(groupPropertyVO != null && groupPropertyVO.getId() != null) 1083 { 1084 List propertiesCategoryList = PropertiesCategoryController.getController().findByPropertiesAttribute(attribute, GroupProperties.class.getName(), groupPropertyVO.getId(), db); 1085 1086 Iterator propertiesCategoryListIterator = propertiesCategoryList.iterator(); 1087 while(propertiesCategoryListIterator.hasNext()) 1088 { 1089 PropertiesCategory propertiesCategory = (PropertiesCategory)propertiesCategoryListIterator.next(); 1090 relatedCategories.add(propertiesCategory.getCategory()); 1091 } 1092 } 1093 } 1094 catch(Exception e) 1095 { 1096 logger.warn("We could not fetch the list of defined category keys: " + e.getMessage(), e); 1097 } 1098 1099 return relatedCategories; 1100 } 1101 1102 1106 1107 public BaseEntityVO getNewVO() 1108 { 1109 return new GroupPropertiesVO(); 1110 } 1111 1112} 1113 | Popular Tags |