Changeset 36186


Ignore:
Timestamp:
2022-05-16T14:39:21+12:00 (5 months ago)
Author:
kjdon
Message:

modified to use teh new SearchMeta

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchMetadataManager.java

    r36162 r36186  
    3232
    3333import org.greenstone.gatherer.Configuration;
     34import org.greenstone.gatherer.DebugStream;
    3435import org.greenstone.gatherer.Dictionary;
    3536import org.greenstone.gatherer.Gatherer;
     
    3940
    4041public class SearchMetadataManager
     42    extends CollectionMetaManager
    4143{
    4244    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 
    5146  // the following are special and should not be translated
    5247  public static final String METADATA_INDEX = "ex.metadata";
    5348
    54     CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager;
     49    //CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager;
    5550
    5651    public SearchMetadataManager() {
    57     }
    58 
     52    super(CollectionDesignManager.collect_config.getDocumentElement(), StaticStrings.SEARCHMETADATA_ELEMENT, new SearchMeta("", ""));
     53    DebugStream.println("SearchMetaManager: " + getSize() + " metadata parsed.");
     54    }
     55   
    5956    /** Destructor. */
    6057    public void destroy() {
     
    7875    }
    7976   
     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
    80124
    81125    /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
     
    83127     */
    84128    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    }   
    85139    }
    86140
     
    137191          String index_id = ((Index)indexes.get(i)).getID();
    138192          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);
    140195        entries.add(sme);
    141196          }
     
    146201        int levels_size = levels.size();
    147202        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);
    149204        entries.add(sme);
    150205        }
     
    155210        for (int i=0; i<sortfields_size; i++) {
    156211              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);
    158213        entries.add(sme);
    159214        }
     
    163218        int facets_size = facets.size();
    164219        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);
    167222        entries.add(sme);
    168223        }
     
    174229        int partitions_size = partitions.size();
    175230        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);
    177232        entries.add(sme);
    178233        }
     
    183238        int languages_size = languages.size();
    184239        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);
    186241        entries.add(sme);
    187242        }
     
    195250    String id;
    196251    String type;
    197     CollectionMeta coll_meta = null;
     252    SearchMeta coll_meta = null;
    198253    String value;
    199254
     
    201256        this.id = id;
    202257        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);
    205261    }
    206262   
Note: See TracChangeset for help on using the changeset viewer.