Project

General

Profile

1 3662 tao
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *    Purpose: To test the ReplicationServerList class by JUnit
6
 *    Authors: Jing Tao
7
 *
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26
27
package edu.ucsb.nceas.metacattest;
28
29
import edu.ucsb.nceas.metacat.*;
30
import edu.ucsb.nceas.metacat.client.Metacat;
31
import edu.ucsb.nceas.metacat.client.MetacatFactory;
32 4080 daigle
import edu.ucsb.nceas.metacat.service.PropertyService;
33 4701 daigle
import edu.ucsb.nceas.metacat.util.MetacatUtil;
34 3662 tao
import edu.ucsb.nceas.utilities.IOUtil;
35
import edu.ucsb.nceas.utilities.XMLUtilities;
36
//import edu.ucsb.nceas.morpho.framework.*;
37
import junit.framework.Test;
38
import junit.framework.TestCase;
39
import junit.framework.TestResult;
40
import junit.framework.TestSuite;
41
import org.apache.commons.logging.Log;
42
import org.apache.commons.logging.LogFactory;
43
import org.w3c.dom.Document;
44
import org.w3c.dom.Node;
45
import org.w3c.dom.NodeList;
46
47
import java.io.*;
48
import java.net.*;
49 3665 tao
import java.text.SimpleDateFormat;
50 3662 tao
import java.util.*;
51
52
53
/**
54
 * This class is used to change the data file location for IPCC eml documents.
55
 * Currently IPCC eml documents point data file ti SRB server. However, the srb
56
 * earthgrid is not very stable. We decided to change the online URL from srb to knb.
57
 * So this class will handle this case.
58
 * Before running this program, it needs:
59
 * 1. Downloaded data files from SRB
60
 * 2. A list of IPCC docid(with revision number) text file. If the text file is not available, it need
61
 * a metacat query file to search metacat to get the doicd list.
62
 * What the class will do:
63 3665 tao
 * 1. It will read the eml from Metacat.
64
 * 2. Get online URL information from eml document by DOM parser.
65
 * 3. Base on the URL information, this program will find the data file in
66
 *     the direcotry which contains the srb data file.
67
* 4. It will generate docid for the data file.
68
* 5. Upload the download srb data file to Metacat with assigned docid.
69
* 6. Modify the eml document with the new URL information (pointing to
70
 *     knb) and new version number in eml
71
 * 7. Update it to a new version in Metacat.
72
 * 8 . Go through above 7 steps for every eml document in the list.
73 3662 tao
 *
74
 */
