Changeset 36186
- Timestamp:
- 2022-05-16T14:39:21+12:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchMetadataManager.java
r36162 r36186 32 32 33 33 import org.greenstone.gatherer.Configuration; 34 import org.greenstone.gatherer.DebugStream; 34 35 import org.greenstone.gatherer.Dictionary; 35 36 import org.greenstone.gatherer.Gatherer; … … 39 40 40 41 public class SearchMetadataManager 42 extends CollectionMetaManager 41 43 { 42 44 private Control controls; 43 44 public static final String TYPE_INDEX = "index"; 45 public static final String TYPE_LEVEL = "level"; 46 public static final String TYPE_PARTITION = "partition"; 47 public static final String TYPE_LANGUAGE = "language"; 48 public static final String TYPE_SORTFIELD = "sortfield"; 49 public static final String TYPE_FACET = "facet"; 50 45 51 46 // the following are special and should not be translated 52 47 public static final String METADATA_INDEX = "ex.metadata"; 53 48 54 CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager;49 //CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager; 55 50 56 51 public SearchMetadataManager() { 57 } 58 52 super(CollectionDesignManager.collect_config.getDocumentElement(), StaticStrings.SEARCHMETADATA_ELEMENT, new SearchMeta("", "")); 53 DebugStream.println("SearchMetaManager: " + getSize() + " metadata parsed."); 54 } 55 59 56 /** Destructor. */ 60 57 public void destroy() { … … 78 75 } 79 76 77 public SearchMeta getMetadatum(String name, String type) { 78 return getMetadatum(name, type, true); 79 } 80 81 public SearchMeta getMetadatum(String name, String type, boolean add_if_not_found) { 82 System.err.println("Get the metadata for " + name + " type="+type+" in the default language."); 83 int size = getSize(); 84 System.err.println("size of searchmeta = "+size); 85 if (size == 0) { 86 return null; 87 } 88 for(int i = 0; i < size; i++) { 89 SearchMeta metadatum = (SearchMeta) getElementAt(i); 90 System.err.println("checking meta = "+metadatum); 91 if(metadatum.getName().equals(name) && metadatum.getType().equals(type) && metadatum.getLanguage().equals(Configuration.getLanguage())) { 92 DebugStream.println("Found '" + metadatum + "'"); 93 return metadatum; 94 } 95 else { 96 //DebugStream.println("No match with: " + metadatum.getName() + " [l=" + metadatum.getLanguage() + "] \"" + metadatum.getValue() + "\""); 97 } 98 metadatum = null; 99 } 100 if(add_if_not_found) { 101 SearchMeta result = new SearchMeta(name, type); 102 addMetadatum(result); 103 DebugStream.println("Added new metadata: " + name); 104 return result; 105 } 106 else { 107 return null; 108 } 109 } 110 111 /** Retrieve all of the metadata for the given feature and type */ 112 public ArrayList getMetadata(String name, String type) { 113 ArrayList result = new ArrayList(); 114 int size = getSize(); // Refresh DOM Model 115 for(int i = 0; i < size; i++) { 116 SearchMeta metadata = (SearchMeta) getElementAt(i); 117 if(metadata.getName().equals(name) && metadata.getType().equals(type)) { 118 result.add(metadata); 119 } 120 } 121 return result; 122 } 123 80 124 81 125 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden … … 83 127 */ 84 128 public void modeChanged(int mode) { 129 } 130 131 public void removeMetadata(String name, String type) { 132 for(int i = getSize(); i != 0; i--) { 133 SearchMeta other = (SearchMeta) getElementAt(i - 1); 134 if(name.equals(other.getName()) && type.equals(other.getType())) { 135 remove(i - 1); 136 } 137 other = null; 138 } 85 139 } 86 140 … … 137 191 String index_id = ((Index)indexes.get(i)).getID(); 138 192 if (!index_id.equals(METADATA_INDEX)) { 139 SearchMetadataEntry sme = new SearchMetadataEntry(index_id, TYPE_INDEX); 193 System.err.println("new sme, id="+index_id); 194 SearchMetadataEntry sme = new SearchMetadataEntry(index_id, SearchMeta.TYPE_INDEX); 140 195 entries.add(sme); 141 196 } … … 146 201 int levels_size = levels.size(); 147 202 for (int i=0; i<levels_size; i++) { 148 SearchMetadataEntry sme = new SearchMetadataEntry(((IndexOption)levels.get(i)).getName(), TYPE_LEVEL);203 SearchMetadataEntry sme = new SearchMetadataEntry(((IndexOption)levels.get(i)).getName(), SearchMeta.TYPE_LEVEL); 149 204 entries.add(sme); 150 205 } … … 155 210 for (int i=0; i<sortfields_size; i++) { 156 211 String sf_id = ((Index)sortfields.get(i)).getID(); 157 SearchMetadataEntry sme = new SearchMetadataEntry(sf_id, TYPE_SORTFIELD);212 SearchMetadataEntry sme = new SearchMetadataEntry(sf_id, SearchMeta.TYPE_SORT); 158 213 entries.add(sme); 159 214 } … … 163 218 int facets_size = facets.size(); 164 219 for (int i=0; i<facets_size; i++) { 165 String facet_id = ((Index) sortfields.get(i)).getID();166 SearchMetadataEntry sme = new SearchMetadataEntry(facet_id, TYPE_FACET);220 String facet_id = ((Index)facets.get(i)).getID(); 221 SearchMetadataEntry sme = new SearchMetadataEntry(facet_id, SearchMeta.TYPE_FACET); 167 222 entries.add(sme); 168 223 } … … 174 229 int partitions_size = partitions.size(); 175 230 for(int i=0; i<partitions_size; i++) { 176 SearchMetadataEntry sme = new SearchMetadataEntry(((SubcollectionIndex)partitions.get(i)).getID(), TYPE_PARTITION);231 SearchMetadataEntry sme = new SearchMetadataEntry(((SubcollectionIndex)partitions.get(i)).getID(), SearchMeta.TYPE_PARTITION); 177 232 entries.add(sme); 178 233 } … … 183 238 int languages_size = languages.size(); 184 239 for (int i=0; i<languages_size; i++) { 185 SearchMetadataEntry sme = new SearchMetadataEntry(((Language)languages.get(i)).getCode(), TYPE_LANGUAGE);240 SearchMetadataEntry sme = new SearchMetadataEntry(((Language)languages.get(i)).getCode(), SearchMeta.TYPE_LANGUAGE); 186 241 entries.add(sme); 187 242 } … … 195 250 String id; 196 251 String type; 197 CollectionMeta coll_meta = null;252 SearchMeta coll_meta = null; 198 253 String value; 199 254 … … 201 256 this.id = id; 202 257 this.type = type; 203 coll_meta = collmeta_manager.getMetadatum(getMetaID()); 204 value = coll_meta.getValue(CollectionMeta.GREENSTONE); 258 //coll_meta = collmeta_manager.getMetadatum(getMetaID(), type); 259 this.coll_meta = getMetadatum(id, type); //getMetaID(), type); 260 this.value = coll_meta.getValue(CollectionMeta.GREENSTONE); 205 261 } 206 262
Note:
See TracChangeset
for help on using the changeset viewer.