CIB JCoMod technischer Leitfaden (DE)

5. Schneller Einstieg

5.1. JCoMod Wrapper-Beispiel für CIB format: Job zum Auswerten von RTF Feldinformationen über einen Analyse-Callback

Das nachfolgende Beispiel benutzt die CIB format Komponente um ein RTF Wurzeldokument inkl. dort abhängiger "includierter" Dokumente durchzuparsen und über einen Analyse-Callback der CIB format Komponente zu den in den Textbausteinen enthaltenen Feldinformationen jeweils Rückmeldungen zu geben.

Der Analyse-Callback liefert jeweils eine ID und einen zugehörigen String mit inhaltlichen Informationen.

import com.cib.comod.jobs.*;
import com.cib.comod.jobs.event.*;
 
import de.cib.util.trace.*;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
 
public class JComodTestCase extends TestCase {
    public static final String TESTPATH = "D:\\jcomod\\";
   
    public static void main(String[] args) {
        JComodTestCase test = new JComodTestCase();
        try {
            test.runTest();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    public static Test suite() {
        TestSuite suite = new TestSuite("JComod");
        suite.addTest(new JComodTestCase());
        return suite;
    }
    /* (non-Javadoc)
     * @see junit.framework.TestCase#runTest()
     */
    protected void runTest() throws Throwable {
        testFieldAnalyze();
    }
    public static void testFieldAnalyze() {
       ICibFormatCallbackListener listener = new JCibFormatCallbackAdapter() {
            public void callbackFormatOnField(FormatOnFieldCallbackEvent e) {
              System.out.println(""+e.FieldID+" "+e.FieldData);
                switch(e.FieldID) {
                    case 46: //Begin of REF field
                       break;
                    case 1046: //end of REF field
                     System.out.println("REF fieldname:"+e.FieldData);
                       break;
                    case 50: //Begin of MERGEFIELD field
                       break;
                    case 1050: //end of MERGEFIELD field
                      System.out.println("MERGEFIELD fieldname:"+e.FieldData);
                       break;
                    case 27: //Begin of INCLUDETEXT field
                       break;
                    case 1027: //end of INCLUDETEXT field
                      System.out.println("INCLUDETEXT fieldname:"+e.FieldData);
                       break;
                }
            }
        };
        //generate Job for CIB format DLL
        JCibFormatJob t_Job = new JCibFormatJob();
        //loads DLL
        if (!t_Job.initialize())
           return;
        //set callback type
       t_Job.executeFunction(ICibFormatJob.FUNCTION_ACTIVATECALLBACK, "FieldCallback");
       t_Job.addCibFormatCallbackListener(listener);
        //set rtf inputfile which should be analyzed
       t_Job.setProperty(ICibFormatJob.PROPERTY_INPUTFILE,"root.rtf");
        //activate, that includes should be analyzed as well
       t_Job.setProperty(ICibFormatJob.PROPERTY_INCLUDETEXT,"1");
        //set workspace, where included rtfs can be found
       t_Job.setProperty(ICibFormatJob.PROPERTY_WORKSPACE,TESTPATH+           "./templates");
        t_Job.execute();
        //Fehlerbehandlung
        int t_Error =
        ((Integer)t_Job.getProperty(ICibFormatJob.PROPERTY_ERROR)).intValue();         if (t_Error != 0) {
            // Fehler beim Ausführen des Jobs
            String t_Errortext = (String)
           t_Job.getProperty(ICibFormatJob.PROPERTY_ERRORTEXT);
            System.out.println("Fehler beim Ausführen: "+t_Error+"             "+t_Errortext);
        }
        t_Job.executeFunction(ICibFormatJob.FUNCTION_DEACTIVATECALLBACK,         "FieldCallback");
        t_Job.removeCibFormatCallbackListener(listener);
        t_Job.dispose();
    }
}