Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/AbstractIndexer.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/AbstractIndexer.java	(revision 6736)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/AbstractIndexer.java	(revision 6736)
@@ -0,0 +1,81 @@
+package org.greenstone.gsdl3.gs3build.indexers;
+
+import java.util.*;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import org.greenstone.gsdl3.gs3build.util.DOMUtils;
+
+public abstract class AbstractIndexer implements IndexerInterface
+{ 
+  class CollectionIndex
+  { String level;
+    String name;
+    List fields;
+
+    public CollectionIndex(String indexName, Node node)
+    { this.fields = new ArrayList();
+      this.name = indexName;
+      this.level = IndexerManager.DEFAULT_LEVEL;
+    
+      NodeList children = node.getChildNodes();
+      for (int c = 0; c < children.getLength(); c ++) {
+	Node child = children.item(c);
+	
+	if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
+	  String name = child.getNodeName();
+	  
+	  if (name.equals("level")) {
+	    String levelName = DOMUtils.getNodeChildText(children.item(c));
+	    this.level = levelName;
+	  }
+	  else if (name.equals("field")) {
+	    String fieldName = DOMUtils.getNodeChildText(children.item(c));
+	    this.fields.add(fieldName.toString());
+	  }
+	}
+      }
+      if (this.fields.size() == 0) {
+	this.fields.add(IndexerManager.DEFAULT_FIELD);
+      }
+    }
+
+    public void prepareIndexer(IndexerInterface indexer)
+    { indexer.addIndex(this.name, this.level, this.fields.get(0).toString());
+    }
+  }
+
+
+  public boolean configure(org.w3c.dom.Node searchNode)
+  {
+    NodeList indexChildren = searchNode.getChildNodes();
+
+    // check for <index> tag children
+    for (int i = 0; i < indexChildren.getLength(); i ++) {
+      String childName = indexChildren.item(i).getNodeName();
+
+      if (childName.equals("index"))
+      { NamedNodeMap atts = indexChildren.item(i).getAttributes();
+	
+	Node attribute = atts.getNamedItem("name");
+	String indexName = attribute.getNodeValue();
+	      
+	// create the local indexer representation
+	CollectionIndex index = new CollectionIndex(indexName, indexChildren.item(i));
+	     
+	// prepare it...
+	index.prepareIndexer(this);
+      }
+    }
+    return true;
+  }
+
+  public void tidyup()
+  {
+  }
+}
Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerFactory.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerFactory.java	(revision 6736)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerFactory.java	(revision 6736)
@@ -0,0 +1,10 @@
+package org.greenstone.gsdl3.gs3build.indexers;
+
+public class IndexerFactory
+{ public static final IndexerInterface makeIndexer(String type, String name)
+  { if (type.equals(MGIndexer.MG_INDEX_TYPE)) 
+    { return new MGIndexer(name);
+    }
+    return null;
+  }
+}
Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerInterface.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerInterface.java	(revision 6735)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerInterface.java	(revision 6736)
@@ -12,10 +12,17 @@
   public static final String GS2_INDEX_LABEL = "Index";  
 
+  public String  getIndexType();
+  public String  getName();
+  public int     getNumberOfPasses();
+  // TODO: add a function call to provide appropriate XML for the service description
+  public void    tidyup();
+
   public boolean configure(String label, String value);
-  public boolean addIndex(String level, String field);
+  public boolean configure(org.w3c.dom.Node node);
+  public boolean addIndex(String name, String level, String field);
+
   public boolean startPass(int passNumber);
   public boolean indexDocument(DocumentID id, DocumentInterface document);
   public boolean endPass(int passNumber);
-  public void    tidyup();
-  public int getNumberOfPasses();
+
 }
Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java	(revision 6735)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java	(revision 6736)
@@ -18,5 +18,5 @@
 import org.greenstone.gsdl3.gs3build.xpointer.XPointer;
 
