1 31 32 package org.opencms.search; 33 34 import org.opencms.main.CmsIllegalArgumentException; 35 import org.opencms.main.CmsLog; 36 import org.opencms.main.OpenCms; 37 import org.opencms.util.CmsStringUtil; 38 39 import java.util.ArrayList ; 40 import java.util.HashMap ; 41 import java.util.List ; 42 import java.util.Map ; 43 44 import org.apache.commons.logging.Log; 45 46 56 public class CmsSearchIndexSource implements Comparable { 57 58 59 private static final Log LOG = CmsLog.getLog(CmsSearchIndexSource.class); 60 61 62 private List m_documentTypes; 63 64 65 private I_CmsIndexer m_indexer; 66 67 68 private String m_indexerClassName; 69 70 71 private String m_name; 72 73 74 private Map m_params; 75 76 77 private List m_resourcesNames; 78 79 82 public CmsSearchIndexSource() { 83 84 m_params = new HashMap (); 85 m_resourcesNames = new ArrayList (); 86 m_documentTypes = new ArrayList (); 87 } 88 89 95 public void addConfigurationParameter(String key, String value) { 96 97 m_params.put(key, value); 98 } 99 100 105 public void addDocumentType(String key) { 106 107 m_documentTypes.add(key); 108 } 109 110 115 public void addResourceName(String resourceName) { 116 117 m_resourcesNames.add(resourceName); 118 } 119 120 138 public int compareTo(Object o) throws ClassCastException { 139 140 CmsSearchIndexSource other = (CmsSearchIndexSource)o; 141 String otherName = other.getName(); 142 String myName = getName(); 143 return myName.compareTo(otherName); 144 } 145 146 161 public boolean equals(Object obj) { 162 163 boolean ret = false; 164 try { 165 int cp = compareTo(obj); 166 ret = cp == 0; 167 } catch (Exception e) { 168 } 170 return ret; 171 } 172 173 178 public List getDocumentTypes() { 179 180 return m_documentTypes; 181 } 182 183 188 public I_CmsIndexer getIndexer() { 189 190 return m_indexer; 191 } 192 193 198 public String getIndexerClassName() { 199 200 return m_indexerClassName; 201 } 202 203 208 public String getName() { 209 210 return m_name; 211 } 212 213 219 public String getParam(String key) { 220 221 return (String )m_params.get(key); 222 } 223 224 229 public Map getParams() { 230 231 return m_params; 232 } 233 234 239 public List getResourcesNames() { 240 241 return m_resourcesNames; 242 } 243 244 250 public int hashCode() { 251 252 return m_name.hashCode(); 253 } 254 255 262 public boolean removeDocumentType(String key) { 263 264 return m_documentTypes.remove(key); 265 } 266 267 272 public void setDocumentTypes(List documentTypes) { 273 274 m_documentTypes = documentTypes; 275 } 276 277 286 public void setIndexerClassName(String indexerClassName) throws CmsIllegalArgumentException { 287 288 try { 289 m_indexer = (I_CmsIndexer)Class.forName(indexerClassName).newInstance(); 290 m_indexerClassName = indexerClassName; 291 } catch (Exception exc) { 292 if (LOG.isWarnEnabled()) { 293 LOG.warn( 294 Messages.get().getBundle().key(Messages.LOG_INDEXER_CREATION_FAILED_1, m_indexerClassName), 295 exc); 296 } 297 throw new CmsIllegalArgumentException(Messages.get().container( 298 Messages.ERR_INDEXSOURCE_INDEXER_CLASS_NAME_2, 299 indexerClassName, 300 I_CmsIndexer.class.getName())); 301 } 302 } 303 304 312 public void setName(String name) throws CmsIllegalArgumentException { 313 314 if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) { 315 throw new CmsIllegalArgumentException(Messages.get().container( 316 Messages.ERR_INDEXSOURCE_CREATE_MISSING_NAME_0)); 317 } 318 if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) { 320 CmsSearchManager mngr = OpenCms.getSearchManager(); 321 if (mngr.getIndexSource(name) != this) { 323 if (mngr.getSearchIndexSources().keySet().contains(name)) { 324 throw new CmsIllegalArgumentException(Messages.get().container( 325 Messages.ERR_INDEXSOURCE_CREATE_INVALID_NAME_1, 326 name)); 327 } 328 } 329 } 330 m_name = name; 331 } 332 333 338 public void setParams(Map params) { 339 340 m_params = params; 341 } 342 343 348 public void setResourcesNames(List resources) { 349 350 m_resourcesNames = resources; 351 } 352 }
| Popular Tags
|