CIB JCoMod technical documentation (EN)
5. Quick start
5.1. JCoMod Wrapper example for CIB format: Job to evaluate RTF field information via an analysis callback
The following example uses the CIB format component to parse through an RTF root document including the dependent "included" documents and to provide feedback on the field information contained in the text modules via an analysis callback of the CIB format component.
The analysis callback returns an ID and a corresponding string with content information.
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();
}
}