Changeset 36138
- Timestamp:
- 2022-04-12T11:04:26+12:00 (2 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer/cdm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/Index.java
r24367 r36138 36 36 import org.w3c.dom.*; 37 37 38 /** This class encapsulates a single indexing pair. 38 /** This class encapsulates a single index. MGPP/Lucene/SOLR 39 * Can be subclassed for Sort fields and facet fields 39 40 * @author John Thompson, Greenstone Digital Library, University of Waikato 40 41 * @version 2.3d … … 42 43 public class Index 43 44 implements Comparable, DOMProxyListEntry { 44 /** An values of items in the index level enumeration. */ 45 static protected final String LEVEL[] = {StaticStrings.DOCUMENT_STR, StaticStrings.SECTION_STR, StaticStrings.PARAGRAPH_STR}; 46 47 private ArrayList sources = null; 48 /** The level of this index (if old sckool MG). */ 49 private int level = -1; 45 46 protected ArrayList sources = null; 47 50 48 /** The element this index is based upon. */ 51 private Element element = null; 49 protected Element element = null; 50 /** The name for our elements */ 51 protected String element_name = StaticStrings.INDEX_ELEMENT; 52 /** The name for the default element */ 53 protected String default_element_name = StaticStrings.INDEX_DEFAULT_ELEMENT; 52 54 /** The unique, if cryptic, identifier of an index. */ 53 pr ivateString id = null;55 protected String id = null; 54 56 55 57 /** Default constructor, which should only be used during DOMProxyListModel creation. */ … … 66 68 this.sources = sources; 67 69 // Create a new element 68 this.element = CollectionConfiguration.createElement( StaticStrings.INDEX_ELEMENT);70 this.element = CollectionConfiguration.createElement(this.element_name); 69 71 // For each source add a content element 70 72 int size = sources.size(); … … 85 87 } 86 88 87 /** Constructor for a newly assigned index with specified level (old skool). */88 public Index(int level, ArrayList sources) {89 this(sources);90 this.level = level;91 element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, LEVEL[level]);92 }93 94 public Index(String level, ArrayList sources) {95 this(sources);96 for(int i = 0; i < LEVEL.length; i++) {97 if(LEVEL[i].equalsIgnoreCase(level)) {98 this.level = i;99 }100 }101 element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, LEVEL[this.level]);102 }103 104 89 /** Method to compare two indexes. 105 90 * @param object The other index as an <strong>Object</strong>. … … 130 115 return element; 131 116 } 132 133 /** Method to get the value of level.134 * @return the level as a int135 */136 public int getLevel() {137 if(level == -1 && element != null) {138 String level_str = element.getAttribute(StaticStrings.LEVEL_ATTRIBUTE);139 for(int i = 0; level == -1 && i < LEVEL.length; i++) {140 if(level_str.equals(LEVEL[i])) {141 level = i;142 }143 }144 level_str = null;145 }146 return level;147 }148 117 149 118 public String getID() { … … 153 122 else if(id == null) { 154 123 StringBuffer id_buffer = new StringBuffer(); 155 // Write level information, if any.156 int level = getLevel();157 if(0 <= level && level < 3) {158 id_buffer.append(LEVEL[level]);159 id_buffer.append(StaticStrings.COLON_CHARACTER);160 }161 124 // Write data information. Retrieve each of the content sources and add them in a comma separated list. 162 125 ArrayList sources = getSources(); … … 225 188 public void setElement(Element element) { 226 189 this.element = element; 227 this.level = -1;228 190 this.id = null; 229 191 this.sources = null; 230 192 } 231 193 232 /** Method to set the level of this index which can only be used for the default index.233 * @param new_level the new level as an int234 */235 public void setLevel(int new_level) {236 // System.err.println("SetLevel(" + new_level + ")");237 if(element != null && element.getNodeName().equals(StaticStrings.INDEX_DEFAULT_ELEMENT)) {238 if (0 <= new_level && new_level < 3) {239 element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, LEVEL[new_level]);240 } else {241 element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, "");242 }243 this.id = null; // Regenerate ID.244 this.level = new_level;245 }246 else {247 DebugStream.println("Error! Called setLevel() of index other than the default.");248 }249 }250 251 194 /** Method to set the sources for this index which can only be used for the default index. 252 195 * @param sources an ArrayList of source names 253 196 */ 254 197 public void setSources(ArrayList sources) { 255 if(element != null && element.getNodeName().equals( StaticStrings.INDEX_DEFAULT_ELEMENT)) {198 if(element != null && element.getNodeName().equals(this.default_element_name)) { 256 199 // Erase old sources 257 200 XMLTools.clear(element); … … 288 231 StringBuffer text_buffer = new StringBuffer(""); 289 232 // Generate language dependant id (include extracted metadata namespace) 290 // Write level information, if any.291 int level = getLevel();292 if(0 <= level && level < 3) {293 text_buffer.append(LEVEL[level]);294 text_buffer.append(StaticStrings.COLON_CHARACTER);295 }296 233 // Write data information. Retrieve each of the content sources and add them in a comma separated list. 297 234 ArrayList sources = getSources();
Note:
See TracChangeset
for help on using the changeset viewer.