1 16 package org.jahia.services.search; 17 18 import java.util.ArrayList ; 19 import java.util.Enumeration ; 20 import java.util.List ; 21 import java.util.Locale ; 22 23 import org.jahia.data.search.JahiaSearchResult; 24 import org.jahia.exceptions.JahiaException; 25 import org.jahia.params.ParamBean; 26 import org.jahia.registries.ServicesRegistry; 27 import org.jahia.services.sites.JahiaSite; 28 import org.jahia.services.version.EntryLoadRequest; 29 30 31 38 39 public class ContainerSearcher extends JahiaSearcher { 40 41 private int ctnListID = 0; 42 43 private int siteId = -1; 44 45 private int[] siteIds = new int[]{}; 46 47 private String containerDefinitionName; 48 49 private boolean siteModeSearching = false; 50 51 private long lastSearchTime = -1; 52 53 private boolean updated = false; 54 55 private int containerLevel = 0; 56 57 private EntryLoadRequest loadRequest = EntryLoadRequest.CURRENT; 58 59 71 public ContainerSearcher (int aCtnListID, String query, EntryLoadRequest aLoadRequest) { 72 this.ctnListID = aCtnListID; 73 if (aLoadRequest != null) { 74 this.loadRequest = aLoadRequest; 75 } 76 setQuery(query); 77 } 78 79 91 public ContainerSearcher (int aCtnListID, int aContainerLevel, String query, 92 EntryLoadRequest aLoadRequest) { 93 this.ctnListID = aCtnListID; 94 this.containerLevel = aContainerLevel; 95 if (aLoadRequest != null) { 96 this.loadRequest = aLoadRequest; 97 } 98 setQuery(query); 99 } 100 101 112 public ContainerSearcher (String containerListName, ParamBean params, String query, 113 EntryLoadRequest aLoadRequest) 114 throws JahiaException { 115 if (containerListName != null) { 116 int clistID = ServicesRegistry.getInstance ().getJahiaContainersService (). 117 getContainerListID (containerListName, params.getPage ().getID ()); 118 if (clistID != -1) { 119 this.ctnListID = clistID; 120 } 121 } 122 setQuery(query); 123 if (aLoadRequest != null) { 124 this.loadRequest = aLoadRequest; 125 } 126 } 127 128 129 144 public ContainerSearcher (int aSiteId, String aContainerDefinitionName, 145 String query, EntryLoadRequest aLoadRequest) { 146 this.siteId = aSiteId; 147 this.containerDefinitionName = aContainerDefinitionName; 148 this.siteModeSearching = true; 149 150 if ( aSiteId == -1 ){ 151 try { 152 ServicesRegistry sReg = ServicesRegistry.getInstance(); 153 Enumeration sites = sReg.getJahiaSitesService().getSites(); 154 JahiaSite site = null; 155 ArrayList ar = new ArrayList (); 156 while ( sites.hasMoreElements() ){ 157 site = (JahiaSite)sites.nextElement(); 158 ar.add(new Integer (site.getID())); 159 } 160 int[] ids = new int[ar.size()]; 161 Integer I = null; 162 for ( int i=0; i<ar.size(); i++ ){ 163 I = (Integer )ar.get(i); 164 ids[i]=I.intValue(); 165 } 166 this.setSiteIds(ids); 167 } catch ( Throwable t) { 168 } 169 } else { 170 this.setSiteIds(new int[]{aSiteId}); 171 } 172 173 if (aLoadRequest != null) { 174 this.loadRequest = aLoadRequest; 175 } 176 setQuery(query); 177 } 178 179 186 public ContainerSearcher (int[] siteIDs, String aContainerDefinitionName, 187 String query, EntryLoadRequest aLoadRequest) { 188 if ( siteIDs != null ){ 189 this.setSiteIds(siteIDs); 190 } 191 this.containerDefinitionName = aContainerDefinitionName; 192 this.siteModeSearching = true; 193 194 if (aLoadRequest != null) { 195 this.loadRequest = aLoadRequest; 196 } 197 this.setQuery(query); 198 } 199 200 207 public boolean isSiteModeSearching () { 208 return this.siteModeSearching; 209 } 210 211 223 public JahiaSearchResult search (String query, ParamBean jParams) 224 throws JahiaException { 225 JahiaSearchResult result = null; 226 227 setQuery (query); 229 230 ServicesRegistry sReg = ServicesRegistry.getInstance (); 232 result = sReg.getJahiaSearchService ().search (this, jParams); 233 234 setResult (result); 236 237 this.lastSearchTime = System.currentTimeMillis(); 239 240 this.updated = true; 241 242 return result; 243 } 244 245 252 public String getName () { 253 return ContainerSearcher.CONTAINER_SEARCHER; 254 } 255 256 262 public int getCtnListID () { 263 return this.ctnListID; 264 } 265 266 270 public int getSiteId () { 271 return this.siteId; 272 } 273 274 278 public String getContainerDefinitionName () { 279 return this.containerDefinitionName; 280 } 281 282 288 public long getLastSearchTime () { 289 return this.lastSearchTime; 290 } 291 292 298 public boolean getUpdateStatus () { 299 return this.updated; 300 } 301 302 306 public void setUpdateStatus () { 307 this.updated = true; 308 } 309 310 314 public void resetUpdateStatus () { 315 this.updated = false; 316 } 317 318 321 public int getContainerLevel () { 322 return this.containerLevel; 323 } 324 325 328 public ArrayList getLanguageCodes () { 329 List locales = loadRequest.getLocales (); 330 ArrayList result = new ArrayList (); 331 for (int i = 0; i < locales.size (); i++) { 332 Locale locale = (Locale ) locales.get (i); 333 result.add (locale.toString ()); 334 } 335 return result; 336 } 337 338 public EntryLoadRequest getEntryLoadRequest () { 339 return this.loadRequest; 340 } 341 342 public int[] getSiteIds() { 343 return siteIds; 344 } 345 346 public void setSiteIds(int[] siteIDs) { 347 this.siteIds = siteIDs; 348 } 349 350 public boolean isQueryValid () { 351 return (getQuery() != null && !"".equals (getQuery().trim ())); 352 } 353 354 public String toString() { 355 return "Query=" + getQuery(); 356 } 357 358 } 359 | Popular Tags |