75
public class UploadIPCCDataTest extends TestCase
76
{
77
78 3665 tao
79 4127 daigle
	  /* Initialize properties*/
80 3662 tao
	  static
81
	  {
82
		  try
83
		  {
84 4719 daigle
//			  PropertyService.getInstance("build/tests");
85
			  PropertyService.getInstance();
86 4701 daigle
			  MetacatUtil.pathsForIndexing
87
			         = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
88 3662 tao
		  }
89
		  catch(Exception e)
90
		  {
91
			  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
92
		  }
93
	  }
94
95
	  /**Constants*/
96 3696 tao
	  private static String SRBDATAFILEDIR = "/home/tao/data-file/IPCC"; // Dir for storing srb data file
97 3662 tao
	  private static String DOCLISTFILE       = "docidList"; // File name which stores IPCC document id
98
	  private static String METACATURL      = "http://chico.dyndns.org/knb/metacat";
99 3696 tao
	  private static String USERNAME          = "uid=dpennington,o=LTER,dc=ecoinformatics,dc=org";
100 3662 tao
	  private static String PASSWORD           = "password";
101 3665 tao
	  private static String TABLEONLINEURL= "/eml:eml/dataset/dataTable/physical/distribution/online/url";
102
	  private static String SPATIALONLINEURL = "/eml:eml/dataset/spatialRaster/physical/distribution/online/url";
103
	  private static String PACKAGEID               ="/eml:eml/@packageId";
104 3662 tao
	  private static String SRB                           = "srb://";
105 3665 tao
	  private static String KNB                           = "ecogrid://knb/";
106
	  private static String DATAIDPREFIX          = "IPCC";
107
	  private static String DOT                           = ".";
108
	  private static String SUCCESSLOG             = "update.log";
109
	  private static String ERRORLOG                = "error.log";
110 3694 tao
	  private static String CURRENT_CORRECTFILENAME = "correct_filename.csv";
111 3665 tao
	  private File log = new File(SUCCESSLOG);
112
	  private File error = new File (ERRORLOG);
113 3662 tao
114 3665 tao
115 3662 tao
	  /**
116
	   * Constructor to build the test
117
	   *
118
	   * @param name the name of the test method
119
	   */
120
	  public UploadIPCCDataTest(String name)
121
	  {
122
	    super(name);
123 3665 tao
124 3662 tao
	  }
125
126
127
	  /**
128
	   * Create a suite of tests to be run together
129
	   */
130
	  public static Test suite()
131
	  {
132
		   TestSuite suite = new TestSuite();
133 3696 tao
		   //suite.addTest(new UploadIPCCDataTest("modifyEMLDocsWithCorrectDataFileName"));
134
		   //suite.addTest(new UploadIPCCDataTest("modifyEMLDocsWithIncorrectDataFileName"));
135 3662 tao
		    return suite;
136
	 }
137
138
	  /**
139 3696 tao
	   * Modify EML Docs' data url online from SRB to ecogrid.
140
	   *Those eml docs pointe valide srb file names.
141
	   */
142
	  public void modifyEMLDocsWithCorrectDataFileName()
143
	  {
144
		  boolean originalDataFileIncorrect = false;
145
		  updateEML(originalDataFileIncorrect);
146
	  }
147
	  /**
148
	   * Modify EML Docs' data url online from SRB to ecogrid.
149
	   *Those eml docs pointe invalide srb file names.
150
	   */
151
	  public void modifyEMLDocsWithIncorrectDataFileName()
152
	  {
153
		  boolean originalDataFileIncorrect = true;
154
		  updateEML(originalDataFileIncorrect);
155
	  }
156
	  /*
157 3662 tao
	   * Upload the data file to Metacat and modify the eml documents
158
	   * @return
159
	   * @throws Exception
160
	   */
161 3696 tao
	  private void updateEML(boolean originalDataFileIncorrect)
162 3662 tao
	  {
163
164
		      // Get eml document first
165
			  Vector list = getDocumentList();
166
			  //If list is not empty, goes through every document by handleSingleEML method -
167
			  //1. It will read the eml from Metacat.
168
			  // 2. Get online URL information from eml document by DOM parser.
169
			  // 3. Base on the URL information, this program will find the data file in
170
			  // the direcotry which contains the srb data file.
171
			  // 4. It will generate docid for the data file
172 3665 tao
              // 5. At last upload the download srb data file to Metacat with assigned docid.
173
			  // 6. Modify the eml document with the new URL information (pointing to
174
			  // knb) and new version number in eml.
175
			  // 7.Update it to a new version in Metacat.
176
177 3662 tao
              if (list != null && !list.isEmpty())
178
              {
179
            	   int size = list.size();
180
            	   for (int i=0; i<size; i++)
181
            	   {
182
            		   String docid = null;
183
            		   try
184
            		   {
185
            			   docid = (String)list.elementAt(i);
186 3696 tao
            			   String dataId = handleSingleEML(docid, originalDataFileIncorrect);
187 3665 tao
            			   String message = "Successfully update eml "+docid + " with data id "+dataId;
188
            			   writeLog(log, message);
189 3662 tao
            		   }
190
            		   catch(Exception e)
191
            		   {
192
            			   System.err.println("Failed to handle eml document "+docid + " since "+
193
            					   e.getMessage());
194 3665 tao
            			   String message = "failed to update eml "+docid + "\n "+e.getMessage();
195
            			   writeLog(error, message);
196 3662 tao
            		   }
197
            	   }
198
              }
199
              else
200
              {
201
            	  System.err.println("There is no EML document to handle");
202
              }
203
204
	  }
205 3665 tao
206 3662 tao
	  /*
207
	   * Does actually job to upload data file and modify eml document for a given id.
208 3665 tao
	   * Here are its tasks:
209 3662 tao
	   * 1. It will read the eml from Metacat.
210
	   * 2. Get online URL information from eml document by DOM parser.
211
	   * 3. Base on the URL information, this program will find the data file in
212
	   *     the direcotry which contains the srb data file.
213
	   * 4. It will generate docid for the data file.
214 3665 tao
	   * 5. Upload the download srb data file to Metacat with assigned docid.
215
	   * 6. Modify the eml document with the new URL information (pointing to
216
	   *     knb) and new version number in eml
217
	   * 7. Update it to a new version in Metacat.
218
	   *
219 3662 tao
	   */
220 3696 tao
	  private String handleSingleEML(String docid,boolean originalDataFileIncorrect) throws Exception
221 3662 tao
	  {
222
		  Metacat metacat = MetacatFactory.createMetacatConnection(METACATURL);
223
		  // login metacat
224 3665 tao
		  String response = metacat.login(USERNAME, PASSWORD);
225
		  if (response.indexOf("<login>") == -1)
226 3662 tao
		  {
227 3665 tao
			  throw new Exception("login failed "+response);
228 3662 tao
		  }
229 3665 tao
		  // 1. Reads eml document from metacat
230 3662 tao
		  Reader r = metacat.read(docid);
231
          Document DOMdoc = XMLUtilities.getXMLReaderAsDOMDocument(r);
232 3665 tao
          Node rootNode = (Node)DOMdoc.getDocumentElement();
233 3662 tao
234 3665 tao
          //2.  Gets online url information. If onlineUrl is not SRB, through an exception
235
          String onlineUrl = getOnLineURL(rootNode);
236
          //System.out.println("=================The url is "+onlineUrl);
237 3662 tao
238 3665 tao
          //3. Find the srb data file
239
          String dataFileName = getDataFileNameFromURL(onlineUrl);
240 3696 tao
          //System.out.println("the data fileName in eml "+dataFileName);
241
          //If the dataFileName in original eml is wrong, we need to look up the
242
          // the correct name first
243
          if (originalDataFileIncorrect)
244
          {
245
        	  Hashtable correctName = getCurrent_CorrectFileNamesPair();
246
        	  dataFileName =(String) correctName.get(dataFileName);
247
          }
248 3665 tao
          //System.out.println("=================The data file is "+dataFileName);
249
          File dataFile = null;
250
          dataFile = new File(SRBDATAFILEDIR,dataFileName);
251
           if (!dataFile.exists())
252
           {
253
        	  throw new Exception("Couldn't find the data file in srb data directory "+dataFile);
254
          }
255
256
          //4. Generate docid for data file
257
          String dataId = generateId();
258
          //System.out.println("=======The docid for data file will be "+dataId);
259 3662 tao
260 3665 tao
          //5. upload data file to Metacat
261
          response = metacat.upload(dataId, dataFile);
262
          if (response.indexOf("<success>") == -1)
263
          {
264
        	  throw new Exception("Couldn't upload data file "+dataFileName +
265
        			  " with id "+dataId+ " into Metacat since "+response);
266
          }
267
268
          //6. Updates eml online url and package id in DOM
269
          String newId = updateEMLDoc(rootNode, docid, dataId);
270
          //System.out.println("The new docid is ========"+newId);
271
272
          //Put EML DOM with the new packagId and oneline url into a StringWriter and store it to String
273
          StringWriter stringWriter = new StringWriter();
274
          PrintWriter printWriter = new PrintWriter(stringWriter);
275
		  XMLUtilities.print(rootNode, printWriter);
276
		  String xml = stringWriter.toString();
277
		  //System.out.println("the xml is "+xml);
278
279
		  //7.insert new (update) EML document into Metacat
280
          StringReader xmlReader = new StringReader(xml);
281
          response = metacat.update(newId, xmlReader, null);
282
          if (response.indexOf("<success>") == -1)
283
          {
284
        	  throw new Exception("Upload data file "+dataFileName +
285
        			  " with id "+dataId+ " successfully but update eml "+newId +" failed since "+ response);
286
          }
287 3662 tao
          metacat.logout();
288 3665 tao
          return dataId;
289 3662 tao
	  }
290
291
	  /*
292
	   * Gets onlineUrl value from a given eml DOM document.
293
	   * The online url xpath can be "/eml/dataset/dataTable/physical/distribution/online/url"
294
	   * or "/eml/dataset/spatialRaster/physical/distribution/online/url"
295
	   */
296 3665 tao
	  private String getOnLineURL(Node root) throws Exception
297 3662 tao
	  {
298
		  String url = null;
299
		  if (root == null)
300
		  {
301
			  throw new Exception("root node for this EML is null and couldn't get online url from it");
302
		  }
303
		  Node urlNode = XMLUtilities.getTextNodeWithXPath(root, TABLEONLINEURL);
304
		  // in table online url does exist, we will try to use another xpath - SPATIALONLEURL
305
		  if (urlNode == null)
306
		  {
307
			  urlNode = XMLUtilities.getTextNodeWithXPath(root, SPATIALONLINEURL);
308
		  }
309
		  // Couldn't find any matche element, throw exception
310
		  if(urlNode == null)
311
		  {
312
			  throw new Exception("Couldn't find any onlie url information in eml document");
313
		  }
314
		  //Gets text node value and if the url doesn't contain "srb;//", it will throw a exception
315
		 url = urlNode.getNodeValue();
316
		 if (url == null || url.indexOf(SRB)== -1)
317
		 {
318
			 throw new Exception("The online url doesn't have srb protocol and we don't need to handle");
319
		 }
320
		  return url;
321
	  }
322 3665 tao
323
	  /*
324
	   * Automatically to generate a unique id for ddata file.
325
	   * This id will be looked like - DATAIDPREFIX.numberBaseonTime.1, e.g
326
	   * IPCC.20072321.1
327
	   */
328
	  private String generateId()
329
	  {
330
		  int version = 1;
331
		  StringBuffer docid = new StringBuffer(DATAIDPREFIX);
332
		  docid.append(DOT);
333
334
		  // Create a calendar to get the date formatted properly
335
		  String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
336
		  SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
337
		  pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);
338
		  pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
339
		  Calendar calendar = new GregorianCalendar(pdt);
340
		  Date trialTime = new Date();
341
		  calendar.setTime(trialTime);
342
343
			int time = 0;
344
345
			docid.append(calendar.get(Calendar.YEAR));
346
347
			time = calendar.get(Calendar.DAY_OF_YEAR);
348
			if(time < 10){
349
				docid.append("0");
350
				docid.append("0");
351
				docid.append(time);
352
			} else if(time < 100) {
353
				docid.append("0");
354
				docid.append(time);
355
			} else {
356
				docid.append(time);
357
			}
358
359
			time = calendar.get(Calendar.HOUR_OF_DAY);
360
			if(time < 10){
361
				docid.append("0");
362
				docid.append(time);
363
			} else {
364
				docid.append(time);
365
			}
366
367
			time = calendar.get(Calendar.MINUTE);
368
			if(time < 10){
369
				docid.append("0");
370
				docid.append(time);
371
			} else {
372
				docid.append(time);
373
			}
374
375
			time = calendar.get(Calendar.SECOND);
376
			if(time < 10){
377
				docid.append("0");
378
				docid.append(time);
379
			} else {
380
				docid.append(time);
381
			}
382
			 //sometimes this number is not unique, so we append a random number
383
			int random = (new Double(Math.random()*100)).intValue();
384
			docid.append(random);
385
			docid.append(DOT);
386
			docid.append(version);
387
388
			return docid.toString();
389
390
	  }
