/** Create a new <code>ConfigurationDialogBase</code> */ public ConfigurationDialogBase(XComponentContext xContext) { this.xContext = xContext; // Get the file picker filePicker = new FilePicker(xContext); // Get the SimpleFileAccess service try { Object sfaObject = xContext .getServiceManager() .createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", xContext); sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject); } catch (com.sun.star.uno.Exception e) { // failed to get SimpleFileAccess service (should not happen) } // Create the config file name try { Object psObject = xContext .getServiceManager() .createInstanceWithContext("com.sun.star.util.PathSubstitution", xContext); xPathSub = (XStringSubstitution) UnoRuntime.queryInterface(XStringSubstitution.class, psObject); sConfigFileName = xPathSub.substituteVariables("$(user)/" + getConfigFileName(), false); } catch (com.sun.star.uno.Exception e) { // failed to get PathSubstitution service (should not happen) } // Create the configuration config = ConverterFactory.createConverter(getMIMEType()).getConfig(); }
public void addLabelForPopupMenu() { try { String sName = "lblPopup"; Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical // order! xFTModelMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, new Object[] { Integer.valueOf(8), "Right-click here", sName, Integer.valueOf(50), Integer.valueOf(50), Integer.valueOf(100) }); // add the model to the NameContainer of the dialog model m_xDlgModelNameContainer.insertByName(sName, oFTModel); XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName)); xWindow.addMouseListener(this); } catch (Exception e) { System.err.println(e + e.getMessage()); e.printStackTrace(); } }
/** get draw page by index */ public static XDrawPage getDrawPageByIndex(XComponent xComponent, int nIndex) throws com.sun.star.lang.IndexOutOfBoundsException, com.sun.star.lang.WrappedTargetException { XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, xComponent); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); return (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex(nIndex)); }
public static XMultiServiceFactory connect(String sConnectStr) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException, Exception { // Get component context XComponentContext xComponentContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null); // initial serviceManager XMultiComponentFactory xLocalServiceManager = xComponentContext.getServiceManager(); // create a connector, so that it can contact the office Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xComponentContext); XUnoUrlResolver xUrlResolver = UnoRuntime.queryInterface(XUnoUrlResolver.class, oUrlResolver); Object oInitialObject = xUrlResolver.resolve(sConnectStr); XNamingService xName = UnoRuntime.queryInterface(XNamingService.class, oInitialObject); XMultiServiceFactory xMSF = null; if (xName != null) { System.err.println("got the remote naming service !"); Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager"); xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, oMSF); } else System.out.println("Error: Can't get XNamingService interface from url resolver!"); return xMSF; }
/** * @descr Connect to a already running LibreOffice application that has been started with a * command line argument like "--accept=socket,host=localhost,port=5678;urp;" */ private void connect(String hostname, int portnumber) { mbInitialized = true; // Set up connection string. String sConnectString = "uno:socket,host=" + hostname + ",port=" + portnumber + ";urp;StarOffice.ServiceManager"; // connect to a running office and get the ServiceManager try { // Create a URL Resolver. XMultiServiceFactory aLocalServiceManager = com.sun.star.comp.helper.Bootstrap.createSimpleServiceManager(); XUnoUrlResolver aURLResolver = UnoRuntime.queryInterface( XUnoUrlResolver.class, aLocalServiceManager.createInstance("com.sun.star.bridge.UnoUrlResolver")); maServiceManager = UnoRuntime.queryInterface( XMultiServiceFactory.class, aURLResolver.resolve(sConnectString)); } catch (Exception e) { MessageArea.println("Could not connect with " + sConnectString + " : " + e); MessageArea.println( "Please start LibreOffice with " + "\"--accept=socket,host=localhost,port=5678;urp;\""); } }
public void showInfoBoxMessage( String Title, String Message, String type) { // type can be: infobox, XComponent xComponent = null; try { Object oToolkit = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.Toolkit", xComponentContext); XWindowPeer xParentWindowPeer = ((XToolkit) UnoRuntime.queryInterface(XToolkit.class, oToolkit)).getDesktopWindow(); XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); // rectangle may be empty if position is in the center of the parent peer Rectangle aRectangle = new Rectangle(); XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox( xParentWindowPeer, aRectangle, type, com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, Title, Message); xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox); if (xMessageBox != null) { short nResult = xMessageBox.execute(); } } catch (Exception ex) { SpeechOO.logger = org.apache.log4j.Logger.getLogger(TrainingDialog.class.getName()); SpeechOO.logger.error(ex); } finally { // make sure always to dispose the component and free the memory! if (xComponent != null) { xComponent.dispose(); } } }
/** * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted to the text document, * and finally endnote settings are gotten from text document using <code>XEndnotesSupplier</code> * interface. */ @Override public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception { XEndnotesSupplier oInterface = null; XInterface oObj = null; XInterface oEndnote; log.println("Creating a test environment"); XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); log.println("creating a endnote"); oEndnote = UnoRuntime.queryInterface( XInterface.class, msf.createInstance("com.sun.star.text.Endnote")); XText oText = xTextDoc.getText(); XTextCursor oCursor = oText.createTextCursor(); log.println("inserting the footnote into text document"); XTextContent xTC = UnoRuntime.queryInterface(XTextContent.class, oEndnote); oText.insertTextContent(oCursor, xTC, false); oInterface = UnoRuntime.queryInterface(XEndnotesSupplier.class, xTextDoc); oObj = oInterface.getEndnoteSettings(); dbg.printPropertiesNames((XPropertySet) oObj); TestEnvironment tEnv = new TestEnvironment(oObj); return tEnv; }
/* ------------------------------------------------------------------ */ private boolean ensureDataSource() throws Exception { m_orb = (XMultiServiceFactory) param.getMSF(); XNameAccess databaseContext = UnoRuntime.queryInterface( XNameAccess.class, m_orb.createInstance("com.sun.star.sdb.DatabaseContext")); XNamingService namingService = UnoRuntime.queryInterface(XNamingService.class, databaseContext); // revoke the data source, if it previously existed if (databaseContext.hasByName(m_dataSourceName)) namingService.revokeObject(m_dataSourceName); // // create a new ODB file, and register it with its URL m_databaseDocument = new HsqlDatabase(m_orb); String documentURL = m_databaseDocument.getDocumentURL(); namingService.registerObject(m_dataSourceName, databaseContext.getByName(documentURL)); m_dataSource = UnoRuntime.queryInterface(XDataSource.class, databaseContext.getByName(m_dataSourceName)); m_dataSourceProps = dbfTools.queryPropertySet(m_dataSource); XPropertySet dataSourceSettings = UnoRuntime.queryInterface( XPropertySet.class, m_dataSourceProps.getPropertyValue("Settings")); dataSourceSettings.setPropertyValue("FormsCheckRequiredFields", new Boolean(false)); return m_dataSource != null; }
private void saveDoc(XInterface xDoc, String sURL) { m_aLog.log(Protocol.TYPE_SCOPE_OPEN, "saveDoc('" + sURL + "') started ..."); try { URL[] aURL = new URL[1]; aURL[0] = new URL(); aURL[0].Complete = ".uno:SaveAs"; m_xURLParser.parseStrict(aURL); XModel xModel = UnoRuntime.queryInterface(XModel.class, xDoc); XDispatchProvider xProvider = UnoRuntime.queryInterface(XDispatchProvider.class, xModel.getCurrentController()); XDispatch xDispatch = xProvider.queryDispatch(aURL[0], "_self", 0); PropertyValue[] lArgs = new PropertyValue[3]; lArgs[0] = new PropertyValue(); lArgs[0].Name = "URL"; lArgs[0].Value = sURL; lArgs[1] = new PropertyValue(); lArgs[1].Name = "Overwrite"; lArgs[1].Value = Boolean.TRUE; lArgs[2] = new PropertyValue(); lArgs[2].Name = "StoreTo"; lArgs[2].Value = Boolean.TRUE; xDispatch.dispatch(aURL[0], lArgs); m_aLog.log(Protocol.TYPE_OK, "saveDoc('" + sURL + "') = OK."); } catch (Throwable ex) { m_aLog.log(ex); } m_aLog.log(Protocol.TYPE_SCOPE_CLOSE, "saveDoc('" + sURL + "') finished."); }
// converts an ODT document into a PDF file public void convert(OOoInputStream input, OOoOutputStream output, String filterName) throws Exception { XMultiComponentFactory xMultiComponentFactory = xComponentContext.getServiceManager(); Object desktopService = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.frame.Desktop", xComponentContext); XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktopService); PropertyValue[] conversionProperties = new PropertyValue[2]; conversionProperties[0] = new PropertyValue(); conversionProperties[1] = new PropertyValue(); conversionProperties[0].Name = "InputStream"; conversionProperties[0].Value = input; conversionProperties[1].Name = "Hidden"; conversionProperties[1].Value = true; XComponent document = xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0, conversionProperties); conversionProperties[0].Name = "OutputStream"; conversionProperties[0].Value = output; conversionProperties[1].Name = "FilterName"; conversionProperties[1].Value = filterName; XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); xstorable.storeToURL("private:stream", conversionProperties); XCloseable xclosable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document); xclosable.close(true); }
public static XControlShape createGrid(XComponent oDoc, int height, int width, int x, int y) { Size size = new Size(); Point position = new Point(); XControlShape oCShape = null; XControlModel aControl = null; // get MSF XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); try { Object oInt = oDocMSF.createInstance("com.sun.star.drawing.ControlShape"); Object aCon = oDocMSF.createInstance("com.sun.star.form.component.GridControl"); XPropertySet model_props = UnoRuntime.queryInterface(XPropertySet.class, aCon); model_props.setPropertyValue( "DefaultControl", "com.sun.star.form.control.InteractionGridControl"); aControl = UnoRuntime.queryInterface(XControlModel.class, aCon); oCShape = UnoRuntime.queryInterface(XControlShape.class, oInt); size.Height = height; size.Width = width; position.X = x; position.Y = y; oCShape.setSize(size); oCShape.setPosition(position); } catch (com.sun.star.uno.Exception e) { // Some exception occurs.FAILED System.out.println("Couldn't create Grid" + e); throw new StatusException("Couldn't create Grid", e); } oCShape.setControl(aControl); return oCShape; } // finish createGrid
/** * Tests boTableInit and boTableRowPopulate * * @throws Exception */ public void testBoTableInit() throws Exception { AbstractDocument doc = new OpenOfficeDocument(); try { String strGroup = "*"; ZXBO objBO = zx.createBO("test/test"); objBO.setPKValue("12"); objBO.loadBO(); assertEquals("Activate Openoffice", zXType.rc.rcOK.pos, doc.activate().pos); assertEquals("Open test document", zXType.rc.rcOK.pos, doc.openDoc("c:/tmp/test.doc").pos); /** Get the placeholder table. */ Object objTable = doc.getTable(1, 1, zXType.wordSection.wsPage); assertEquals( "Setup the table", zXType.rc.rcOK.pos, doc.boTableInit(objTable, objBO, strGroup).pos); objTable = doc.getTable(1, 1, zXType.wordSection.wsPage); XTextTable xTable = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, objTable); XCellRange objRow = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, xTable); objRow = objRow.getCellRangeByName("A2:C2"); assertEquals( "Populate table row.", zXType.rc.rcOK.pos, doc.boTableRowPopulate(objRow, objBO, strGroup).pos); } finally { assertEquals("Close document", zXType.rc.rcOK.pos, doc.closeDoc(false).pos); } }
private void createStandardBag(boolean allowLazyAdding) { try { m_bag = null; final Object initArgs[] = { new NamedValue("AutomaticAddition", Boolean.valueOf(allowLazyAdding)) }; final String serviceName = "com.sun.star.beans.PropertyBag"; m_bag = UnoRuntime.queryInterface( XPropertyContainer.class, m_orb.createInstanceWithArguments(serviceName, initArgs)); if (m_bag == null) { fail("could not create a " + serviceName + " instance"); } m_set = UnoRuntime.queryInterface(XPropertySet.class, m_bag); m_access = UnoRuntime.queryInterface(XPropertyAccess.class, m_bag); final Object properties[][] = { {"BoolValue", Boolean.TRUE}, {"StringValue", ""}, {"IntegerValue", Integer.valueOf(3)}, {"InterfaceValue", m_bag} }; for (int i = 0; i < properties.length; ++i) { m_bag.addProperty((String) properties[i][0], PropertyAttribute.MAYBEVOID, properties[i][1]); } } catch (com.sun.star.uno.Exception e) { } }
public boolean checkStreamH( XStorage xParentStorage, String sPath, String sMediaType, boolean bCompressed, byte[] pBytes) { // open substream element first XStream xSubStream = null; try { XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xParentStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sPath, ElementModes.READ); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't open substream '" + sPath + "'!"); return false; } } catch (Exception e) { Error("Can't open substream '" + sPath + "', exception : " + e + "!"); return false; } boolean bResult = InternalCheckStream(xSubStream, sPath, sMediaType, bCompressed, pBytes, true); // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sPath)) return false; return bResult; }
public boolean WriteBytesToEncrStreamH( XStorage xStorage, String sStreamPath, String sMediaType, boolean bCompressed, byte[] pBytes, String sPass, boolean bCommit) { // open substream element XStream xSubStream = null; try { XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sStreamPath, ElementModes.WRITE, sPass); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamPath + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamPath + "', exception : " + e + "!"); return false; } if (!WriteBytesToStream(xSubStream, sStreamPath, sMediaType, bCompressed, pBytes)) return false; XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream); if (xTransact == null) { Error("Substream '" + sStreamPath + "', stream opened for writing must be transacted!"); return false; } if (bCommit) { try { xTransact.commit(); } catch (Exception e) { Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!"); return false; } } // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamPath)) return false; return true; }
/** * Makes a string unique by appending a numerical suffix. * * @param elementContainer The container the new element is going to be inserted to * @param elementName The name of the element */ public XTextComponent insertTextFrame(int posX, int posY, int width, String text) throws Exception { // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, "TextFrame"); // Create an editable text field control model Object oTextFrameModel = xMultiComponentFactoryDialogModel.createInstance("com.sun.star.text.TextFrame"); // Set the properties at the model XPropertySet xTextFramePropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTextFrameModel); xTextFramePropertySet.setPropertyValue("PositionX", new Integer(posX)); xTextFramePropertySet.setPropertyValue("PositionY", new Integer(posY)); xTextFramePropertySet.setPropertyValue("Height", new Integer(12)); xTextFramePropertySet.setPropertyValue("Width", new Integer(width)); xTextFramePropertySet.setPropertyValue("Text", (text != null) ? text : ""); xTextFramePropertySet.setPropertyValue("Name", uniqueName); // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, xTextFramePropertySet); // Reference the control by the unique name XControl xEditableTextFieldControl = xDialogContainer.getControl(uniqueName); return (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xEditableTextFieldControl); }
private XTextComponent insertTextField( int posX, int posY, int width, int height, String text, char echoChar) throws Exception { // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, "TextField"); // Create an editable text field control model Object oTextFieldModel = xMultiComponentFactoryDialogModel.createInstance("com.sun.star.awt.UnoControlEditModel"); // Set the properties at the model XPropertySet xTextFieldPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTextFieldModel); xTextFieldPropertySet.setPropertyValue("PositionX", new Integer(posX)); xTextFieldPropertySet.setPropertyValue("PositionY", new Integer(posY)); xTextFieldPropertySet.setPropertyValue("Height", new Integer(height)); xTextFieldPropertySet.setPropertyValue("Width", new Integer(width)); xTextFieldPropertySet.setPropertyValue("Text", (text != null) ? text : ""); xTextFieldPropertySet.setPropertyValue("Name", uniqueName); xTextFieldPropertySet.setPropertyValue("MultiLine", false); xTextFieldPropertySet.setPropertyValue("ReadOnly", false); if (echoChar != 0 && echoChar != ' ') { // Useful for password fields xTextFieldPropertySet.setPropertyValue("EchoChar", new Short((short) echoChar)); } // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, oTextFieldModel); // Reference the control by the unique name XControl xTextFieldControl = xDialogContainer.getControl(uniqueName); return (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xTextFieldControl); }
public XFixedText insertFixedText(int posX, int posY, int height, int width, String label) throws Exception { // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, "FixedText"); // Create a fixed text control model Object oFixedTextModel = xMultiComponentFactoryDialogModel.createInstance( "com.sun.star.awt.UnoControlFixedTextModel"); // Set the properties at the model XPropertySet xFixedTextPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFixedTextModel); xFixedTextPropertySet.setPropertyValue("PositionX", new Integer(posX)); xFixedTextPropertySet.setPropertyValue("PositionY", new Integer(posY + 2)); xFixedTextPropertySet.setPropertyValue("Height", new Integer(height)); xFixedTextPropertySet.setPropertyValue("Width", new Integer(width)); xFixedTextPropertySet.setPropertyValue("Label", (label != null) ? label : ""); xFixedTextPropertySet.setPropertyValue("Name", uniqueName); // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, oFixedTextModel); // Reference the control by the unique name XControl xFixedTextControl = xDialogContainer.getControl(uniqueName); return (XFixedText) UnoRuntime.queryInterface(XFixedText.class, xFixedTextControl); }
/** * Shows an messagebox * * @param _xParentWindowPeer the windowpeer of the parent window * @param _sTitle the title of the messagebox * @param _sMessage the message of the messagebox * @param _aType string which determines the message box type: * (infobox|warningbox|errorbox|querybox|messbox) * @param _aButtons MessageBoxButtons which buttons should be available on the message box */ public short showMessageBox( XWindowPeer _xParentWindowPeer, String _sTitle, String _sMessage, String _aType, int _aButtons) { short nResult = -1; XComponent xComponent = null; try { Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); // rectangle may be empty if position is in the center of the parent peer Rectangle aRectangle = new Rectangle(); XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox( _xParentWindowPeer, aRectangle, _aType, _aButtons, _sTitle, _sMessage); xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox); if (xMessageBox != null) { nResult = xMessageBox.execute(); } } catch (com.sun.star.uno.Exception ex) { ex.printStackTrace(System.out); } finally { // make sure always to dispose the component and free the memory! if (xComponent != null) { xComponent.dispose(); } } return nResult; }
/** * Test reads persist object from stream and compares properties of the object with properties of * persist object obtained from relation <code>'PersistObject'</code> * * <p>Has <b> OK </b> status if returned value isn't null and values of objects properties are * equal. * * <p> */ public void _readObject() { Object objWrite = tEnv.getObjRelation("PersistObject"); if (objWrite == null) { log.println("PersistObject not found in relations"); tRes.tested("readObject()", false); return; } // write the object try { XObjectOutputStream oStream = (XObjectOutputStream) tEnv.getObjRelation("StreamWriter"); oStream.writeObject((XPersistObject) objWrite); } catch (com.sun.star.io.IOException e) { log.println("Couldn't write object to stream"); e.printStackTrace(log); tRes.tested("readObject()", Status.skipped(false)); return; } Object objRead = null; try { objRead = oObj.readObject(); } catch (com.sun.star.io.IOException e) { log.println("Couldn't read object from stream"); e.printStackTrace(log); tRes.tested("readObject()", false); return; } if (objRead == null) { log.println("No object was read."); tRes.tested("readObject()", false); return; } XPropertySet props1 = null; XPropertySet props2 = null; props1 = UnoRuntime.queryInterface(XPropertySet.class, objRead); props2 = UnoRuntime.queryInterface(XPropertySet.class, objWrite); if (props1 == null) { log.println("Object read doesn't implement XPropertySet"); tRes.tested("readObject()", false); return; } if (props2 == null) { log.println("Object written doesn't implement XPropertySet"); tRes.tested("readObject()", false); return; } tRes.tested("readObject()", compareProperties(props1, props2)); }
public boolean WriteBytesToStream( XStream xStream, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes) { // get output stream of substream XOutputStream xOutput = xStream.getOutputStream(); if (xOutput == null) { Error("Can't get XOutputStream implementation from substream '" + sStreamName + "'!"); return false; } // get XTrucate implementation from output stream XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface(XTruncate.class, xOutput); if (xTruncate == null) { Error("Can't get XTruncate implementation from substream '" + sStreamName + "'!"); return false; } // write requested byte sequence try { xTruncate.truncate(); xOutput.writeBytes(pBytes); } catch (Exception e) { Error("Can't write to stream '" + sStreamName + "', exception: " + e); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("MediaType", sMediaType); xPropSet.setPropertyValue("Compressed", new Boolean(bCompressed)); } catch (Exception e) { Error("Can't set properties to substream '" + sStreamName + "', exception: " + e); return false; } // check size property of the stream try { long nSize = AnyConverter.toLong(xPropSet.getPropertyValue("Size")); if (nSize != pBytes.length) { Error("The 'Size' property of substream '" + sStreamName + "' contains wrong value!"); return false; } } catch (Exception e) { Error("Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e); return false; } return true; }
@Override public void run() { try { for (; ; ) { synchronized (this) { if (terminate) { break; } } Message msg = _iProtocol.readMessage(); Object obj = null; if (msg.isRequest()) { String oid = msg.getObjectId(); Type type = new Type(msg.getType()); int fid = msg.getMethod().getIndex(); if (fid == MethodDescription.ID_RELEASE) { _java_environment.revokeInterface(oid, type); remRefHolder(type, oid); if (msg.isSynchronous()) { sendReply(false, msg.getThreadId(), null); } continue; } obj = _java_environment.getRegisteredInterface(oid, type); if (obj == null && fid == MethodDescription.ID_QUERY_INTERFACE) { if (_xInstanceProvider == null) { sendReply( true, msg.getThreadId(), new com.sun.star.uno.RuntimeException("unknown OID " + oid)); continue; } else { UnoRuntime.setCurrentContext(msg.getCurrentContext()); try { obj = _xInstanceProvider.getInstance(oid); } catch (com.sun.star.uno.RuntimeException e) { sendReply(true, msg.getThreadId(), e); continue; } catch (Exception e) { sendReply( true, msg.getThreadId(), new com.sun.star.uno.RuntimeException(e.toString())); continue; } finally { UnoRuntime.setCurrentContext(null); } } } } _iThreadPool.putJob(new Job(obj, java_remote_bridge.this, msg)); } } catch (Throwable e) { dispose(e); } }
private void insertBookmark(XTextCursor crsr, String name, String content) throws com.sun.star.uno.Exception { XMultiServiceFactory xDocFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc); Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark"); XTextContent xBookmarkAsTextContent = UnoRuntime.queryInterface(XTextContent.class, xBookmark); crsr.setString(content); XNamed xBookmarkAsNamed = UnoRuntime.queryInterface(XNamed.class, xBookmark); xBookmarkAsNamed.setName(name); m_xDoc.getText().insertTextContent(crsr, xBookmarkAsTextContent, true); }
private void createEmptyBag() { try { m_bag = null; final String serviceName = "com.sun.star.beans.PropertyBag"; m_bag = UnoRuntime.queryInterface(XPropertyContainer.class, m_orb.createInstance(serviceName)); if (m_bag == null) { fail("could not create a " + serviceName + " instance"); } m_set = UnoRuntime.queryInterface(XPropertySet.class, m_bag); m_access = UnoRuntime.queryInterface(XPropertyAccess.class, m_bag); } catch (com.sun.star.uno.Exception e) { } }
public void _createNameGroup() { boolean result = true; try { XDataPilotField xDataPilotField = UnoRuntime.queryInterface(XDataPilotField.class, oObj); XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, xDataPilotField.getItems()); String[] elements = xNameAccess.getElementNames(); oObj.createNameGroup(elements); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("Exception while checking createNameGroup" + e); result = false; } tRes.tested("createNameGroup()", result); }
/** Closes connection of <code>RowSet</code> instance created. */ protected void cleanup(TestParameters Param, PrintWriter log) { String doing = null; try { doing = "revoking data source registration"; log.println(doing); m_dataSource.revokeRegistration(); doing = "closing database document"; log.println(doing); XModel databaseDocModel = UnoRuntime.queryInterface( XModel.class, m_dataSource.getDatabaseDocument().getDatabaseDocument()); String documentFile = databaseDocModel.getURL(); XCloseable closeModel = UnoRuntime.queryInterface( XCloseable.class, m_dataSource.getDatabaseDocument().getDatabaseDocument()); closeModel.close(true); if (m_rowSet != null) { doing = "disposing row set"; log.println(doing); XComponent rowSetComponent = UnoRuntime.queryInterface(XComponent.class, m_rowSet); rowSetComponent.dispose(); } try { doing = "closing connection"; log.println(doing); m_connection.close(); } catch (com.sun.star.lang.DisposedException e) { log.println("already closed - okay."); } doing = "deleting database file (" + documentFile + ")"; log.println(doing); impl_deleteFile(documentFile); if (m_tableFile != null) { doing = "deleting dBase table file (" + m_tableFile + ")"; log.println(doing); impl_deleteFile(m_tableFile); } } catch (com.sun.star.uno.Exception e) { log.println("error: "); e.printStackTrace(log); } }
public XComboBox insertComboBox( int posX, int posY, int width, String[] stringItemList, String Name, String Text) { XComboBox xComboBox = null; try { // create a unique name by means of an own implementation... String sName = Name; // createUniqueName(xDialogModelNameContainer, "ComboBox"); // create a controlmodel at the multiservicefactory of the dialog model... Object oComboBoxModel = xMultiComponentFactoryDialogModel.createInstance( "com.sun.star.awt.UnoControlComboBoxModel"); XPropertySet xComboBOxPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oComboBoxModel); /* //######################Debug de propriedades######################### XPropertySetInfo xCursorPropsInfo = xComboBOxPropertySet.getPropertySetInfo(); Property[] aProps = xCursorPropsInfo.getProperties(); int i; for (i = 0; i < aProps.length; ++i) { // prints Property Name System.out.println(aProps[i].Name); } */ xComboBOxPropertySet.setPropertyValue("Dropdown", true); xComboBOxPropertySet.setPropertyValue("Step", 3); xComboBOxPropertySet.setPropertyValue("PositionX", new Integer(posX)); xComboBOxPropertySet.setPropertyValue("PositionY", new Integer(posY)); xComboBOxPropertySet.setPropertyValue("Height", new Integer(12)); xComboBOxPropertySet.setPropertyValue("Width", new Integer(width)); xComboBOxPropertySet.setPropertyValue("StringItemList", stringItemList); xComboBOxPropertySet.setPropertyValue("Name", sName); xComboBOxPropertySet.setPropertyValue("Text", Text); xDialogModelNameContainer.insertByName(sName, oComboBoxModel); XControl xControl = xDialogContainer.getControl(sName); // retrieve a ComboBox that is more convenient to work with than the Model of the ComboBox... xComboBox = (XComboBox) UnoRuntime.queryInterface(XComboBox.class, xControl); } catch (com.sun.star.uno.Exception ex) { SpeechOO.logger = org.apache.log4j.Logger.getLogger(TrainingDialog.class.getName()); SpeechOO.logger.error(ex); } return xComboBox; }
public boolean WBToSubstrOfEncr( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bEncrypted) { // open substream element XStream xSubStream = null; try { Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamName + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamName + "', exception : " + e + "!"); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("UseCommonStoragePasswordEncryption", new Boolean(bEncrypted)); } catch (Exception e) { Error( "Can't set 'UseCommonStoragePasswordEncryption' property to substream '" + sStreamName + "', exception: " + e); return false; } if (!WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes)) return false; // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamName)) return false; return true; }
public boolean checkStream( XStorage xParentStorage, String sName, String sMediaType, boolean bCompressed, byte[] pBytes) { // open substream element first XStream xSubStream = null; try { Object oSubStream = xParentStorage.openStreamElement(sName, ElementModes.READ); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't open substream '" + sName + "'!"); return false; } } catch (Exception e) { Error("Can't open substream '" + sName + "', exception : " + e + "!"); return false; } boolean bResult = InternalCheckStream(xSubStream, sName, sMediaType, bCompressed, pBytes, true); // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sName)) return false; return bResult; }
public boolean WriteBytesToEncrSubstream( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes, String sPass) { // open substream element XStream xSubStream = null; try { Object oSubStream = xStorage.openEncryptedStreamElement(sStreamName, ElementModes.WRITE, sPass); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamName + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamName + "', exception : " + e + "!"); return false; } if (!WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes)) return false; // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamName)) return false; return true; }