01: package br.com.gfp.ofc.tools;
02:
03: import java.io.BufferedReader;
04: import java.io.File;
05: import java.io.FileNotFoundException;
06: import java.io.FileReader;
07: import java.io.IOException;
08:
09: /**
10: * This class converts a SGML OFX file to a XML with closing tags.
11: * Most of its functionality cames from OFCConversor. Only the file
12: * loading is different, as it bypass the OFX file header.
13: *
14: * @author Igor Regis da Silva Simoes
15: * @since 06/09/2007
16: */
17: public class OFXConversor extends OFCConversor {
18: /**
19: * For test only
20: * @param args
21: * @throws Exception
22: */
23: public static void main(String args[]) throws Exception {
24: File fileIn = new File("/home/igor/Desktop/extrato.ofx");
25: File fileOut = new File("/home/igor/Desktop/extrato.xml");
26: OFXConversor c = new OFXConversor();
27: c.execute(fileIn, fileOut);
28: }
29:
30: /**
31: * Load the file as a String
32: *
33: * @param file
34: * @return
35: * @throws FileNotFoundException
36: * @throws IOException
37: */
38: @Override
39: protected String getText(File file) throws FileNotFoundException,
40: IOException {
41: FileReader reader = new FileReader(file);
42: BufferedReader buffer = new BufferedReader(reader);
43: StringBuffer sb = new StringBuffer();
44: String line;
45: boolean passedHeader = false;
46: while ((line = buffer.readLine()) != null) {
47: if (!passedHeader)//We will start to "load" the file when we find the <OFX> tag
48: if (!(passedHeader = line.toUpperCase()
49: .indexOf("<OFX>") != -1))
50: continue;
51: sb.append(line + "\n");
52: }
53:
54: buffer.close();
55: reader.close();
56: return sb.toString().replace('&', 'e');
57: }
58: }
|