1 13 package info.magnolia.cms.gui.controlx.search; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.ItemType; 17 import info.magnolia.cms.util.NodeDataUtil; 18 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 import java.util.SortedMap ; 22 import java.util.TreeMap ; 23 24 import javax.jcr.RepositoryException; 25 26 import org.slf4j.Logger; 27 import org.slf4j.LoggerFactory; 28 29 30 35 public class DialogBasedSearchConfig extends SearchConfigImpl { 36 37 Logger log = LoggerFactory.getLogger(DialogBasedSearchConfig.class); 38 39 42 public DialogBasedSearchConfig(Content dialogNode) { 43 try { 44 init(dialogNode); 45 } 46 catch (Exception e) { 47 log.error("can't configure the search", e); 48 } 49 } 50 51 55 protected void init(Content dialogNode) throws Exception { 56 SortedMap sortMap = new TreeMap (); 58 59 Collection tabNodes = dialogNode.getChildren(ItemType.CONTENTNODE); 61 62 for (Iterator iter = tabNodes.iterator(); iter.hasNext();) { 63 Content tabNode = (Content) iter.next(); 64 65 Collection controlNodes = tabNode.getChildren(); 66 67 for (Iterator iter2 = controlNodes.iterator(); iter2.hasNext();) { 68 Content controlNode = (Content) iter2.next(); 69 70 if (controlNode.hasNodeData("searchable")) { 71 String searchable = NodeDataUtil.getString(controlNode, "searchable"); 72 73 SearchControlDefinition def = createSearchControl(controlNode); 74 75 sortMap.put(searchable, def); 76 } 77 } 78 } 79 80 for (Iterator iter = sortMap.values().iterator(); iter.hasNext();) { 82 SearchControlDefinition def = (SearchControlDefinition) iter.next(); 83 this.addControlDefinition(def); 84 } 85 } 86 87 protected SearchControlDefinition createSearchControl(Content controlNode) throws Exception { 88 String type = controlNode.getNodeData("searchType").getString(); 89 String name = controlNode.getNodeData("name").getString(); 90 String label = controlNode.getNodeData("label").getString(); 91 92 if (type.equals("select")) { 93 SelectSearchControlDefinition select = new SelectSearchControlDefinition(name, label); 94 configureSelect(select, controlNode); 95 return select; 96 } 97 return new SearchControlDefinition(name, label, type); 98 } 99 100 public void configureSelect(SelectSearchControlDefinition def, Content node) throws RepositoryException { 101 Collection optionNodes = node.getContent("options").getChildren(); 102 103 for (Iterator iter = optionNodes.iterator(); iter.hasNext();) { 104 Content optionNode = (Content) iter.next(); 105 String value = optionNode.getNodeData("value").getString(); 106 String label = optionNode.getNodeData("value").getString(); 107 def.addOption(value, label); 108 } 109 } 110 111 } 112 | Popular Tags |