*/
public void execute(ExecutionContext context) throws Exception {
XComponent xComponent = null;
XDesktop xdesktop = null;
IDossierDAO dossierDAO = null;
XBridge bridge = null;
String tempFolder = null;
ContextInstance contextInstance = null;
try {
logger.debug("Start execution");
contextInstance = context.getContextInstance();
logger.debug("Context Instance retrived " + contextInstance);
ProcessInstance processInstance = context.getProcessInstance();
Long workflowProcessId = new Long(processInstance.getId());
logger.debug("Workflow process id: " + workflowProcessId);
String dossierIdStr = (String) contextInstance.getVariable(DossierConstants.DOSSIER_ID);
logger.debug("Dossier id variable retrived " + dossierIdStr);
Integer dossierId = new Integer(dossierIdStr);
BIObject dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(dossierId);
logger.debug("Dossier retrived " + dossier);
dossierDAO = DAOFactory.getDossierDAO();
tempFolder = dossierDAO.init(dossier);
logger.debug("Path tmp folder dossier =" + tempFolder + " created.");
// gets the template file data
String templateFileName = dossierDAO.getPresentationTemplateFileName(tempFolder);
logger.debug("Template file name: " + templateFileName);
InputStream contentTempIs = dossierDAO.getPresentationTemplateContent(tempFolder);
logger.debug("InputStream opened on dossier template.");
byte[] contentTempBytes = GeneralUtilities.getByteArrayFromInputStream(contentTempIs);
logger.debug("DossierTemplateContent stored into a byte array.");
contentTempIs.close();
// write template content into a temp file
File templateFile = new File(tempFolder, templateFileName);
FileOutputStream fosTemplate = new FileOutputStream(templateFile);
fosTemplate.write(contentTempBytes);
fosTemplate.flush();
fosTemplate.close();
logger.debug("Dossier template content written into a temp file.");
// initialize openoffice environment
ConfigSingleton config = ConfigSingleton.getInstance();
SourceBean officeConnectSB = (SourceBean) config.getAttribute("DOSSIER.OFFICECONNECTION");
logger.debug("Office connection Sourcebean retrieved: " + officeConnectSB.toXML());
String host = (String) officeConnectSB.getAttribute("host");
String port = (String) officeConnectSB.getAttribute("port");
logger.debug("Office connection host: " + host);
logger.debug("Office connection port: " + port);
XComponentContext xRemoteContext = Bootstrap.createInitialComponentContext(null);
logger.debug("InitialComponentContext xRemoteContext created: " + xRemoteContext);
Object x = xRemoteContext.getServiceManager().createInstanceWithContext(
"com.sun.star.connection.Connector", xRemoteContext);
XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, x);
logger.debug("XConnector retrieved: " + xConnector);
XConnection connection = xConnector.connect("socket,host=" + host + ",port=" + port);
logger.debug("XConnection retrieved: " + connection);
x = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
xRemoteContext);
XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, x);
logger.debug("XBridgeFactory retrieved: " + xBridgeFactory);
// this is the bridge that you will dispose
bridge = xBridgeFactory.createBridge("", "urp", connection, null);
logger.debug("XBridge retrieved: " + bridge);
XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
// get the remote instance
x = bridge.getInstance("StarOffice.ServiceManager");
logger.debug("StarOffice.ServiceManager instance retrieved: " + x);
// Query the initial object for its main factory interface
XMultiComponentFactory xRemoteServiceManager = (XMultiComponentFactory) UnoRuntime.queryInterface(
XMultiComponentFactory.class, x);