1 13 22 23 27 28 package org.jahia.services.containers; 29 30 import org.jahia.data.containers.JahiaContainer; 31 import org.jahia.data.containers.JahiaContainerList; 32 import org.jahia.exceptions.JahiaException; 33 34 import java.util.Enumeration ; 35 import java.util.Vector ; 36 37 38 public class JahiaContainersLogic { 39 40 private static org.apache.log4j.Logger logger = 41 org.apache.log4j.Logger.getLogger (JahiaContainersLogic.class); 42 43 44 47 public JahiaContainersLogic () { 48 } 49 50 51 58 public void logic_sort_container_tree (Vector theTree) 59 throws JahiaException { 60 for (int i = 0; i < theTree.size (); i++) { 62 JahiaContainerList theList = (JahiaContainerList) theTree.elementAt (i); 63 if (theList.getParentEntryID () != 0) { 64 if (logic_add_container_list_to_container (theList, theList.getParentEntryID (), 65 theTree)) { 66 theTree.removeElementAt (i); 67 i--; 68 } 69 } 70 } 71 } 72 73 74 83 private boolean logic_add_container_list_to_container ( 84 JahiaContainerList theContainerList, 85 int thectnid, 86 Vector theTree) 87 throws JahiaException { 88 JahiaContainer theContainer = logic_find_container_in_list (thectnid, 89 theTree.elements ()); 90 if (theContainer != null) { 91 if (theContainerList == null) { 92 logger.error ("Hey, the container list is null !!"); 93 } 94 theContainer.addContainerList (theContainerList); 95 return true; 96 } else { 97 String errorMsg = "Error in container structure : container " + thectnid + " is referrenced"; 98 errorMsg += " by list " + theContainerList.getID () + ", but does not exist."; 99 logger.error (errorMsg); 100 return false; 101 } 102 } 103 104 105 110 private JahiaContainer logic_find_container_in_list (int thectnid, 111 Enumeration containerLists) { 112 while (containerLists.hasMoreElements ()) { 113 JahiaContainerList theContainerList = (JahiaContainerList) containerLists.nextElement (); 114 Enumeration containers = theContainerList.getContainers (); 115 while (containers.hasMoreElements ()) { 116 JahiaContainer theContainer = (JahiaContainer) containers.nextElement (); 117 if (theContainer.getID () != thectnid) { 118 Enumeration listInContainer = theContainer.getContainerLists (); 119 while (listInContainer.hasMoreElements ()) { 120 JahiaContainer tmpContainer = logic_find_container_in_list (thectnid, 121 listInContainer); 122 if (tmpContainer != null) { 123 return tmpContainer; 124 } 125 } 126 } else { 127 return theContainer; 128 } 129 } 130 } 131 return null; 132 } 133 134 } 135 | Popular Tags |