Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java	(revision 6738)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java	(revision 7187)
@@ -28,4 +28,6 @@
  
   public static final String DIVISION_TYPE  = "Division";
+  public static final String DIVISION_TAG   = "div";
+  public static final String FPTR_TAG       = "fptr";
 
   public METSDivision(String ID, String order, String orderLabel, String userLabel, String type)
@@ -256,4 +258,11 @@
   }
 
+  /**
+   *  Get the parent division name.  Division identifiers
+   *  concatenate the ancestor's names with intervening
+   *  '.' characters.
+   *
+   *  @return <code>String</code> the division name
+   */
   public static String getParentName(String divisionName)
   { int at = divisionName.lastIndexOf('.');
@@ -265,4 +274,9 @@
   }
 
+  /**
+   *  Get the top division name.
+   *
+   *  @return <code>String</code> the division name
+   */
   public static String getTopDivisionName(String divisionName)
   { int at = divisionName.indexOf('.');
@@ -272,15 +286,16 @@
     }
     else
-    {	return divisionName;
-    }
-  }
-
-  /**
-   *  Write the METS file in an XML to a text-output sink
+    { return divisionName;
+    }
+  }
+
+  /**
+   *  Write the METS file in an XML to a text-output sink.
    *
    *  @param <code>PrintWriter</code> the destination of the output
    */
   public boolean write(PrintWriter writer)
-  { String tag = XMLTools.getOpenTag("mets", "div");
+  { // Get the main tag for the division
+    String tag = XMLTools.getOpenTag("mets", DIVISION_TAG);
     tag = XMLTools.addAttribute(tag, "ID", this.ID.toString());
     tag = XMLTools.addAttribute(tag, "TYPE", this.type);
@@ -292,27 +307,20 @@
     { tag = XMLTools.addAttribute(tag, "LABEL", this.userLabel);
     }
+
+    // Add a metadata reference attribute
+    if (this.metadataRefs.size() > 0)
+    { String metaList = this.writeList(this.metadataRefs);
+
+      tag = XMLTools.addAttribute(tag, "DMDID", metaList);
+    }
+
+    // write the central tag
     writer.println(tag);
 
     // write the list of file pointers for this structural element
     if (this.fileRefs.size() > 0)
-    { tag = XMLTools.getOpenTag("mets", "fptr");
-      
-      String fileList = this.writeList(this.fileRefs);
-
-      tag = XMLTools.addAttribute(tag, "FILEID", fileList);
-      
-      tag = XMLTools.makeSingleton(tag);
-      writer.println(tag);
-    }
-
-    // ..and then the metadata - this is the same code at present,
-    // but is replicated here in case of future amendment.
-    if (this.metadataRefs.size() > 0)
-    { tag = XMLTools.getOpenTag("mets", "mptr");
-
-      String metaList = this.writeList(this.metadataRefs);
-      tag = XMLTools.addAttribute(tag, "METAID", metaList);
-      tag = XMLTools.makeSingleton(tag);
-      writer.println(tag);
+    { String fileList = this.writeTagList("mets", "fptr", "FILEID", this.fileRefs);
+
+      writer.println(fileList);
     }
 
@@ -329,7 +337,27 @@
     
     // close the div element
-    writer.println(XMLTools.getCloseTag("mets", "div"));
+    writer.println(XMLTools.getCloseTag("mets", DIVISION_TAG));
 
     return true;
+  }
+
+  /**
+   *  A convenience method for writing a <code>List</code> as a series of tags...
+   */
+  private String writeTagList(String namespace, String tagname, 
+			      String attribute, List list)
+  { StringBuffer listString = new StringBuffer();
+      
+    Iterator iterator = list.iterator();
+    while (iterator.hasNext())
+    { String item = iterator.next().toString();
+
+      String tag = XMLTools.getOpenTag(namespace, tagname);
+      tag = XMLTools.addAttribute(tag, attribute, item);
+      tag = XMLTools.makeSingleton(tag);
+
+      listString.append(tag);
+    }
+    return listString.toString();
   }
 
@@ -343,7 +371,9 @@
     while (iterator.hasNext())
     { String item = iterator.next().toString();
-      if (listString.length() > 0)
-      { listString.append(" ");
-      }
+
+      if (listString.length() > 0) {
+	listString.append(" ");
+      }
+
       listString.append(item);
     }
