예제 #1
0
  /**
   * 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();
    }
  }
  /**
   * 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);
      }
    }
  }
  /**
   * 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