391
	  /*
392
	   * Get data file name from online url. SRB oneline url will looks like -
393
	   * srb://seek:/home/beam.seek/IPCC_climate/Present/ccld6190.dat.
394
	   * The last part - ccld6190.dat is the file name. This method will get
395
	   * the file name from the give url
396
	   */
397
	  private String getDataFileNameFromURL(String onlineUrl) throws Exception
398
	  {
399
		  String dataFile = null;
400
		  String slash = "/";
401
		  if (onlineUrl != null)
402
		  {
403
			  int index = onlineUrl.lastIndexOf(slash);
404
			  try
405
			  {
406
			     dataFile = onlineUrl.substring(index+1);
407
			  }
408
			  catch(Exception e)
409
			  {
410
				  throw new Exception("Couldn't get data file name from the given url "+onlineUrl+
411
						  " since "+e.getMessage());
412
			  }
413
		  }
414
		  return dataFile;
415
	  }
416
417
418 3662 tao
419
      /*
420
       * Gets eml document list from text file. The text file format should be:
421
       * tao.1.1
422
       * tao.2.1
423
       */
424
	  private Vector getDocumentListFromFile() throws Exception
425
	  {
426
		  Vector docList = new Vector();
427
		  File docListFile = new File(SRBDATAFILEDIR,DOCLISTFILE);
428
		  FileReader docListFileReader= new FileReader(docListFile);
429
		  BufferedReader readDocList = new BufferedReader(docListFileReader);
430
		  // Read every line from the text file and put it into a vector
431
		  String docid = readDocList.readLine();
432
		  while (docid != null)
433
		  {
434
			  // If the docid string is not empty, put it into vector
435
			  if (!docid.trim().equals(""))
436
			  {
437
			     docList.add(docid.trim());
438
			  }
439
			  docid = readDocList.readLine();
440
		  }
441
		  return docList;
442
	  }
