Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java	(revision 9939)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java	(revision 9940)
@@ -28,19 +28,19 @@
 public class MGIndexer extends AbstractIndexer
 { 
-  int          pass;
-  int          documentSeqNo;
-  int          sectionSeqNo;
-  boolean      firstDocument;
-  String       outputDirectory;
-//   InputStream  indexerFeedback;
-//   InputStream  indexerErrors;
+    int          pass;
+    int          documentSeqNo;
+    int          sectionSeqNo;
+    boolean      firstDocument;
+    String       outputDirectory;
+    //   InputStream  indexerFeedback;
+    //   InputStream  indexerErrors;
     //OutputStream indexerTextfeed;
     StringBuffer indexBuffer;
     //Process      mg_passes;
-  File         textDirectory;
-  File         indexDirectory;
-  String       indexStem;
-  String       textStem;
-  List         indexes;
+    File         textDirectory;
+    File         indexDirectory;
+    String       indexStem;
+    String       textStem;
+    List         indexes;
     String       overallName; 
     
@@ -51,298 +51,305 @@
     MGPassesWrapper mgPasses;
     
-  static final char END_OF_DOCUMENT = (char) 2;
+    static final char END_OF_DOCUMENT = (char) 2;
     static final char END_OF_SECTION  = (char) 3; // actually this is end of para for mg
-  static final char END_OF_STREAM   = (char) 4;
+    static final char END_OF_STREAM   = (char) 4;
 
     public static final String MG_INDEX_TYPE = "mg";
     public static final String INDEX_FILE_STEM = "index";
     
-  class MGIndex
-  { String name=null;
-    String level=null;
-    String field=null;
-      boolean error = false;// assume built until we get an error
-
-    public MGIndex(String name, String level, String field)
-    { this.name  = name;
-      this.level = level;
-      this.field = field;
-    }
-
-    public MGIndex(String indexLabel)
-    { int colonAt = indexLabel.indexOf(':');
-    
-      if (colonAt >= 0)
-      { this.field = indexLabel.substring(colonAt+1);
-        this.level = indexLabel.substring(0, colonAt);
-	createIndexName();
-      }
-   }
-
-    public String getLevel()
-    { return this.level;
-    }
-
-    public String getField()
-    { return this.field;
-    }
+    class MGIndex
+    { 
+	String name=null;
+	String level=null;
+	String field=null;
+	boolean error = false;// assume built until we get an error
+
+	public MGIndex(String name, String level, String field)
+	{ 
+	    this.name  = name;
+	    this.level = level;
+	    this.field = field;
+	}
+	
+	public MGIndex(String indexLabel)
+	{ 
+	    int colonAt = indexLabel.indexOf(':');
+	    
+	    if (colonAt >= 0) {
+		this.field = indexLabel.substring(colonAt+1);
+		this.level = indexLabel.substring(0, colonAt);
+		createIndexName();
+	    }
+	}
+
+	public String getLevel()
+	{ 
+	    return this.level;
+	}
+
+	public String getField()
+	{ 
+	    return this.field;
+	}
+
+	public String getName()
+	{ 
+	    if (this.name==null || this.name.equals("")) {
+		createIndexName();
+	    }
+	    return this.name;
+	}
+
+	public boolean hasError() {
+	    return this.error;
+	}
+	public void setError(boolean b) {
+	    this.error = b;
+	}
+
+	private void createIndexName() {
+	    StringBuffer new_name = new StringBuffer();
+	    new_name.append(Character.toLowerCase((char) this.level.charAt(0)));
+
+	    int c, w;
+	    w = 0;
+	    c = 0;
+	    while (c < this.field.length() && w < 2) {
+		char ch = this.field.charAt(c);
+
+		ch = Character.toLowerCase(ch);
+		if (Character.isLetter(ch)) {
+		    if (ch != 'a' && ch != 'e' && ch != 'i' &&
+			ch != 'o' && ch != 'u') {
+			new_name.append(ch);
+			w++;
+		    }
+		}
+		c ++;
+	    }
+	    this.name = new_name.toString();
+	}
+    } // MGIndex
+
+    public MGIndexer(String name)
+    { 
+	this.indexes = new ArrayList();
+	this.overallName = name; 
+    }
+
+    public String getIndexType()
+    { 
+	return MG_INDEX_TYPE;
+    } 
 
     public String getName()
     { 
-	if (this.name==null || this.name.equals("")) {
-	    createIndexName();
-	}
-	return this.name;
-    }
-
-      public boolean hasError() {
-	  return this.error;
-      }
-      public void setError(boolean b) {
-	  this.error = b;
-      }
-
-      private void createIndexName() {
-	  StringBuffer new_name = new StringBuffer();
-	  new_name.append(Character.toLowerCase((char) this.level.charAt(0)));
-
-	  int c, w;
-	  w = 0;
-	  c = 0;
-	  while (c < this.field.length() && w < 2) {
-	      char ch = this.field.charAt(c);
-
-	      ch = Character.toLowerCase(ch);
-	      if (Character.isLetter(ch)) {
-		  if (ch != 'a' && ch != 'e' && ch != 'i' &&
-		      ch != 'o' && ch != 'u') {
-		      new_name.append(ch);
-		      w++;
-		  }
-	      }
-	      c ++;
-	  }
-	  this.name = new_name.toString();
-
-      }
-  } // MGIndex
-
-  public MGIndexer(String name)
-  { this.indexes = new ArrayList();
-    this.overallName = name;
+	return this.overallName; 
+    }
+
+    //    private String getIndexDirectory(String level, String field)
+    //    { StringBuffer directory = new StringBuffer();
+    //      directory.append(Character.toLowerCase((char) level.charAt(0)));
+
+    //      int c, w;
+    //      w = 0;
+    //      c = 0;
+    //      while (c < field.length() && w < 2) {
+    //        char ch = field.charAt(c);
+
+    //        ch = Character.toLowerCase(ch);
+    //        if (Character.isLetter(ch)) {
+    //  	if (ch != 'a' && ch != 'e' && ch != 'i' &&
+    //  	    ch != 'o' && ch != 'u') {
+    //  	  directory.append(ch);
+    //  	  w++;
+    //  	}
+    //        }
+    //        c ++;
+    //      }
+    //      return directory.toString();
+    //    }
+
+    /**
+     *  The output directory should be (collection)/building/text/ for
+     *  normal Greenstone builds.
+     *
+     *  @param <code>String</code> the label to configure
+     *  @param <code>String</code> the value...
+     */ 
+    public boolean configure(String label, String value)
+    { 
+	if (label.equals(IndexerManager.outputDir)) {
+	    this.outputDirectory = value;
+	    this.pass = 0;
     
-  }
-
-  public String getIndexType()
-  { return MG_INDEX_TYPE;
-  } 
-
-  public String getName()
-    { return this.overallName; 
-    }
-
-//    private String getIndexDirectory(String level, String field)
-//    { StringBuffer directory = new StringBuffer();
-//      directory.append(Character.toLowerCase((char) level.charAt(0)));
-
-//      int c, w;
-//      w = 0;
-//      c = 0;
-//      while (c < field.length() && w < 2) {
-//        char ch = field.charAt(c);
-
-//        ch = Character.toLowerCase(ch);
-//        if (Character.isLetter(ch)) {
-//  	if (ch != 'a' && ch != 'e' && ch != 'i' &&
-//  	    ch != 'o' && ch != 'u') {
-//  	  directory.append(ch);
-//  	  w++;
-//  	}
-//        }
-//        c ++;
-//      }
-//      return directory.toString();
-//    }
-
-  /**
-   *  The output directory should be (collection)/building/text/ for
-    *  normal Greenstone builds.
-   *
-   *  @param <code>String</code> the label to configure
-   *  @param <code>String</code> the value...
-   */ 
-  public boolean configure(String label, String value)
-  { 
-    if (label.equals(IndexerManager.outputDir)) {
-      this.outputDirectory = value;
-      this.pass = 0;
-    
-      // attempt to ensure that the text subdirectory exists
-      this.textDirectory = new File(outputDirectory, "text");
-      if (!textDirectory.exists()) {
-	if (!textDirectory.mkdir()) {
-	  return false;
-	}
-      }
-      else if (!textDirectory.isDirectory()) {
-	return false;
-      }
-      this.textStem = this.textDirectory.getPath() + File.separator + INDEX_FILE_STEM;
-
-      // Sign to the user which mg directory is being used...
-      System.out.println("Output MG directory is " + this.textStem);
-    }
-    else if (label.equals(IndexerInterface.GS2_INDEX_LABEL)) {
-      this.indexes.add(new MGIndex(value));
-    }
-
-    return true;
-  }
-
-  public boolean addIndex(String name, String level, String field)
-  {
-    MGIndex index = new MGIndex(name, level, field);
-    this.indexes.add(index);
-    return true;
-  }
-
-  private Node recurseDOM(DocumentInterface metsDoc, Node node, 
-			  AbstractStructure structure, StringBuffer textBuffer,
-			  StringBuffer extraBuffer, String namespace) 
-			  //String name, String namespace, String field)
-  {
-    // send out the ctrl-c...if this is
-    if (structure.getStructureType().equals(METSDivision.DIVISION_TYPE)) {
-	// try doing this for all index types
-	if ((this.currentIndexName != null)) { // && this.level != null && this.level.equals(IndexerInterface.SECTION_LEVEL)) { //name.startsWith("s")) {
-	    METSDivision division = (METSDivision) structure;
-
-	    // get the division metadata block
-	    METSDescriptive descriptive;
-	    String metadataId = division.getDefaultMetadataReference();
-	    if (metadataId == null) {
-		descriptive = metsDoc.getDocumentMetadata().createDescriptive(division.getLabel());
-		division.addMetadataReference(descriptive.getID());
+	    // attempt to ensure that the text subdirectory exists
+	    this.textDirectory = new File(outputDirectory, "text");
+	    if (!textDirectory.exists()) {
+		if (!textDirectory.mkdir()) {
+		    return false;
+		}
+	    }
+	    else if (!textDirectory.isDirectory()) {
+		return false;
+	    }
+	    this.textStem = this.textDirectory.getPath() + File.separator + INDEX_FILE_STEM;
+
+	    // Sign to the user which mg directory is being used...
+	    System.out.println("Output MG directory is " + this.textStem);
+	}
+	else if (label.equals(IndexerInterface.GS2_INDEX_LABEL)) {
+	    this.indexes.add(new MGIndex(value));
+	}
+
+	return true;
+    }
+
+    public boolean addIndex(String name, String level, String field)
+    {
+	MGIndex index = new MGIndex(name, level, field);
+	this.indexes.add(index);
+	return true;
+    }
+
+    private Node recurseDOM(DocumentInterface metsDoc, Node node, 
+			    AbstractStructure structure, StringBuffer textBuffer,
+			    StringBuffer extraBuffer, String namespace) 
+	//String name, String namespace, String field)
+    {
+	// send out the ctrl-c...if this is
+	if (structure.getStructureType().equals(METSDivision.DIVISION_TYPE)) {
+	    // try doing this for all index types
+	    if ((this.currentIndexName != null)) { // && this.level != null && this.level.equals(IndexerInterface.SECTION_LEVEL)) { //name.startsWith("s")) {
+		METSDivision division = (METSDivision) structure;
+
+		// get the division metadata block
+		METSDescriptive descriptive;
+		String metadataId = division.getDefaultMetadataReference();
+		if (metadataId == null) {
+		    descriptive = metsDoc.getDocumentMetadata().createDescriptive(division.getLabel());
+		    division.addMetadataReference(descriptive.getID());
+		}
+		else {
+		    // Get the descriptive item...
+		    descriptive = metsDoc.getDocumentMetadata().getDescriptiveById(metadataId);
+		}
+	    
+		descriptive.addMetadata("gsdl3", "mgseqno", this.overallName + "." + Integer.toString(this.sectionSeqNo));
+	    
+		metsDoc.setChanged(true);
+		//metsDoc.setModified(true);
+		//	System.out.println("Assigning " + this.sectionSeqNo + " to " + metsDoc.getID() + " " + division.getLabel());
+	    } // section level
+	
+	    // append an 'end of section' marker
+	    //textBuffer.append(END_OF_SECTION);
+	    this.sectionSeqNo ++;
+	
+	    // for document-level indexes, always append an 'end of document' tag at the
+	    // end of the document for each section.  Otherwise, each section is followed
+	    // by an end of document character.  This ensures that all indexes use the
+	    // same document numbering...
+	    if (this.currentIndexLevel == null ||
+		this.currentIndexLevel.equals(IndexerInterface.DOCUMENT_LEVEL)) {
+		extraBuffer.append(END_OF_DOCUMENT);
 	    }
 	    else {
-		// Get the descriptive item...
+		textBuffer.append(END_OF_DOCUMENT);
+		this.documentSeqNo ++;
+	    }
+	
+	    // produce the body here for metadata output of divisions - in the case of
+	    // text output, that will happen below...
+	    if (!this.currentIndexField.equals("text")) {
+		METSDescriptive descriptive;
+	
+		METSDivision division = (METSDivision) structure;
+
+		String metadataId = division.getDefaultMetadataReference();
+	    
 		descriptive = metsDoc.getDocumentMetadata().getDescriptiveById(metadataId);
-	    }
-	    
-	    descriptive.addMetadata("gsdl3", "mgseqno", this.overallName + "." + Integer.toString(this.sectionSeqNo));
-	    
-	    metsDoc.setChanged(true);
-	    //metsDoc.setModified(true);
-	    //	System.out.println("Assigning " + this.sectionSeqNo + " to " + metsDoc.getID() + " " + division.getLabel());
-	} // section level
-	
-	// append an 'end of section' marker
-	//textBuffer.append(END_OF_SECTION);
-	this.sectionSeqNo ++;
-	
-	// for document-level indexes, always append an 'end of document' tag at the
-	// end of the document for each section.  Otherwise, each section is followed
-	// by an end of document character.  This ensures that all indexes use the
-	// same document numbering...
-	if (this.currentIndexLevel == null ||
-	    this.currentIndexLevel.equals(IndexerInterface.DOCUMENT_LEVEL)) {
-	    extraBuffer.append(END_OF_DOCUMENT);
-	}
-	else {
-	    textBuffer.append(END_OF_DOCUMENT);
-	    this.documentSeqNo ++;
-	}
-	
-	// produce the body here for metadata output of divisions - in the case of
-      // text output, that will happen below...
-      if (!this.currentIndexField.equals("text")) 
-      { METSDescriptive descriptive;
-	
-	METSDivision division = (METSDivision) structure;
-
-	String metadataId = division.getDefaultMetadataReference();
-	    
-	descriptive = metsDoc.getDocumentMetadata().getDescriptiveById(metadataId);
-	if (descriptive != null) {
-	  List values = descriptive.getMetadata(namespace, this.currentIndexField);
+		if (descriptive != null) {
+		    List values = descriptive.getMetadata(namespace, this.currentIndexField);
 	  
-	  if (values != null) {	
-	    Iterator valueIter = values.iterator();
-	    while (valueIter.hasNext()) {
-	      String value = valueIter.next().toString();
+		    if (values != null) {	
+			Iterator valueIter = values.iterator();
+			while (valueIter.hasNext()) {
+			    String value = valueIter.next().toString();
 	      
-	      textBuffer.append(value);
-	      if (valueIter.hasNext()) {
-		  //textBuffer.append(END_OF_SECTION);
-	      }
-	    }
-	  }
-	}
-      }
-    }
-
-    // go through our children as required...
-    Iterator children = structure.getChildIterator();
-    Node startNode;
-    while (children.hasNext()) {
-      AbstractStructure child = (AbstractStructure) children.next();
+			    textBuffer.append(value);
+			    if (valueIter.hasNext()) {
+				//textBuffer.append(END_OF_SECTION);
+			    }
+			}
+		    }
+		}
+	    }
+	}
+
+	// go through our children as required...
+	Iterator children = structure.getChildIterator();
+	Node startNode;
+	while (children.hasNext()) {
+	    AbstractStructure child = (AbstractStructure) children.next();
       
-      // get xpointer for child 
-      // get start position node
-      if (metsDoc.getDocumentType() == "METS"){
-	  startNode = ((METSDocument) metsDoc).getSectionStartNode((METSDivision) child);	  
-      } else {
-	  startNode = ((HTMLDocument) metsDoc).getSectionStartNode((METSDivision) child);
-      }
+	    // get xpointer for child 
+	    // get start position node
+	    if (metsDoc.getDocumentType() == "METS"){
+		startNode = ((METSDocument) metsDoc).getSectionStartNode((METSDivision) child);	  
+	    } else {
+		startNode = ((HTMLDocument) metsDoc).getSectionStartNode((METSDivision) child);
+	    }
 	    //Node startNode = ((HTMLDocument) metsDoc).getSectionStartNode((METSDivision) child);
       
-      // while this node isn't the child's start node, produce the HTML node text, if
-      // in text field mode...
-      if (this.currentIndexField.equals("text")) {
-	while (node != startNode) {
-	  XPointer.printNode(node, textBuffer, false);
-
-	  // print buffer to node
-	  node = XPointer.getNextNode(node, (this.currentIndexField.equals("text") ? textBuffer : null));
-	}
-      }
+	    // while this node isn't the child's start node, produce the HTML node text, if
+	    // in text field mode...
+	    if (this.currentIndexField.equals("text")) {
+		while (node != startNode) {
+		    XPointer.printNode(node, textBuffer, false);
+
+		    // print buffer to node
+		    node = XPointer.getNextNode(node, (this.currentIndexField.equals("text") ? textBuffer : null));
+		}
+	    }
       
-      // recurse to child
-      node = this.recurseDOM(metsDoc, node, child, textBuffer, extraBuffer, namespace); // name, namespace, field);
-    } // while next child
-
-    // close a document - the actual closing \B will be done by the main
-    // loop, so only a required \C is printed here...
-    if (structure.getStructureType().equals(METSStructure.STRUCTURE_TYPE)) {
-      while (node != null) {
-	if (this.currentIndexField.equals("text")) {
-	  XPointer.printNode(node, textBuffer, false);
-	}
-	node = XPointer.getNextNode(node, (this.currentIndexField.equals("text") ? textBuffer : null));
-      }
+	    // recurse to child
+	    node = this.recurseDOM(metsDoc, node, child, textBuffer, extraBuffer, namespace); // name, namespace, field);
+	} // while next child
+
+	// close a document - the actual closing \B will be done by the main
+	// loop, so only a required \C is printed here...
+	if (structure.getStructureType().equals(METSStructure.STRUCTURE_TYPE)) {
+	    while (node != null) {
+		if (this.currentIndexField.equals("text")) {
+		    XPointer.printNode(node, textBuffer, false);
+		}
+		node = XPointer.getNextNode(node, (this.currentIndexField.equals("text") ? textBuffer : null));
+	    }
       
-      //textBuffer.append(END_OF_SECTION);
-      this.sectionSeqNo ++;
+	    //textBuffer.append(END_OF_SECTION);
+	    this.sectionSeqNo ++;
       
-    }
-    return node;
+	}
+	return node;
     }
 
     private String prepareDOM(DocumentInterface metsDoc, Document document, METSStructure structure, String namespace)
-    //  String name, String namespace, String field)
-  { StringBuffer extraBuffer = new StringBuffer();
-    Node node = document.getDocumentElement();
-    StringBuffer textBuffer = new StringBuffer();
-
-    this.recurseDOM(metsDoc, node, structure, textBuffer, extraBuffer, namespace); //name, namespace, field);
-    textBuffer.append(extraBuffer.toString());
-    return textBuffer.toString();
-  }
-
-  /**
-   *  Index a single document; the document interface can be used to extract individual
-   *  metadata items etc. as required or desired and index those instead or as well as
-   *  the body text of the document.
-   */
+    {
+	//  String name, String namespace, String field)
+	StringBuffer extraBuffer = new StringBuffer();
+	Node node = document.getDocumentElement();
+	StringBuffer textBuffer = new StringBuffer();
+	
+	this.recurseDOM(metsDoc, node, structure, textBuffer, extraBuffer, namespace); //name, namespace, field);
+	textBuffer.append(extraBuffer.toString());
+	return textBuffer.toString();
+    }
+
+    /**
+     *  Index a single document; the document interface can be used to extract individual
+     *  metadata items etc. as required or desired and index those instead or as well as
+     *  the body text of the document.
+     */
     public boolean indexDocument(DocumentID docID, DocumentInterface document)
     {
@@ -405,14 +412,14 @@
 	
 	this.indexBuffer.append(docText);
-    // remember that we're not on the first document, 
-    this.firstDocument = false;
-    // assign the sequence number on the first pass only, and increment the sequence number.
-    if (this.pass == 0) {
-	document.addDocumentMetadata("gsdl3", "mgseqno", this.overallName+"."+Integer.toString(startSeqNo));
-    }
-    this.documentSeqNo += 1;
-
-    return true;
-  }
+	// remember that we're not on the first document, 
+	this.firstDocument = false;
+	// assign the sequence number on the first pass only, and increment the sequence number.
+	if (this.pass == 0) {
+	    document.addDocumentMetadata("gsdl3", "mgseqno", this.overallName+"."+Integer.toString(startSeqNo));
+	}
+	this.documentSeqNo += 1;
+
+	return true;
+    }
 
     /**
@@ -646,8 +653,10 @@
      */
     public int getNumberOfPasses()
-    { return 2 + this.indexes.size() * 2;
-    }
-
-    public boolean addServiceDescriptions(org.w3c.dom.Element service_rack_list) {
+    { 
+	return 2 + this.indexes.size() * 2;
+    }
+
+    public boolean addServiceDescriptions(org.w3c.dom.Element service_rack_list)
+    {
 	Document doc = service_rack_list.getOwnerDocument();
 
