OFC Converter

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown OFC Converter

by igor4java-gfp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Marcelo,

I made some adjustments, just added some trim() call
because BB uses spaces to "format" the OFC file, so
the converter wasn't working.
Check if it still works with HSBC OFC file.

Regards,
Igor Regis


      Flickr agora em português. Você clica, todo mundo vê.
http://www.flickr.com.br/
package br.com.gfp.ofc.parser;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Conversor {
        public static void main(String args[]) throws Exception{
                File fileIn = new File("/home/igor/Desktop/extrato.ofc");
                File fileOut = new File("/home/igor/Desktop/extrato.xml");
                Conversor c = new Conversor();
                c.execute(fileIn,fileOut);
        }
        public void execute (File fileIn,File fileOut) throws Exception{
               
                String text = getText(fileIn);
                Map<String,String> tags = getClosedTags(text);
       
                //for(String tag: tags.values())
                // System.out.println(tag);
               
                writeOut(fileOut,text,tags);
        }
        /**
         * Write xml output
         * @param file
         * @param text
         * @param tags
         * @throws Exception
         */
        private void writeOut(File file, String text, Map<String,String> tags) throws Exception{
                FileWriter write = new FileWriter(file);
                StringTokenizer st = new StringTokenizer(text,"\n");
                while (st.hasMoreTokens()){
                        String line = st.nextToken();
                        if (line.trim().startsWith("</")){
                                write.write(line);
                        }else {
                                String tag = line.trim().substring(1,line.trim().indexOf(">"));
                System.out.println(tag);
                                if (tags.containsKey(tag)){
                                        write.write(line);
                                }else {
                                        write.write(line + "</" + tag+ ">");
                                }
                        }
                }
                write.close();
        }
        /**
         * Get all text
         * @param file
         * @return
         * @throws FileNotFoundException
         * @throws IOException
         */
        private String getText(File file) throws FileNotFoundException, IOException {
                FileReader reader = new FileReader(file);
                BufferedReader buffer = new BufferedReader(reader);
                StringBuffer sb = new StringBuffer();
                String line;
                while ((line = buffer.readLine()) !=null)
                        sb.append(line + "\n");
               
                buffer.close();
                reader.close();
                return sb.toString();
        }
        /**
         * Find tags with closed tag
         * @param text
         * @return
         */
        private Map<String,String> getClosedTags(String text) {
                Map<String,String> tags = new HashMap<String, String>();
                while (text.indexOf("<")>=0){
                        int ini = text.indexOf("<") +1;
                        int end  = text.indexOf(">",ini);
                        String tag = text.substring(ini, end);
                        if (tag.startsWith("/") && !tags.containsKey(tag))
                                tags.put(tag.substring(1), tag.substring(1));
                        text = text.substring(end +1);
                }
                return tags;
        }
}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
gfd-developers mailing list
gfd-developers@...
https://lists.sourceforge.net/lists/listinfo/gfd-developers

Re: OFC Converter

by Marcelo_Adamatti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Igor,

        See HSBC OFC sample. I created a XSLT to format the result in
browser. It is working ok for me!

[]s

Marcelo Adamatti
http://adamatti.googlepages.com 
http://adamatti.blogspot.com 
http://fumigant.googlecode.com/

-----Original Message-----
From: igor4java-gfp@... [mailto:igor4java-gfp@...]
Sent: Tuesday, September 04, 2007 8:38 AM
To: Adamatti, Marcelo
Cc: GFP List
Subject: OFC Converter

Hi Marcelo,

I made some adjustments, just added some trim() call because BB uses
spaces to "format" the OFC file, so the converter wasn't working.
Check if it still works with HSBC OFC file.

Regards,
Igor Regis



<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="extratoOFC.xslt"?>
<OFC>
<DTD>0</DTD>
<CPAGE>0000</CPAGE>
<ACCTSTMT>
<ACCTFROM>
<BANKID>000</BANKID>
<ACCTID>00000000000</ACCTID>
<ACCTTYPE>0</ACCTTYPE>
</ACCTFROM>
<STMTRS>
<DTSTART>20060101</DTSTART>
<DTEND>20060201</DTEND>
<LEDGER>10.00</LEDGER>
<STMTTRN>
<TRNTYPE>1</TRNTYPE>
<DTPOSTED>20060101</DTPOSTED>
<TRNAMT>-0.30</TRNAMT>
<FITID>0000000</FITID>
<CHKNUM>0000000</CHKNUM>
<MEMO>BALA DE GOMA</MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>1</TRNTYPE>
<DTPOSTED>20060101</DTPOSTED>
<TRNAMT>5.00</TRNAMT>
<FITID>0000000</FITID>
<CHKNUM>0000000</CHKNUM>
<MEMO>MESADA</MEMO>
</STMTTRN>
</STMTRS>
</ACCTSTMT>
</OFC>



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
gfd-developers mailing list
gfd-developers@...
https://lists.sourceforge.net/lists/listinfo/gfd-developers

sample.ofc (568 bytes) Download Attachment
Conversor.java (3K) Download Attachment
extratoOFC.xslt (6K) Download Attachment