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
/** * @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;\""); } }
/** * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.ucprmt.ContentProvider</code>. * * <p>Object relations created : * * <ul> * <li><code>'FACTORY'</code> for {@link ifc.ucb._XContentProvider} factory for content * identifiers. Here it is <code>UniversalContentBroker</code> service. * <li><code>'CONTENT1'</code> for {@link ifc.ucb._XContentProvider}: suitable content URL for * this provider * <li><code>'CONTENT2'</code> for {@link ifc.ucb._XContentProvider}: another suitable content * URL for this provider * </ul> */ public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { XInterface oObj = null; XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF(); XContentIdentifierFactory cntIDFac = null; try { oObj = (XInterface) xMSF.createInstance("com.sun.star.ucb.RemoteAccessContentProvider"); cntIDFac = UnoRuntime.queryInterface(XContentIdentifierFactory.class, oObj); } catch (com.sun.star.uno.Exception e) { log.println("Can't create an object."); throw new StatusException("Can't create an object", e); } if (oObj == null) { log.println("!!! Object wasn't created !!!"); throw new StatusException(Status.failed("!!! Object wasn't created !!!")); } TestEnvironment tEnv = new TestEnvironment(oObj); // adding relation for XContentProvider tEnv.addObjRelation("FACTORY", cntIDFac); tEnv.addObjRelation("CONTENT1", "vnd.sun.star.wfs:///user/work"); tEnv.addObjRelation("CONTENT2", "vnd.sun.star.wfs:///user/config"); return tEnv; } // finish method getTestEnvironment
/** * 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; }
/** * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.sheet.RecentFunctions</code> and an instance of the service <code> * com.sun.star.sheet.FunctionDescriptions</code>. Object relations created : * * <ul> * <li><code>'FUNCTIONLIST'</code> for {@link ifc.sheet._XRecentFunctions}(the second created * instance) * </ul> */ public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws StatusException { XInterface oObj = null; XInterface allFunctions = null; // creation of testobject here // first we write what we are intend to do to log file log.println("Creating a test environment"); try { log.println("Getting test object "); XMultiServiceFactory oDocMSF = (XMultiServiceFactory) Param.getMSF(); oObj = (XInterface) oDocMSF.createInstance("com.sun.star.sheet.RecentFunctions"); allFunctions = (XInterface) oDocMSF.createInstance("com.sun.star.sheet.FunctionDescriptions"); log.println("Creating object - " + ((oObj == null) ? "FAILED" : "OK")); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Couldn't create instance", e); } TestEnvironment tEnv = new TestEnvironment(oObj); // Other parameters required for interface tests XNameAccess NA = UnoRuntime.queryInterface(XNameAccess.class, allFunctions); tEnv.addObjRelation("FUNCTIONLIST", NA); return tEnv; }
/** * Inserts the element stored and removed before. * * <p>Has <b> OK </b> status if <code>has()</code> method returns <code>true</code>. The following * method tests are to be completed successfully before : * * <ul> * <li><code> remove() </code> : element from set is stored and removed * </ul> */ public void _insert() { boolean res = true; try { XMultiServiceFactory xMSF = (XMultiServiceFactory) tParam.getMSF(); element = xMSF.createInstance("com.sun.star.reflection.TypeDescriptionProvider"); oObj.insert(element); if (!oObj.has(element)) { res = false; log.println("After adding element method has()" + " returned false"); hasResult = false; } } catch (com.sun.star.container.ElementExistException e) { e.printStackTrace(log); res = false; } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); res = false; } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); res = false; } tRes.tested("insert()", res); }
/** * Check BackColor and IsLandscape properties, wait for an exception: test is ok if no exception * happened. */ public void checkChangeColor() { try { XMultiServiceFactory m_xMSF_ = (XMultiServiceFactory) param.getMSF(); XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, m_xMSF_.createInstance("com.sun.star.frame.Desktop")); XComponent xDocument = (XComponent) UnoRuntime.queryInterface( XComponent.class, aLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, new PropertyValue[0])); // xDocument.addEventListener( this ); XTextDocument oDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xDocument); XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); // XInterface xInterface = (XInterface) oDocMSF.createInstance( "com.sun.star.style.PageStyle" // ); // create a supplier to get the Style family collection XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, oDoc); // get the NameAccess interface from the Style family collection XNameAccess xNameAccess = xSupplier.getStyleFamilies(); XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName("PageStyles")); // create a PropertySet to set the properties for the new Pagestyle XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xPageStyleCollection.getByName("Standard")); log.println("BackColor @ " + xPropertySet.getPropertyValue("BackColor").toString()); log.println("IsLandscape @ " + xPropertySet.getPropertyValue("IsLandscape").toString()); log.println( "Size @ H:" + ((Size) xPropertySet.getPropertyValue("Size")).Height + " W:" + ((Size) xPropertySet.getPropertyValue("Size")).Width); log.println("Set Landscape"); xPropertySet.setPropertyValue("IsLandscape", new Boolean(true)); log.println("Set BackColor"); xPropertySet.setPropertyValue("BackColor", new Integer((int) 255000000)); } catch (Exception e) { e.printStackTrace(); failed("Exception."); } }
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); }
/** * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.java.JavaVirtualMachine</code>. */ protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { XMultiServiceFactory xMSF = (XMultiServiceFactory) tParam.getMSF(); try { XInterface xInt = (XInterface) xMSF.createInstance("com.sun.star.java.JavaVirtualMachine"); return new TestEnvironment(xInt); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Unexpected exception", e); } }
/* ------------------------------------------------------------------ */ 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; }
/** * 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 Object insertButton( int posX, int posY, int width, String label, int pushButtonType, boolean enabled, String uniqueName) throws Exception { // Create a button control model Object oButtonModel = xMultiComponentFactoryDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel"); // Set the properties at the model XPropertySet xButtonPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oButtonModel); xButtonPropertySet.setPropertyValue("PositionX", new Integer(posX)); xButtonPropertySet.setPropertyValue("PositionY", new Integer(posY)); xButtonPropertySet.setPropertyValue("Height", new Integer(14)); xButtonPropertySet.setPropertyValue("Width", new Integer(width)); xButtonPropertySet.setPropertyValue("Label", (label != null) ? label : ""); xButtonPropertySet.setPropertyValue("PushButtonType", new Short((short) pushButtonType)); xButtonPropertySet.setPropertyValue("Name", uniqueName); xButtonPropertySet.setPropertyValue("Enabled", enabled); // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, oButtonModel); return oButtonModel; }
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); }
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) { } }
/** * Create test environment: * * <ul> * <li>create a text doc * <li>get the model from the text doc * <li>query model for XUIConfigurationManagerSupplier interface * <li>get the manager from the supplier * </ul> * * @param tParam The test parameters. * @param log The log writer. * @return The test environment. */ protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { TestEnvironment tEnv = null; XMultiServiceFactory xMSF = (XMultiServiceFactory) tParam.getMSF(); log.println("Creating instance..."); xTextDoc = WriterTools.createTextDoc(xMSF); try { oObj = xMSF.createInstance("com.sun.star.ui.UIElementFactoryManager"); } catch (com.sun.star.uno.Exception e) { throw new StatusException("Cannot create test object.", e); } log.println("TestObject: " + util.utils.getImplName(oObj)); tEnv = new TestEnvironment((XInterface) oObj); return tEnv; }
/** * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.comp.Chart.XMLExporter</code> with argument which is an implementation of * <code>XDocumentHandler</code> and which can check if required tags and character data is * exported. * * <p>The chart document is set as a source document for exporter created. A new 'main title' is * set for chart. This made for checking if this title is successfully exported within the * document content. Object relations created : * * <ul> * <li><code>'MediaDescriptor'</code> for {@link ifc.document._XFilter} interface * <li><code>'XFilter.Checker'</code> for {@link ifc.document._XFilter} interface * <li><code>'SourceDocument'</code> for {@link ifc.document._XExporter} interface * </ul> */ @Override public TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception { XMultiServiceFactory xMSF = tParam.getMSF(); XInterface oObj = null; final String exportStr = "XMLExporter test."; FilterChecker filter = new FilterChecker(log); Any arg = new Any(new Type(XDocumentHandler.class), filter); oObj = (XInterface) xMSF.createInstanceWithArguments( "com.sun.star.comp.Chart.XMLExporter", new Object[] {arg}); XExporter xEx = UnoRuntime.queryInterface(XExporter.class, oObj); xEx.setSourceDocument(xChartDoc); Object oTitle = xChartDoc.getTitle(); XPropertySet xTitleProp = UnoRuntime.queryInterface(XPropertySet.class, oTitle); xTitleProp.setPropertyValue("String", exportStr); filter.addTag(new XMLTools.Tag("office:document")); filter.addTagEnclosed(new XMLTools.Tag("office:meta"), new XMLTools.Tag("office:document")); filter.addTagEnclosed(new XMLTools.Tag("office:body"), new XMLTools.Tag("office:document")); filter.addCharactersEnclosed(exportStr, new XMLTools.Tag("chart:title")); // create testobject here log.println("creating a new environment"); TestEnvironment tEnv = new TestEnvironment(oObj); tEnv.addObjRelation( "MediaDescriptor", XMLTools.createMediaDescriptor( new String[] {"FilterName"}, new Object[] {"schart: StarOffice XML (Chart)"})); tEnv.addObjRelation("SourceDocument", xChartDoc); tEnv.addObjRelation("XFilter.Checker", filter); log.println("Implementation Name: " + util.utils.getImplName(oObj)); return tEnv; }
public XStream CreateTempFileStream(XMultiServiceFactory xMSF) { // try to get temporary file representation XStream xTempFileStream = null; try { Object oTempFile = xMSF.createInstance("com.sun.star.io.TempFile"); xTempFileStream = (XStream) UnoRuntime.queryInterface(XStream.class, oTempFile); } catch (Exception e) { } if (xTempFileStream == null) Error("Can't create temporary file!"); return xTempFileStream; }
/** simulates pressing a toolbox button with the given URL */ private void executeSlot(String slotURL) throws java.lang.Exception { XDispatch xDispatch = m_document.getCurrentView().getDispatcher(slotURL); URL[] url = new URL[] {new URL()}; url[0].Complete = slotURL; XURLTransformer xTransformer = UnoRuntime.queryInterface( XURLTransformer.class, m_orb.createInstance("com.sun.star.util.URLTransformer")); xTransformer.parseStrict(url); PropertyValue[] aArgs = new PropertyValue[0]; xDispatch.dispatch(url[0], aArgs); }
/** * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.text.TextFrame</code>. Then inserts created text frame to the text, and * finally gets all frames of text document using <code>XTextFramesSupplier</code> interface.<br> */ public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws StatusException { XInterface oObj = null; XTextFrame oFrame1 = null; XText oText = null; XTextCursor oCursor = null; XMultiServiceFactory oDocMSF = null; XTextFramesSupplier oInterface = null; log.println("creating a test environment"); try { oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); Object oInt = oDocMSF.createInstance("com.sun.star.text.TextFrame"); oFrame1 = UnoRuntime.queryInterface(XTextFrame.class, oInt); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Couldn't create instance of TextFrame", e); } oText = xTextDoc.getText(); oCursor = oText.createTextCursor(); try { oText.insertTextContent(oCursor, oFrame1, false); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Error: can't insert text content to text document", e); } oInterface = UnoRuntime.queryInterface(XTextFramesSupplier.class, xTextDoc); oObj = oInterface.getTextFrames(); log.println("creating a new environment for Frame object"); TestEnvironment tEnv = new TestEnvironment(oObj); return tEnv; } // finish method getTestEnvironment
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) { } }
/** * Creating a Testenvironment for the interfaces to be tested. Using SOffice ServiceManager an * instance of <code>com.sun.star.sheet.TableAutoFormatField</code> service is created. From this * collection one Format is retrieved as object tested. */ public TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { XInterface oObj = null; XMultiServiceFactory oMSF = (XMultiServiceFactory) tParam.getMSF(); try { XInterface formats = (XInterface) oMSF.createInstance("com.sun.star.sheet.TableAutoFormats"); XIndexAccess formatsIndex = UnoRuntime.queryInterface(XIndexAccess.class, formats); oObj = (XInterface) AnyConverter.toObject( new Type(XInterface.class), formatsIndex.getByIndex(formatsIndex.getCount() - 1)); XNamed objNamed = UnoRuntime.queryInterface(XNamed.class, oObj); log.println("AutoFormat name is '" + objNamed.getName() + "'"); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Unexpected exception", e); } TestEnvironment tEnv = new TestEnvironment(oObj); return tEnv; }
/** * Creating a Testenvironment for the interfaces to be tested. In case if OS is Win or not * specified tries to create an instance of the service <code>com.sun.star.system.SimpleSystemMail * </code>. * * <p>Object relations created : * * <ul> * <li><code>'SystemMailExist'</code> for {@link ifc.system._XSimpleMailClientSupplier} : the * value depends on tested platform and <code>test.system.mail.isExist</code> INI parameter. * </ul> */ public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws StatusException { XInterface oObj = null; Object oInterface = null; boolean isWinOS = false; boolean isSystemMailExist = false; // if 'OS' parameter is not defined then by default // Win platform is used. If really not the error will occurs. isWinOS = Param.get("OS") == null || "wntmsci".equals(Param.get("OS")); isSystemMailExist = "true".equalsIgnoreCase((String) Param.get("test.system.mail.isExist")); XMultiServiceFactory xMSF = Param.getMSF(); try { if (isWinOS) { log.println("The OS is Win : trying to create service"); oInterface = xMSF.createInstance("com.sun.star.system.SimpleSystemMail"); } else { log.println("The OS is NOT Win, SKIPPING this component"); log.println("Creating Dummy object ..."); oInterface = xMSF.createInstance("com.sun.star.io.Pipe"); } } catch (com.sun.star.uno.Exception e) { log.println("Can't create an object."); throw new StatusException("Can't create an object", e); } oObj = (XInterface) oInterface; log.println("ImplementationName: " + util.utils.getImplName(oObj)); TestEnvironment tEnv = new TestEnvironment(oObj); tEnv.addObjRelation("SystemMailExist", new Boolean(isSystemMailExist)); return tEnv; } // finish method getTestEnvironment
/** * ******************************************************************* create a new frame with a * new container window inside, which isn't part of the global frame tree. * * <p>Attention: a) This frame wont be destroyed by the office. It must be closed by you! Do so - * please call XCloseable::close(). b) The container window is part of the frame. Dont hold it * alive - nor try to kill it. It will be destroyed inside close(). */ public void createPreviewFrame(XMultiServiceFactory xmsf, XControl xControl) throws com.sun.star.uno.Exception, com.sun.star.lang.IllegalArgumentException { XWindowPeer controlPeer = xControl.getPeer(); XWindow controlWindow = UnoRuntime.queryInterface(XWindow.class, xControl); Rectangle r = controlWindow.getPosSize(); Object toolkit = xmsf.createInstance("com.sun.star.awt.Toolkit"); XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit); WindowDescriptor aDescriptor = new WindowDescriptor(); aDescriptor.Type = WindowClass.SIMPLE; aDescriptor.WindowServiceName = "window"; aDescriptor.ParentIndex = -1; aDescriptor.Parent = controlPeer; // xWindowPeer; //argument ! aDescriptor.Bounds = new Rectangle(0, 0, r.Width, r.Height); aDescriptor.WindowAttributes = VclWindowPeerAttribute.CLIPCHILDREN | WindowAttribute.SHOW; XWindowPeer xPeer = xToolkit.createWindow(aDescriptor); xWindow = UnoRuntime.queryInterface(XWindow.class, xPeer); Object frame = xmsf.createInstance("com.sun.star.frame.Frame"); xFrame = UnoRuntime.queryInterface(XFrame.class, frame); xFrame.initialize(xWindow); xWindow.setVisible(true); }
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; }
/** Create a specified read-only configuration view */ protected Object createConfigurationReadOnlyView(String sPath) throws com.sun.star.uno.Exception { // XMultiServiceFactory xProvider = getProvider(); // The service name: Need only read access: final String sReadOnlyView = "com.sun.star.configuration.ConfigurationAccess"; // creation arguments: nodepath com.sun.star.beans.PropertyValue aPathArgument = new com.sun.star.beans.PropertyValue(); aPathArgument.Name = "nodepath"; aPathArgument.Value = sPath; Object[] aArguments = new Object[1]; aArguments[0] = aPathArgument; Object xViewRoot = m_ConfProvider.createInstanceWithArguments(sReadOnlyView, aArguments); return xViewRoot; }
/** Create a specified updatable configuration view using default synchronicity */ protected Object createConfigurationReadWriteView(String sPath) throws com.sun.star.uno.Exception { // The service name: Need update access: final String cUpdatableView = "com.sun.star.configuration.ConfigurationUpdateAccess"; // creation arguments: nodepath com.sun.star.beans.PropertyValue aPathArgument = new com.sun.star.beans.PropertyValue(); aPathArgument.Name = "nodepath"; aPathArgument.Value = sPath; // creation arguments: commit mode - write-through or write-back com.sun.star.beans.PropertyValue aModeArgument = new com.sun.star.beans.PropertyValue(); aModeArgument.Name = "enableasync"; aModeArgument.Value = new Boolean(false); Object[] aArguments = new Object[2]; aArguments[0] = aPathArgument; aArguments[1] = aModeArgument; // create the view Object xViewRoot = m_ConfProvider.createInstanceWithArguments(cUpdatableView, aArguments); return xViewRoot; }
public String CreateTempFile(XMultiServiceFactory xMSF) { String sResult = null; // try to get temporary file representation XPropertySet xTempFileProps = null; try { Object oTempFile = xMSF.createInstance("com.sun.star.io.TempFile"); xTempFileProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTempFile); } catch (Exception e) { } if (xTempFileProps != null) { try { xTempFileProps.setPropertyValue("RemoveFile", new Boolean(false)); sResult = AnyConverter.toString(xTempFileProps.getPropertyValue("Uri")); } catch (Exception e) { Error("Can't control TempFile properties, exception: " + e); } } else { Error("Can't create temporary file representation!"); } // close temporary file explicitly try { XStream xStream = (XStream) UnoRuntime.queryInterface(XStream.class, xTempFileProps); if (xStream != null) { XOutputStream xOut = xStream.getOutputStream(); if (xOut != null) xOut.closeOutput(); XInputStream xIn = xStream.getInputStream(); if (xIn != null) xIn.closeInput(); } else Error("Can't close TempFile!"); } catch (Exception e) { Error("Can't close TempFile, exception: " + e); } return sResult; }
/** * @short Create the environment for following tests. * @descr create an empty test frame, where we can load different components inside. */ @Before public void before() { m_aLog = new Protocol( Protocol.MODE_HTML | Protocol.MODE_STDOUT, Protocol.FILTER_NONE, utils.getUsersTempDir() + "/complex_log_ascii_01.html"); try { // get uno service manager from global test environment m_xSMGR = getMSF(); // get another helper to e.g. create test documents m_aSOF = SOfficeFactory.getFactory(m_xSMGR); // create AutoSave instance m_xAutoSave = theAutoRecovery.get(connection.getComponentContext()); // prepare AutoSave // make sure it will be started every 1 min ConfigHelper aConfig = new ConfigHelper( connection.getComponentContext(), "org.openoffice.Office.Recovery", false); aConfig.writeRelativeKey("AutoSave", "Enabled", Boolean.TRUE); aConfig.writeRelativeKey("AutoSave", "TimeIntervall", Integer.valueOf(1)); // 1 min aConfig.flush(); aConfig = null; // is needed to parse dispatch commands m_xURLParser = UnoRuntime.queryInterface( XURLTransformer.class, m_xSMGR.createInstance("com.sun.star.util.URLTransformer")); } catch (java.lang.Throwable ex) { m_aLog.log(ex); fail("Couldn't create test environment"); } }
private AutoSaveListener(XMultiServiceFactory xSMGR, XDispatch xAutoSave, Protocol aLog) { m_aLog = aLog; m_aLog.log(Protocol.TYPE_SCOPE_OPEN, "create listener for AutoSave notifications ..."); try { m_xAutoSave = xAutoSave; XURLTransformer xParser = UnoRuntime.queryInterface( XURLTransformer.class, xSMGR.createInstance("com.sun.star.util.URLTransformer")); URL[] aURL = new URL[1]; aURL[0] = new URL(); aURL[0].Complete = "vnd.sun.star.autorecovery:/doAutoSave"; xParser.parseStrict(aURL); m_aRegistration = aURL[0]; m_xAutoSave.addStatusListener(this, m_aRegistration); m_aLog.log(Protocol.TYPE_INFO, "successfully registered as AutoSave listener."); } catch (Throwable ex) { m_aLog.log(ex); } m_aLog.log(Protocol.TYPE_SCOPE_CLOSE, ""); }