443
444
	  /*
445 3665 tao
	   * Update the given eml document (in DOM). There are two places to be updated
446
	   * The package id will be increased 1, i.e.,  from 1 to 2. The distribution online url will
447
	   * point to the new ecogrid id, i.e. , ecogrid://knb/IPCC.2007.1
448
	   */
449
	  private String updateEMLDoc(Node root, String docid, String dataId) throws Exception
450
	  {
451
		  // update package id
452
		  docid = getIncreasedNewDocid(docid);
453
		  XMLUtilities.addAttributeNodeToDOMTree( root, PACKAGEID, docid);
454
	      // update online url.  oneline url should either in spatialRaster or dataTable.
455
		  // First try to see if spatialRaster exist or not. If not try data table
456
		  String newUrl = KNB+dataId; //new url looks like ecogrid://knb/IPCC.2007.1
457
		  boolean isSpatialRaster = true;
458
		  boolean isDataTable = false;
459
		  Node urlNode = XMLUtilities.getTextNodeWithXPath(root, SPATIALONLINEURL);
460
		  if (urlNode == null)
461
		  {
462
			  // has no spatialRaster
463
			 isSpatialRaster = false;
464
		  }
465
		  else
466
		  {
467
			  // has spatialRaster
468
			  isSpatialRaster = true;
469
		  }
470
		  // determin if has datable or not
471
		  urlNode = XMLUtilities.getTextNodeWithXPath(root,TABLEONLINEURL);
472
		  if (urlNode != null)
473
		  {
474
				 isDataTable = true;
475
		  }
476
477
		  if (isSpatialRaster && !isDataTable)
478
		  {
479
			 //only has spatialRaster and no dataTable, update spatialRaster online url
480
			  XMLUtilities.addTextNodeToDOMTree(root, SPATIALONLINEURL, newUrl);
481
		  }
482
		  else if (!isSpatialRaster && isDataTable)
483
		  {
484
              //only has dataTable and no spatialRaster, update dataTable online url
485
			  XMLUtilities.addTextNodeToDOMTree(root, TABLEONLINEURL, newUrl);
486
		  }
487
		  else
488
		  {
489
			  //some strange things happen
490
			  throw new Exception("The eml either has both dataTable or spatialRaster OR doesn't has any entity");
491
		  }
492
		  return docid;
493
	  }
