/** * Constructor. * * @param c the OpenOffice component context */ public SettingsDialog(XComponentContext c) { super(c, Constants.SETTINGS_DIALOG); LoginData loginData = new LoginData(); XWikiExtension xWikiExtension = XWikiExtension.getInstance(); if (loginData.canAutoLogin()) { credentials = loginData.getCredentials(); ConnectionSettings set = xWikiExtension.getSettings(); set.setServerURL(credentials[0]); set.setPassword(credentials[1]); set.setPassword(credentials[2]); set.setWikiURL(credentials[3]); set.setXmlRpcURL(credentials[4]); try { getPropSet("txtServerURL").setPropertyValue("Text", credentials[0]); getPropSet("txtUsername").setPropertyValue("Text", credentials[1]); // TODO secure store for the password getPropSet("txtPassword").setPropertyValue("Text", credentials[2]); } catch (UnknownPropertyException e) { e.printStackTrace(); } catch (PropertyVetoException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (WrappedTargetException e) { e.printStackTrace(); } } String urlOkButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_OK_BUTTON; String urlCancelButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_CANCEL_BUTTON; String urlCustomButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_CONN_SETTINGS; try { getPropSet("btnOK").setPropertyValue("ImageURL", urlOkButton); getPropSet("btnCancel").setPropertyValue("ImageURL", urlCancelButton); getPropSet("cmdCustom").setPropertyValue("ImageURL", urlCustomButton); } catch (UnknownPropertyException e) { e.printStackTrace(); } catch (PropertyVetoException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (WrappedTargetException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
/** * Through <code>XEnumeration</code> interface an element from the set is retrieved. Then this * element removed. * * <p>Has <b> OK </b> status if after removing <code>has()</code> method returns false. */ public void _remove() { requiredMethod("insert()"); boolean res = true; try { // get an element to be removed/inserted oObj.remove(element); if (oObj.has(element)) { res = false; log.println("After removing element method has()" + " returned true"); hasResult = false; } } catch (com.sun.star.container.NoSuchElementException e) { e.printStackTrace(log); res = false; } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); res = false; } tRes.tested("remove()", res); }
/** * 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); }
/** * This property is very interesting. After setting URL of bitmap you get <code>XBitmap</code> * interface of the image file specified. The method first gets two different bitmaps and then * tests the property. */ public void _FillBitmap() { String propName = "FillBitmap"; XPropertySetInfo info = oObj.getPropertySetInfo(); if (!info.hasPropertyByName(propName)) { if (isOptional(propName)) { // skipping optional property test log.println("Property '" + propName + "' is optional and not supported"); tRes.tested(propName, true); return; } } else { try { oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("crazy-blue.jpg")); the_bitmap = (XBitmap) AnyConverter.toObject(new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap")); oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("space-metal.jpg")); the_secondBitmap = (XBitmap) AnyConverter.toObject(new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap")); testProperty("FillBitmap", BitmapTester); } catch (com.sun.star.beans.PropertyVetoException e) { log.println("Couldn't change Bitmap"); e.printStackTrace(log); tRes.tested("FillBitmap", false); } catch (com.sun.star.beans.UnknownPropertyException e) { log.println("Couldn't change Bitmap"); e.printStackTrace(log); tRes.tested("FillBitmap", false); } catch (com.sun.star.lang.WrappedTargetException e) { log.println("Couldn't change Bitmap"); e.printStackTrace(log); tRes.tested("FillBitmap", false); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("Couldn't change Bitmap"); e.printStackTrace(log); tRes.tested("FillBitmap", false); } } }
/** * An instance of text content is created using relation and inserted before the paragraph which * was added into text in <code>insertTextContentAfter</code> method test. * * <p>Has <b>OK</b> status if no exceptions occurred. * * <p>The following method tests are to be completed successfully before : * * <ul> * <li><code> insertTextContentAfter() </code> : here the <code>Paragraph</code> instance is * inserted. * </ul> */ public void _insertTextContentBefore() { requiredMethod("insertTextContentAfter()"); try { XInstCreator para = (XInstCreator) tEnv.getObjRelation("PARA"); XInterface oInt = para.createInstance(); XTextContent new_content = (XTextContent) oInt; oObj.insertTextContentBefore(new_content, content); tRes.tested("insertTextContentBefore()", true); } catch (com.sun.star.lang.IllegalArgumentException ex) { log.println("Exception occurred while checking " + "insertTextContentBefore()"); ex.printStackTrace(log); tRes.tested("insertTextContentBefore()", false); } } // end _insertTextContentBefore()
public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { XInterface oObj = null; TestEnvironment tEnv = null; try { // creation of testobject here XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc); oObj = (XInterface) AnyConverter.toObject( new Type(XInterface.class), props.getPropertyValue("AreaLinks")); XAreaLinks links = null; // adding one link into collection (for best testing) links = UnoRuntime.queryInterface(XAreaLinks.class, oObj); CellAddress addr = new CellAddress((short) 1, 2, 3); String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc"); links.insertAtPosition(addr, aSourceArea, "a2:b5", "", ""); XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class, oObj); oObj = ea.createEnumeration(); log.println("ImplementationName: " + util.utils.getImplName(oObj)); // creating test environment tEnv = new TestEnvironment(oObj); tEnv.addObjRelation("ENUM", ea); } catch (com.sun.star.beans.UnknownPropertyException e) { log.println("Exception occurred while creating test Object."); e.printStackTrace(log); throw new StatusException("Couldn't create test object", e); } catch (com.sun.star.lang.WrappedTargetException e) { log.println("Exception occurred while creating test Object."); e.printStackTrace(log); throw new StatusException("Couldn't create test object", e); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("Exception occurred while creating test Object."); e.printStackTrace(log); throw new StatusException("Couldn't create test object", e); } return tEnv; }
/** * Tries to change each property of each control. Has <b>OK</b> status if values are properly * changed. */ public void _setControlProperty() { boolean result = true; String error = ""; for (int i = 0; i < supControls.length; i++) { log.println("Checking properties for control " + supControls[i]); for (int j = 0; j < supProperties[i].length; j++) { log.println("\t" + supProperties[i][j]); try { Object oldVal = oObj.getControlProperty(supControls[i], supProperties[i][j]); Object newVal = util.ValueChanger.changePValue(oldVal); if (supProperties[i][j].startsWith("Help")) { newVal = "HID:133"; } oObj.setControlProperty(supControls[i], supProperties[i][j], newVal); Object resVal = oObj.getControlProperty(supControls[i], supProperties[i][j]); log.println("\t Old:" + oldVal + ",New:" + newVal + ",Result:" + resVal); if (!util.ValueComparer.equalValue(newVal, resVal)) { error += "####Property '" + supProperties[i][j] + " of " + supControls[i] + " didn't work\n\r" + "\t Old:" + oldVal + ",New:" + newVal + ",Result:" + resVal + "\n\r"; } result &= util.ValueComparer.equalValue(newVal, resVal); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("Unexpected exception:"); e.printStackTrace(log); result = false; } } } log.println(error); tRes.tested("setControlProperty()", result); tRes.tested("getControlProperty()", result); }
/** * Tries to query <code>com.sun.star.ui.dialogs.XControlInformation</code> interface, and obtain * properties' names of each available control. * * <p> * * @throw StatusException if interface is not supported or properties couldn't be get. */ @Override protected void before() { XControlInformation xCI = UnoRuntime.queryInterface(XControlInformation.class, oObj); if (xCI == null) throw new StatusException(Status.failed("XControlInformation not supported")); supControls = xCI.getSupportedControls(); supProperties = new String[supControls.length][]; for (int i = 0; i < supControls.length; i++) { try { supProperties[i] = xCI.getSupportedControlProperties(supControls[i]); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Exception while init.", e); } } }
/** * First an instance of <code>Paragraph</code> service created using relation and inserted into * text. Then an instance of text content is created and inserted after the paragraph. * * <p>Has <b>OK</b> status if no exceptions occurred. */ public void _insertTextContentAfter() { try { XInstCreator para = (XInstCreator) tEnv.getObjRelation("PARA"); XInterface oInt = para.createInstance(); XTextContent new_content = (XTextContent) oInt; XText theText = UnoRuntime.queryInterface(XText.class, oObj); XTextCursor oCursor = theText.createTextCursor(); XInstCreator info = (XInstCreator) tEnv.getObjRelation("XTEXTINFO"); oInt = info.createInstance(); content = (XTextContent) oInt; theText.insertTextContent(oCursor, content, false); oObj.insertTextContentAfter(new_content, content); tRes.tested("insertTextContentAfter()", true); } catch (com.sun.star.lang.IllegalArgumentException ex) { log.println("Exception occurred while checking " + "insertTextContentAfter()"); ex.printStackTrace(log); tRes.tested("insertTextContentAfter()", false); } } // end _insertTextContentAfter()
/** * 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
/** * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.text.AutoTextContainer</code>, then selects the 'mytexts' group from the * given container using <code>XNameAccess</code> interface, and inserts some text entry to this * group. Then entry passed as test component. * * <p>Object relations created : * * <ul> * <li><code>'XTEXTINFO'</code> for {@link ifc.text._XText} : creates tables 6x4 * <li><code>'TEXTDOC'</code> for {@link ifc.text._XAutoTextEntry} : text document * </ul> */ protected synchronized TestEnvironment createTestEnvironment( TestParameters Param, PrintWriter log) { XAutoTextEntry oEntry = null; XAutoTextContainer oContainer; XInterface oObj = null; log.println("creating a test environment"); try { XMultiServiceFactory myMSF = (XMultiServiceFactory) Param.getMSF(); Object oInst = myMSF.createInstance("com.sun.star.text.AutoTextContainer"); oContainer = UnoRuntime.queryInterface(XAutoTextContainer.class, oInst); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Couldn't create AutoTextContainer", e); } XNameAccess oContNames = UnoRuntime.queryInterface(XNameAccess.class, oContainer); String contNames[] = oContNames.getElementNames(); for (int i = 0; i < contNames.length; i++) { log.println("ContainerNames[ " + i + "]: " + contNames[i]); } try { oObj = (XInterface) AnyConverter.toObject(new Type(XInterface.class), oContNames.getByName("mytexts")); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Couldn't get AutoTextGroup", e); } oGroup = UnoRuntime.queryInterface(XAutoTextGroup.class, oObj); String[] oENames = oGroup.getElementNames(); for (int i = 0; i < oENames.length; i++) { log.println("AutoTextEntryNames[" + i + "]: " + oENames[i]); } XText oText = xTextDoc.getText(); oText.insertString(oText.getStart(), "New AutoText", true); XTextRange oTextRange = oText; try { if (oGroup.hasByName("NewEntryName")) { oGroup.removeByName("NewEntryName"); log.println("Element 'NewEntryName' exists, removing..."); } log.println("Adding new element 'NewEntryName' to group..."); oGroup.insertNewByName("NewEntryName", "NewEntryTitle", oTextRange); oEntry = (XAutoTextEntry) AnyConverter.toObject( new Type(XAutoTextEntry.class), oGroup.getByName("NewEntryName")); } catch (com.sun.star.container.ElementExistException e) { e.printStackTrace(log); } catch (com.sun.star.container.NoSuchElementException e) { e.printStackTrace(log); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); } oObj = oEntry; log.println("Trying to use XText as TextRange in the method applyTo"); oEntry.applyTo(oTextRange); oTextRange = oText.createTextCursor(); log.println("Trying to use XTextCursor as TextRange in the method applyTo"); oEntry.applyTo(oTextRange); log.println("creating a new environment for AutoTextEntry object"); TestEnvironment tEnv = new TestEnvironment(oObj); // adding relation for XText DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent", "com.sun.star.text.TextField.DateTime"); log.println(" adding InstCreator object"); tEnv.addObjRelation("XTEXTINFO", new InstCreator(xTextDoc, tDsc)); log.println("adding TextDocument as mod relation to environment"); tEnv.addObjRelation("TEXTDOC", xTextDoc); return tEnv; } // finish method getTestEnvironment
/** * Creating a Testenvironment for the interfaces to be tested. Retrieves the collection of style * families available in the document using the interface <code>XStyleFamiliesSupplier</code>. * Obtains default style from the style family <code>'PageStyles'</code>. Retrieves value of the * property <code>'RightPageHeaderContent'</code>. Sets some string for the text which is printed * in the center part of the header or footer using the interface <code>XHeaderFooterContent * </code> and sets new value of the property <code>'RightPageHeaderContent'</code>. Creates text * cursor for the text which is printed in the center part of the header or footer. This text * cursor is the instance of the service <code>com.sun.star.text.TextCursor</code>. * </ul> */ protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { XInterface oObj = null; XPropertySet PropSet; XNameAccess PageStyles = null; XStyle StdStyle = null; XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xSpreadsheetDoc); XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); try { PageStyles = (XNameAccess) AnyConverter.toObject( new Type(XNameAccess.class), StyleFamNames.getByName("PageStyles")); StdStyle = (XStyle) AnyConverter.toObject(new Type(XStyle.class), PageStyles.getByName("Default")); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); throw new StatusException("Couldn't get by name", e); } catch (com.sun.star.container.NoSuchElementException e) { e.printStackTrace(log); throw new StatusException("Couldn't get by name", e); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Couldn't get by name", e); } // get the property-set PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle); XHeaderFooterContent RPHC = null; // creation of testobject here // first we write what we are intend to do to log file log.println("creating a test environment"); try { RPHC = (XHeaderFooterContent) AnyConverter.toObject( new Type(XHeaderFooterContent.class), PropSet.getPropertyValue("RightPageHeaderContent")); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); throw new StatusException("Couldn't get HeaderContent", e); } catch (com.sun.star.beans.UnknownPropertyException e) { e.printStackTrace(log); throw new StatusException("Couldn't get HeaderContent", e); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Couldn't get HeaderContent", e); } XText center = RPHC.getCenterText(); center.setString("CENTER"); try { PropSet.setPropertyValue("RightPageHeaderContent", RPHC); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } catch (com.sun.star.beans.PropertyVetoException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } catch (com.sun.star.beans.UnknownPropertyException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } // create testobject here oObj = center.createTextCursor(); TestEnvironment tEnv = new TestEnvironment(oObj); // add relation for XTextRange tEnv.addObjRelation("XTEXT", UnoRuntime.queryInterface(XText.class, center)); return tEnv; } // finish method getTestEnvironment