1   package org.kuali.ole.converter;
2   
3   import org.kuali.ole.pojo.bib.BibliographicRecord;
4   import org.marc4j.MarcReader;
5   import org.marc4j.MarcStreamReader;
6   import org.marc4j.MarcWriter;
7   import org.marc4j.MarcXmlWriter;
8   import org.marc4j.marc.Record;
9   
10  import java.io.*;
11  
12  
13  
14  
15  
16  
17  
18  
19  public class MarcXMLConverter {
20      
21  
22  
23  
24  
25      public String convertRawMarcToXML(File inputFile) throws FileNotFoundException {
26          InputStream input = new FileInputStream(inputFile);
27          String fileName = inputFile.getName().replace(".mrc", ".xml");
28          FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName));
29          MarcReader reader = new MarcStreamReader(input);
30          MarcWriter writer = new MarcXmlWriter(fileOutputStream, true);
31  
32          while (reader.hasNext()) {
33              Record record = reader.next();
34              writer.write(record);
35          }
36          writer.close();
37          return fileName;
38      }
39  
40  
41      
42  
43  
44  
45      public String convert(String content) {
46          ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
47          ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
48  
49          MarcReader reader = new MarcStreamReader(byteArrayInputStream);
50          MarcWriter writer = new MarcXmlWriter(byteArrayOutputStream, true);
51  
52          while (reader.hasNext()) {
53              Record record = reader.next();
54              writer.write(record);
55          }
56          writer.close();
57          return new String(byteArrayOutputStream.toByteArray());
58      }
59  
60      public void generateMarcBean(BibliographicRecord orderRecord) {
61  
62      }
63  }