494
495
	  /*
496
	   * Gets new docid with increased version. Docid looks like tao.1.1. The new docid will be
497
	   * tao.1.2.
498
	   */
499
	  private String getIncreasedNewDocid(String docid) throws Exception
500
	  {
501
		  int rev = 1;
502
		  String revision = null;
503
		  String prefix = null;
504
		  String newId = null;
505
		  if (docid != null)
506
		  {
507
			  int index = docid.lastIndexOf(DOT);
508
			  try
509
			  {
510
				 // Get revsion part(1)
511
			     revision = docid.substring(index+1);
512
			     // Get prefix part (tao.1.)
513
			     prefix    = docid.substring(0, index+1);
514
			     // increase version from 1 to 2
515
			     rev = (new Integer(revision)).intValue();
516
			     rev++;
517
			     // combines the prefix tao.1. and new revision2 to get tao.1.2
518
			     newId= prefix+rev;
519
520
			  }
521
			  catch(Exception e)
522
			  {
523
				  throw new Exception("Couldn't increase revsion number from the given docid "+docid+
524
						  " since "+e.getMessage());
525
526
			  }
527
		  }
528
		  return newId;
529
	  }
530
531
	  /*
532 3662 tao
	   * Gets eml document list from searching Metacat
533
	   * TO-DO: This method need to be implemented
534
	   */
