protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
XInterface oObj = null;
XInterface oRowSet = null;
Object oConnection = null;
XJob Job = null;
log.println(" instantiate MailMerge service");
try {
oObj = (XInterface) ( (XMultiServiceFactory) Param.getMSF()).createInstance
("com.sun.star.text.MailMerge");
} catch (Exception e) {
throw new StatusException("Can't create object environment", e) ;
}
// <set some variables>
String cTestDoc = utils.getFullTestURL("MailMerge.sxw");
//cMailMerge_DocumentURL = cTestDoc
String cOutputURL = utils.getOfficeTemp( (XMultiServiceFactory) Param.getMSF());
String cDataSourceName = "Bibliography";
String cDataCommand = "biblio";
Object[] sel = new Object[2];
sel[0] = new int[2];
sel[1] = new int[5];
Object[] myBookMarks = new Object[2];
// </set some variables>
// <create XResultSet>
log.println("create a XResultSet");
try {
oRowSet = (XInterface) ( (XMultiServiceFactory) Param.getMSF()).createInstance
("com.sun.star.sdb.RowSet");
} catch (Exception e) {
throw new StatusException("Can't create com.sun.star.sdb.RowSet", e);
}
XPropertySet oRowSetProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, oRowSet);
XRowSet xRowSet = (XRowSet)
UnoRuntime.queryInterface(XRowSet.class, oRowSet);
try {
oRowSetProps.setPropertyValue("DataSourceName",cDataSourceName);
oRowSetProps.setPropertyValue("Command",cDataCommand);
oRowSetProps.setPropertyValue("CommandType", new Integer(CommandType.TABLE));
} catch (UnknownPropertyException e) {
throw new StatusException("Can't set properties on oRowSet", e);
} catch (PropertyVetoException e) {
throw new StatusException("Can't set properties on oRowSet", e);
} catch (IllegalArgumentException e) {
throw new StatusException("Can't set properties on oRowSet", e);
} catch (WrappedTargetException e) {
throw new StatusException("Can't set properties on oRowSet", e);
}
try {
xRowSet.execute();
} catch (SQLException e) {
throw new StatusException("Can't execute oRowSet", e);
}
XResultSet oResultSet = (XResultSet)
UnoRuntime.queryInterface(XResultSet.class, oRowSet);
// <create Bookmarks>
log.println("create bookmarks");
try {
XRowLocate oRowLocate = (XRowLocate) UnoRuntime.queryInterface(
XRowLocate.class, oResultSet);
oResultSet.first();
myBookMarks[0] = oRowLocate.getBookmark();
oResultSet.next();
myBookMarks[1] = oRowLocate.getBookmark();
} catch (SQLException e) {
throw new StatusException("Cant get Bookmarks", e);
}
// </create Bookmarks>
// <fill object with values>
log.println("fill MailMerge with default connection");
XPropertySet oObjProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, oObj);
try {
oObjProps.setPropertyValue("ActiveConnection", getLocalXConnection(Param));
oObjProps.setPropertyValue("DataSourceName", cDataSourceName);
oObjProps.setPropertyValue("Command", cDataCommand);
oObjProps.setPropertyValue("CommandType", new Integer(CommandType.TABLE));
oObjProps.setPropertyValue("OutputType", new Short(MailMergeType.FILE));
oObjProps.setPropertyValue("DocumentURL", cTestDoc);
oObjProps.setPropertyValue("OutputURL", cOutputURL);
oObjProps.setPropertyValue("FileNamePrefix", "Author");
oObjProps.setPropertyValue("FileNameFromColumn", new Boolean(false));
oObjProps.setPropertyValue("Selection", new Object[0]);
} catch (UnknownPropertyException e) {
throw new StatusException("Can't set properties on oObj", e);
} catch (PropertyVetoException e) {
throw new StatusException("Can't set properties on oObj", e);
} catch (IllegalArgumentException e) {
throw new StatusException("Can't set properties on oObj", e);
} catch (WrappedTargetException e) {
throw new StatusException("Can't set properties on oObj", e);
}
// </fill object with values>
// <create object relations>
Object[] vXJobArgs = new Object[4];
NamedValue[] vXJobArg0 = new NamedValue[8];
NamedValue[] vXJobArg1 = new NamedValue[7];
NamedValue[] vXJobArg2 = new NamedValue[10];
NamedValue[] vXJobArg3 = new NamedValue[0];
// first Arguments
vXJobArg0[0] = new NamedValue("DataSourceName", cDataSourceName);
vXJobArg0[1] = new NamedValue("Command", cDataCommand);
vXJobArg0[2] = new NamedValue("CommandType",new Integer(CommandType.TABLE));
vXJobArg0[3] = new NamedValue("OutputType",new Short(MailMergeType.FILE));
vXJobArg0[4] = new NamedValue("DocumentURL", cTestDoc);
vXJobArg0[5] = new NamedValue("OutputURL", cOutputURL);
vXJobArg0[6] = new NamedValue("FileNamePrefix", "Identifier");
vXJobArg0[7] = new NamedValue("FileNameFromColumn", new Boolean(true));
//second Arguments
vXJobArg1[0] = new NamedValue("DataSourceName", cDataSourceName);
vXJobArg1[1] = new NamedValue("Command", cDataCommand);
vXJobArg1[2] = new NamedValue("CommandType",new Integer(CommandType.TABLE));
vXJobArg1[3] = new NamedValue("OutputType",
new Short(MailMergeType.PRINTER));
vXJobArg1[4] = new NamedValue("DocumentURL", cTestDoc);
vXJobArg1[5] = new NamedValue("FileNamePrefix", "Author");
vXJobArg1[6] = new NamedValue("FileNameFromColumn", new Boolean(true));
// third Arguments
vXJobArg2[0] = new NamedValue("ActiveConnection", getLocalXConnection(Param));
vXJobArg2[1] = new NamedValue("DataSourceName", cDataSourceName);
vXJobArg2[2] = new NamedValue("Command", cDataCommand);
vXJobArg2[3] = new NamedValue("CommandType",new Integer(CommandType.TABLE));
vXJobArg2[4] = new NamedValue("OutputType",
new Short(MailMergeType.FILE));
vXJobArg2[5] = new NamedValue("ResultSet", oResultSet);
vXJobArg2[6] = new NamedValue("OutputURL", cOutputURL);
vXJobArg2[7] = new NamedValue("FileNamePrefix", "Identifier");
vXJobArg2[8] = new NamedValue("FileNameFromColumn", new Boolean(true));
vXJobArg2[9] = new NamedValue("Selection", myBookMarks);
vXJobArgs[0] = vXJobArg0;
vXJobArgs[1] = vXJobArg1;
vXJobArgs[2] = vXJobArg2;
vXJobArgs[3] = vXJobArg3;
Job = (XJob) UnoRuntime.queryInterface(XJob.class, oObj);
try{
Job.execute(vXJobArg2);
} catch ( IllegalArgumentException e){
System.out.println(e.toString());
} catch ( Exception e){
System.out.println(e.toString());
}