Index: /OAIHarvester/trunk/OAIHarvester/src/test/java/eu/clarin/cmdi/oai/harvester/HarvesterTest.java
===================================================================
--- /OAIHarvester/trunk/OAIHarvester/src/test/java/eu/clarin/cmdi/oai/harvester/HarvesterTest.java	(revision 1905)
+++ /OAIHarvester/trunk/OAIHarvester/src/test/java/eu/clarin/cmdi/oai/harvester/HarvesterTest.java	(revision 1906)
@@ -8,4 +8,5 @@
 import java.util.Date;
 import java.util.List;
+import java.util.Properties;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
@@ -17,4 +18,8 @@
 import javax.xml.stream.XMLStreamWriter;
 
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+
 import eu.clarin.cmdi.oai.harvester.impl.SimpleHarvester;
 import eu.clarin.cmdi.oai.harvester.util.XMLStreamCopier;
@@ -24,13 +29,17 @@
     private static XMLOutputFactory factory =
         XMLOutputFactory.newInstance();
+    private static final DateTimeFormatter fmt =
+            ISODateTimeFormat.basicDateTimeNoMillis().withZoneUTC();
 
     private static class MyHarvestHandler extends HarvestHandlerAdapter {
         private ZipOutputStream output;
+        private boolean saveHeader;
         private int reqNum;
         private String prefix;
         private byte[] buffer = new byte[8192];
 
-        public MyHarvestHandler(File file) {
+        public MyHarvestHandler(File file, boolean saveHeader) {
             try {
+                this.saveHeader = saveHeader;
                 FileOutputStream fos = new FileOutputStream(file);
                 output = new ZipOutputStream(fos);
@@ -130,21 +139,47 @@
                 System.err.println("    Sets: " + header.getSets());
             }
-            String filename = header.getIdentifier();
-            filename = replaceBadChars(filename) + ".xml";
-            if (prefix != null) {
-                filename = replaceBadChars(prefix) + "/" + filename; 
-            }
             try {
-                ZipEntry entry = new ZipEntry(filename);
-                entry.setTime(header.getDatestamp().getTime());
-                output.putNextEntry(entry);
-                XMLStreamWriter writer =
-                    factory.createXMLStreamWriter(output);
-                XMLStreamCopier.copy(reader, writer);
-                writer.flush();
-                writer.close();
-                output.closeEntry();
-                output.flush();
-                reader.close();
+                if (!header.isDeleted()) {
+                    String filename = makeFileName(header.getIdentifier(),
+                            prefix, "xml");
+                    ZipEntry entry = new ZipEntry(filename);
+                    entry.setTime(header.getDatestamp().getTime());
+                    output.putNextEntry(entry);
+                    XMLStreamWriter writer =
+                            factory.createXMLStreamWriter(output);
+                    XMLStreamCopier.copy(reader, writer);
+                    writer.flush();
+                    writer.close();
+                    output.closeEntry();
+                    output.flush();
+                    reader.close();
+                }
+
+                if (saveHeader) {
+                    String filename = makeFileName(header.getIdentifier(),
+                            prefix, "oai");
+                    ZipEntry entry = new ZipEntry(filename);
+                    entry.setTime(header.getDatestamp().getTime());
+                    output.putNextEntry(entry);
+                    Properties props = new Properties();
+                    props.put("datestamp",
+                            fmt.print(new DateTime(header.getDatestamp())));
+                    if (header.isDeleted()) {
+                        props.put("isDeleted", "true");
+                    }
+                    if (header.getSets() != null) {
+                        StringBuilder sb = new StringBuilder();
+                        for (String set : header.getSets()) {
+                            if (sb.length() > 0) {
+                                sb.append(", ");
+                            }
+                            sb.append(set);
+                        }
+                        props.put("sets", sb.toString());
+                    }
+                    props.store(output, null);
+                    output.closeEntry();
+                    output.flush();
+                }
             } catch (Exception e) {
                 e.printStackTrace();
@@ -180,10 +215,37 @@
         }
 
-        private String replaceBadChars(String s) {
-            return s.replace(':', '_').replace('.', '_').replace('\\', '_')
-                    .replace('/', '_');
+        private static String makeFileName(String identifier, String prefix,
+                String extension) {
+            StringBuilder sb = new StringBuilder();
+            if (prefix != null) {
+                sanitizedAppend(sb, prefix);
+                sb.append('/');
+            }
+            sanitizedAppend(sb, identifier);
+            sb.append('.');
+            sb.append(extension);
+            return sb.toString();
+        }
+
+        private static void sanitizedAppend(StringBuilder sb, String s) {
+            for (int i = 0; i < s.length(); i++ ) {
+                char ch = s.charAt(i);
+                switch (ch) {
+                case ':':
+                    /* FALL-THROUGH */
+                case '.':
+                    /* FALL-THROUGH */
+                case '/':
+                    /* FALL-THROUGH */
+                case '\\':
+                    sb.append("_");
+                    break;
+                default:
+                    sb.append(ch);
+                }
+            }
         }
     };
-    
+
     public void run(String[] args) {
         if (args.length < 2) {
@@ -192,5 +254,6 @@
         }
         final String repos = args[0];
-        MyHarvestHandler handler = new MyHarvestHandler(new File(args[1]));
+        MyHarvestHandler handler =
+                new MyHarvestHandler(new File(args[1]), false);
 
         Harvester harvester = SimpleHarvester.newInstance();
