01: package com.calipso.reportgenerator.reportmanager;
02:
03: /**
04: * Resuelce la conexion con el Open Office
05: */
06:
07: import com.sun.star.uno.XComponentContext;
08: import com.sun.star.uno.UnoRuntime;
09: import com.sun.star.lang.XMultiComponentFactory;
10: import com.sun.star.bridge.XUnoUrlResolver;
11: import com.sun.star.beans.XPropertySet;
12: import com.sun.star.comp.helper.Bootstrap;
13: import com.calipso.reportgenerator.common.LanguageTraslator;
14: import com.calipso.reportgenerator.common.InfoException;
15:
16: public class OOConnectionManager {
17:
18: private XComponentContext xRemoteContext;
19: private String unoUrl;
20:
21: public OOConnectionManager(String unoUrl) {
22: this .unoUrl = unoUrl;
23: xRemoteContext = null;
24: }
25:
26: public XComponentContext getConnection() throws InfoException {
27: if (xRemoteContext == null) {
28: try {
29: XComponentContext xLocalContext = Bootstrap
30: .createInitialComponentContext(null);
31: XMultiComponentFactory xLocalServiceManager = xLocalContext
32: .getServiceManager();
33: Object urlResolver = xLocalServiceManager
34: .createInstanceWithContext(
35: "com.sun.star.bridge.UnoUrlResolver",
36: xLocalContext);
37: XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime
38: .queryInterface(XUnoUrlResolver.class,
39: urlResolver);
40:
41: Object initialObject = xUnoUrlResolver.resolve(unoUrl);
42: XPropertySet xPropertySet = (XPropertySet) UnoRuntime
43: .queryInterface(XPropertySet.class,
44: initialObject);
45: Object context = xPropertySet
46: .getPropertyValue("DefaultContext");
47: xRemoteContext = (XComponentContext) UnoRuntime
48: .queryInterface(XComponentContext.class,
49: context);
50: } catch (Exception e) {
51: throw new InfoException(LanguageTraslator
52: .traslate("273"), e);
53: }
54: }
55: return xRemoteContext;
56: }
57: }
|