-public class MGIndexer implements IndexerInterface
+public class MGIndexer extends AbstractIndexer
 { 
   int          pass;
@@ -37,4 +37,5 @@
   String       level;
   String       field;
+  String       name;
 
   static final char END_OF_DOCUMENT = (char) 2;
@@ -42,10 +43,14 @@
   static final char END_OF_STREAM   = (char) 4;
 
+  public static final String MG_INDEX_TYPE = "mg";
+
   class MGIndex
-  { String level;
+  { String name;
+    String level;
     String field;
 
-    public MGIndex(String level, String field)
-    { this.level = level;
+    public MGIndex(String name, String level, String field)
+    { this.name  = name;
+      this.level = level;
       this.field = field;
     }
@@ -55,7 +60,8 @@
     
       if (colonAt >= 0)
-      { field = indexLabel.substring(colonAt+1);
-        level = indexLabel.substring(0, colonAt);
-      }
+      { this.field = indexLabel.substring(colonAt+1);
+        this.level = indexLabel.substring(0, colonAt);
+      }
+      this.name = null;
     }
 
@@ -67,8 +73,21 @@
     { return this.field;
     }
-  }
-
-  public MGIndexer()
+
+    public String getName()
+    { return this.name;
+    }
+  }
+
+  public MGIndexer(String name)
   { this.indexes = new ArrayList();
+    this.name    = name;
+  }
+
+  public String getIndexType()
+  { return MG_INDEX_TYPE;
+  } 
+
+  public String getName()
+  { return this.name;
   }
 
@@ -131,7 +150,7 @@
   }
 
-  public boolean addIndex(String level, String field)
+  public boolean addIndex(String name, String level, String field)
   {
-    MGIndex index = new MGIndex(level, field);
+    MGIndex index = new MGIndex(name, level, field);
     this.indexes.add(index);
     return true;
@@ -160,5 +179,5 @@
 	}
 
-	descriptive.setMetadata("gsdl3", "mgseqno", indexName + "." + Integer.toString(this.sectionSeqNo));
+	descriptive.addMetadata("gsdl3", "mgseqno", indexName + "." + Integer.toString(this.sectionSeqNo));
 	metsDoc.setModified(true);
 	//	System.out.println("Assigning " + this.sectionSeqNo + " to " + metsDoc.getID() + " " + division.getLabel());
@@ -269,4 +288,8 @@
   public boolean indexDocument(DocumentID docID, DocumentInterface document)
   {
+    if (this.pass == 0) {
+      document.removeAllMetadata("gsdl3", "mgseqno");
+    }
+
     if (!this.firstDocument)
     { // Send a 'CTRL-B' before the document itself
@@ -280,4 +303,5 @@
       }
     }
+
     String docText = null;
 
@@ -421,5 +445,8 @@
 	this.level = index.getLevel();
 	this.field = index.getField();
-	this.indexName = this.getIndexDirectory(index.getLevel(), index.getField());
+	this.indexName = index.getName();
+	if (this.indexName == null || this.indexName.length() == 0) {
+	  this.indexName = this.getIndexDirectory(index.getLevel(), index.getField());
+	}
 	this.indexStem = this.outputDirectory + File.separatorChar + 
 	  this.indexName + File.separatorChar + "index"; // TODO: modify for index
Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGPPIndexer.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGPPIndexer.java	(revision 6735)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGPPIndexer.java	(revision 6736)
@@ -8,7 +8,8 @@
 import java.io.IOException;
 
-public class MGPPIndexer implements IndexerInterface
+public class MGPPIndexer extends AbstractIndexer
 { 
   int          pass;
+  String       name;
   boolean      firstDocument;
   String       outputDirectory;
@@ -19,7 +20,13 @@
   Process      mgpp_passes;
   static final String documentSeparator = "<Document>";
+
+  public static final String MGPP_INDEX_TYPE = "mgpp";
   
-  public MGPPIndexer()
-  {	
+  public MGPPIndexer(String name)
+  { this.name = name;
+  }
+
+  public String getName()
+  { return this.name;
   }
 
@@ -38,5 +45,9 @@
   }
 
-  public boolean addIndex(String level, String field)
+  public String getIndexType()
+  { return MGPP_INDEX_TYPE;
+  }
+
+  public boolean addIndex(String name, String level, String field)
   { return true;
   }
