1 23 24 package org.apache.slide.search.basic; 25 26 import java.util.Enumeration ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 31 import org.apache.slide.common.SlideException; 32 import org.apache.slide.common.SlideToken; 33 import org.apache.slide.content.Content; 34 import org.apache.slide.search.BadQueryException; 35 import org.apache.slide.search.InvalidScopeException; 36 import org.apache.slide.search.PropertyProvider; 37 import org.apache.slide.search.QueryScope; 38 import org.apache.slide.search.SearchToken; 39 import org.apache.slide.search.SlideUri; 40 import org.apache.slide.structure.ObjectNode; 41 import org.apache.slide.structure.Structure; 42 import org.apache.slide.structure.StructureException; 43 44 50 public class ComparableResourcesPoolImpl implements ComparableResourcesPool { 51 52 53 private Structure structure; 54 private Content contentHelper; 55 private SlideToken slideToken; 56 private QueryScope scope; 57 private SearchToken searchToken; 58 59 private int scopeDepth; 60 private int maxSlideDepth; 61 private boolean partialResult = false; 62 private Set pool; 63 private SlideUri slideContext; 64 65 68 protected PropertyProvider propertyProvider = null; 69 70 80 public ComparableResourcesPoolImpl (SearchToken searchToken, 81 QueryScope scope, 82 PropertyProvider propertyProvider) 83 throws BadQueryException 84 { 85 this.structure = searchToken.getStructureHelper(); 86 this.slideToken = searchToken.getSlideToken(); 87 this.scope = scope; 88 this.propertyProvider = propertyProvider; 89 this.contentHelper = searchToken.getContentHelper(); 90 this.slideContext = searchToken.getSlideContext(); 91 this.searchToken = searchToken; 92 93 scopeDepth = scope.getDepth (); 94 maxSlideDepth = searchToken.getMaxDepth(); 95 96 createPool (); 97 } 98 99 105 public Iterator resourceIterator() { 106 return pool.iterator(); 107 } 108 109 110 116 public Set getPool() { 117 return pool; 118 } 119 120 121 127 private void createPool () throws BadQueryException { 128 pool = new HashSet (); 129 130 String resourceUri = searchToken.getSlideContext().getSlidePath (scope.getHref()); 131 132 ObjectNode resource = null; 134 135 try { 136 resource = structure.retrieve (slideToken, resourceUri); 137 parseOneObject (resource, 0); 138 } 139 catch (StructureException e) { 140 throw new InvalidScopeException 141 ("scope " + resourceUri + " is invalid"); 142 } 143 catch (Exception e) { 144 throw new BadQueryException (e.getMessage()); 145 } 146 } 147 148 158 private void parseOneObject (ObjectNode object, int currentDepth) 159 throws SlideException 160 { 161 if (currentDepth > scopeDepth) 162 return; 163 164 if (currentDepth > maxSlideDepth) { 165 partialResult = true; 166 return; 167 } 168 169 Enumeration children = null; 170 children = structure.getChildren (slideToken, object); 171 172 while (children.hasMoreElements()) { 173 ObjectNode cur = (ObjectNode)children.nextElement(); 174 parseOneObject (cur, currentDepth + 1); 175 } 176 177 ComparableResource item = 178 new ComparableResourceImpl (object, searchToken, scope, propertyProvider); 179 180 pool.add (item); 181 } 182 183 189 public boolean partialResult() { 190 return partialResult; 191 } 192 193 198 public QueryScope getScope() { 199 return scope; 200 } 201 202 } 203 | Popular Tags |