Index: /main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchMetadataManager.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchMetadataManager.java	(revision 36185)
+++ /main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchMetadataManager.java	(revision 36186)
@@ -32,4 +32,5 @@
 
 import org.greenstone.gatherer.Configuration;
+import org.greenstone.gatherer.DebugStream;
 import org.greenstone.gatherer.Dictionary;
 import org.greenstone.gatherer.Gatherer;
@@ -39,22 +40,18 @@
 
 public class SearchMetadataManager
+    extends CollectionMetaManager
 {
     private Control controls;
-
-    public static final String TYPE_INDEX = "index";
-    public static final String TYPE_LEVEL = "level";
-    public static final String TYPE_PARTITION = "partition";
-    public static final String TYPE_LANGUAGE = "language";
-  public static final String TYPE_SORTFIELD = "sortfield";
-  public static final String TYPE_FACET = "facet";
-  
+ 
   // the following are special and should not be translated
   public static final String METADATA_INDEX = "ex.metadata";
 
-    CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager;
+    //CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager;
 
     public SearchMetadataManager() {
-    }
-
+	super(CollectionDesignManager.collect_config.getDocumentElement(), StaticStrings.SEARCHMETADATA_ELEMENT, new SearchMeta("", ""));
+	DebugStream.println("SearchMetaManager: " + getSize() + " metadata parsed.");
+    }
+    
     /** Destructor. */
     public void destroy() {
@@ -78,4 +75,51 @@
     }
     
+    public SearchMeta getMetadatum(String name, String type) {
+	return getMetadatum(name, type, true);
+    }
+
+    public SearchMeta getMetadatum(String name, String type, boolean add_if_not_found) {
+	System.err.println("Get the metadata for " + name + " type="+type+" in the default language.");
+	int size = getSize();
+	System.err.println("size of searchmeta = "+size);
+	if (size == 0) {
+	    return null;
+	}
+	for(int i = 0; i < size; i++) {
+	    SearchMeta metadatum = (SearchMeta) getElementAt(i);
+	    System.err.println("checking meta = "+metadatum);
+	    if(metadatum.getName().equals(name) && metadatum.getType().equals(type) && metadatum.getLanguage().equals(Configuration.getLanguage())) {
+		DebugStream.println("Found '" + metadatum + "'");
+		return metadatum;
+	    }
+	    else {
+		//DebugStream.println("No match with: " + metadatum.getName() + " [l=" + metadatum.getLanguage() + "] \"" + metadatum.getValue() + "\"");
+	    }
+	    metadatum = null;
+	}
+	if(add_if_not_found) {
+	    SearchMeta result = new SearchMeta(name, type);
+	    addMetadatum(result);
+	    DebugStream.println("Added new metadata: " + name);
+	    return result;
+	}
+	else {
+	    return null;
+	}
+    }
+
+    /** Retrieve all of the metadata for the given feature and type */
+    public ArrayList getMetadata(String name, String type) {
+    	ArrayList result = new ArrayList();
+    	int size = getSize(); // Refresh DOM Model
+    	for(int i = 0; i < size; i++) {
+    	    SearchMeta metadata = (SearchMeta) getElementAt(i);
+    	    if(metadata.getName().equals(name) && metadata.getType().equals(type)) {
+    		result.add(metadata);
+    	    }
+    	}
+    	return result;
+    }
+
 
     /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
@@ -83,4 +127,14 @@
      */
     public void modeChanged(int mode) {
+    }
+
+    public void removeMetadata(String name, String type) {
+	for(int i = getSize(); i != 0; i--) {
+	    SearchMeta other = (SearchMeta) getElementAt(i - 1);
+	    if(name.equals(other.getName()) && type.equals(other.getType())) {
+		remove(i - 1);
+	    }
+	    other = null;
+	}	
     }
 
@@ -137,5 +191,6 @@
 	      String index_id = ((Index)indexes.get(i)).getID();
 	      if (!index_id.equals(METADATA_INDEX)) {
-		SearchMetadataEntry sme = new SearchMetadataEntry(index_id, TYPE_INDEX);
+		  System.err.println("new sme, id="+index_id);
+		SearchMetadataEntry sme = new SearchMetadataEntry(index_id, SearchMeta.TYPE_INDEX);
 		entries.add(sme);
 	      }
@@ -146,5 +201,5 @@
 	    int levels_size = levels.size();
 	    for (int i=0; i<levels_size; i++) {
-		SearchMetadataEntry sme = new SearchMetadataEntry(((IndexOption)levels.get(i)).getName(), TYPE_LEVEL);
+		SearchMetadataEntry sme = new SearchMetadataEntry(((IndexOption)levels.get(i)).getName(), SearchMeta.TYPE_LEVEL);
 		entries.add(sme);
 	    }
@@ -155,5 +210,5 @@
 	    for (int i=0; i<sortfields_size; i++) {
               String sf_id = ((Index)sortfields.get(i)).getID();
-              SearchMetadataEntry sme = new SearchMetadataEntry(sf_id, TYPE_SORTFIELD);
+              SearchMetadataEntry sme = new SearchMetadataEntry(sf_id, SearchMeta.TYPE_SORT);
 		entries.add(sme);
 	    }
@@ -163,6 +218,6 @@
 	    int facets_size = facets.size();
 	    for (int i=0; i<facets_size; i++) {
-              String facet_id = ((Index)sortfields.get(i)).getID();
-              SearchMetadataEntry sme = new SearchMetadataEntry(facet_id, TYPE_FACET);
+              String facet_id = ((Index)facets.get(i)).getID();
+              SearchMetadataEntry sme = new SearchMetadataEntry(facet_id, SearchMeta.TYPE_FACET);
 		entries.add(sme);
 	    }
@@ -174,5 +229,5 @@
 	    int partitions_size = partitions.size();
 	    for(int i=0; i<partitions_size; i++) {
-		SearchMetadataEntry sme = new SearchMetadataEntry(((SubcollectionIndex)partitions.get(i)).getID(), TYPE_PARTITION);
+		SearchMetadataEntry sme = new SearchMetadataEntry(((SubcollectionIndex)partitions.get(i)).getID(), SearchMeta.TYPE_PARTITION);
 		entries.add(sme);
 	    }
@@ -183,5 +238,5 @@
 	    int languages_size = languages.size();
 	    for (int i=0; i<languages_size; i++) {
-		SearchMetadataEntry sme = new SearchMetadataEntry(((Language)languages.get(i)).getCode(), TYPE_LANGUAGE);
+		SearchMetadataEntry sme = new SearchMetadataEntry(((Language)languages.get(i)).getCode(), SearchMeta.TYPE_LANGUAGE);
 		entries.add(sme);
 	    }
@@ -195,5 +250,5 @@
 	String id;
 	String type;
-	CollectionMeta coll_meta = null;
+	SearchMeta coll_meta = null;
 	String value;
 
@@ -201,6 +256,7 @@
 	    this.id = id;
 	    this.type = type;
-	    coll_meta = collmeta_manager.getMetadatum(getMetaID());
-	    value = coll_meta.getValue(CollectionMeta.GREENSTONE);
+	    //coll_meta = collmeta_manager.getMetadatum(getMetaID(), type);
+	    this.coll_meta = getMetadatum(id, type); //getMetaID(), type);
+	    this.value = coll_meta.getValue(CollectionMeta.GREENSTONE);
 	}
 	