535
	  private Vector getDocumentListFromMetacat()
536
	  {
537
		  Vector docList = new Vector();
538
		  return docList;
539
	  }
540
541
	  /*
542
	   * Get eml document list. First this method will try
543
	   * to get the eml document list form text file. If the result is empty or
544
	   * it caught an exception it will try to get eml document list from metacat.
545
	   */
546
	  private Vector getDocumentList()
547
	  {
548
		  Vector list = null;
549
		  try
550
		  {
551
			  //First, try to get eml doc list from text file
552
			  list = getDocumentListFromFile();
553
			  if (list == null || list.isEmpty())
554
			  {
555
				  throw new Exception("The eml doclist is empty in text file");
556
			  }
557
		  }
558
		  catch(Exception e)
559
		  {
560
			  System.err.println("Couldn't get eml document list from text file: "+e.getMessage());
561
			  // If an exception happened, try to get eml doc list from metacat
562
			  list = getDocumentListFromMetacat();
563
		  }
564
		  if (list != null)
565
		  {
566
			  System.out.println("the list is "+list);
567
		  }
568
		  return list;
569
	  }
570 3665 tao
571
	  /*
572
	   * Writes error message into log file.
573
	   */
574
	  private void writeLog(File file, String message)
575
	  {
576
	    try
577
	    {
578
	      FileOutputStream fos = new FileOutputStream(file, true);
579
	      PrintWriter pw = new PrintWriter(fos);
580
	      SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss");
581
	      java.util.Date localtime = new java.util.Date();
582
	      String dateString = formatter.format(localtime);
583
	      dateString += " :: " + message;
584
	      //time stamp each entry
585
	      pw.println(dateString);
586
	      pw.flush();
587
	      pw.close();
588
	      fos.close();
589
	    }
590
	    catch(Exception e)
591
	    {
592
	      System.out.println("error writing to replication log from " +
593
	                         "MetacatReplication.replLog: " + e.getMessage());
594
	      //e.printStackTrace(System.out);
595
	    }
596
	 }
597 3694 tao
598
	  /*
599
	   * Read a csv file which contains current data file name and correct data file name.
600
	   * The format of csv file is:
601
	   * currentname1,correctname1
602
	   * currentname2,correctname2
603
	   * ........
604
	   * The return value is hash table, the current data file name is key and correct file name is
605
	   * value.
606
	   */
607
	   private Hashtable getCurrent_CorrectFileNamesPair() throws Exception
608
	   {
609
		   Hashtable fileNamesHash = new Hashtable();
610
		   File current_correctFileNames = new File(CURRENT_CORRECTFILENAME);
611
		   FileReader fileReader= new FileReader(current_correctFileNames);
612
		   BufferedReader readDocList = new BufferedReader(fileReader);
613
		   // Read every line from the text file, this line will look like:
614
		   // currentname1,correctname1
615
		   String lineString = readDocList.readLine();
616
		   while (lineString != null)
617
		   {
618
			   //Get the comma index number
619
			   int commaIndex = lineString.indexOf(",");
620
			   if (commaIndex != -1)
621
			   {
622
			      //Get the current file name part
623
			      String currentName = lineString.substring(0, commaIndex);
624
			      //Get the correct file name part
625
			      String correctName = lineString.substring(commaIndex+1, lineString.length());
626
				  if (currentName != null && correctName != null)
627
				  {
628
					  fileNamesHash.put(currentName.trim(), correctName.trim());
629
				  }
630
			  }
631
			   lineString = readDocList.readLine();
632
		   }
633
		   return fileNamesHash;
634
	   }
635 3662 tao
}